diff options
Diffstat (limited to 'js/index.js')
-rw-r--r-- | js/index.js | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/js/index.js b/js/index.js index b16a742..c0f2e84 100644 --- a/js/index.js +++ b/js/index.js @@ -1,11 +1,13 @@ 'use strict'; -var _dl_progress_timeout; +/* global localforage */ + +let _dl_progress_timeout; function cache_refresh(force) { if ('serviceWorker' in navigator) { localforage.getItem("epube.cache-timestamp").then(function(stamp) { - var ts = parseInt(new Date().getTime()/1000); + const ts = parseInt(new Date().getTime()/1000); if (force || !stamp || ts - stamp > 3600 * 24 * 7) { console.log('asking worker to refresh cache'); @@ -20,13 +22,13 @@ function cache_refresh(force) { } function toggle_fav(elem) { - var bookId = elem.getAttribute("data-book-id"); + const bookId = elem.getAttribute("data-book-id"); if (elem.getAttribute("data-is-fav") == "0" || confirm("Remove favorite?")) { $.post("backend.php", {op: "togglefav", id: bookId}, function(data) { if (data) { - var msg = "[Error]"; + let msg = "[Error]"; if (data.status == 0) { msg = "Add to favorites"; @@ -48,8 +50,8 @@ function toggle_fav(elem) { function mark_offline(elem) { - var bookId = elem.getAttribute("data-book-id"); - var cacheId = "epube-book." + bookId; + const bookId = elem.getAttribute("data-book-id"); + const cacheId = "epube-book." + bookId; localforage.getItem(cacheId).then(function(book) { if (book) { @@ -77,7 +79,7 @@ function mark_offline(elem) { } function mark_offline_books() { - var elems = $(".offline_dropitem"); + const elems = $(".offline_dropitem"); $.each(elems, function (i, elem) { mark_offline(elem); @@ -90,13 +92,13 @@ function offline_cache(bookId, callback) { $.post("backend.php", {op: "getinfo", id: bookId}, function(data) { if (data) { - var cacheId = 'epube-book.' + bookId; + const cacheId = 'epube-book.' + bookId; localforage.setItem(cacheId, data).then(function(data) { console.log(cacheId + ' got data'); - var promises = []; + const promises = []; promises.push(fetch('backend.php?op=download&id=' + data.epub_id, {credentials: 'same-origin'}).then(function(resp) { if (resp.status == 200) { @@ -158,11 +160,11 @@ function offline_cache(bookId, callback) { } function show_summary(elem) { - var id = elem.getAttribute("data-book-id"); + const id = elem.getAttribute("data-book-id"); $.post("backend.php", {op: 'getinfo', id: id}, function(data) { - var comment = data.comment ? data.comment : 'No description available'; + const comment = data.comment ? data.comment : 'No description available'; $("#summary-modal .modal-title").html(data.title); $("#summary-modal .book-summary").html(comment); @@ -179,12 +181,12 @@ function offline_get_all() { if (confirm("Download all books on this page?")) { $(".index_cell").each(function (i, row) { - var bookId = $(row).attr("id").replace("cell-", ""); - var dropitem = $(row).find(".offline_dropitem")[0]; + const bookId = $(row).attr("id").replace("cell-", ""); + const dropitem = $(row).find(".offline_dropitem")[0]; if (bookId) { - var cacheId = 'epube-book.' + bookId; + const cacheId = 'epube-book.' + bookId; localforage.getItem(cacheId).then(function(book) { if (!book) { @@ -200,4 +202,3 @@ function offline_get_all() { } } - |