diff --git a/package.json b/package.json index dee5d79..ddcbf84 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "body-parser": "^1.18.3", "bulma": "^0.7.2", + "cookie-parser": "^1.4.3", "express": "^4.16.4", "express-fileupload": "^1.0.0", "fecha": "^3.0.2", diff --git a/public/js/little-library.js b/public/js/little-library.js index c9389f6..c4c0566 100644 --- a/public/js/little-library.js +++ b/public/js/little-library.js @@ -33,6 +33,12 @@ $(document).ready(function() { } }); + $('#readableToggle').click(function() { + var useReadable = getCookieValue('useReadable'); + document.cookie = 'useReadable=' + (useReadable !== 'yes' ? 'yes' : 'no'); + window.location.reload(); + }); + $('.modal-background, .modal-close, .modal-card-head .delete, .modal .close').click(function() { $(this).closest('.modal').removeClass('is-active'); downloadButton = undefined; @@ -64,4 +70,9 @@ $(document).ready(function() { } $('#bookFileName').text(fileName ? fileName : 'None Selected'); }); -}); \ No newline at end of file +}); + +function getCookieValue(key) { + var matches = document.cookie.match('(^|;)\\s*' + key + '\\s*=\\s*([^;]+)'); + return matches ? matches.pop() : '' +} \ No newline at end of file diff --git a/routes/get_home.js b/routes/get_home.js index 9c8e515..b1a85c3 100644 --- a/routes/get_home.js +++ b/routes/get_home.js @@ -8,6 +8,7 @@ const settings = require('../settings.json'); module.exports = function (app) { app.server.get('/', (req, res) => { + const useReadable = req.cookies['useReadable'] === 'yes'; const files = fs.readdirSync(app.fileLocation).filter(fileName => fileName.includes('.json')) .map(fileName => { // Cache the file data so sorting doesn't need to re-check each file const stats = fs.statSync(path.resolve(app.fileLocation, fileName)); @@ -50,7 +51,7 @@ module.exports = function (app) { if (!spineColor.isValid()) { spineColor = tinycolor.random(); } - return app.templater.fill('./templates/elements/book.html', { + return app.templater.fill(useReadable ? './templates/elements/book_readable.html' : './templates/elements/book.html', { id, title: bookData.title, author: bookData.author, @@ -68,7 +69,11 @@ module.exports = function (app) { books = '