summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-04-13 11:32:55 +0300
committerAndrew Dolgov <[email protected]>2021-04-13 11:32:55 +0300
commitf15d77c0ea8f551c6d51d2687f3709bf3a4bc649 (patch)
treef1cf1758069bbafa87845f387f2a4b2adde606a0 /js
parentb57adffcaeff9488d1a15eeaea5f54583f9396ef (diff)
don't try to store location needlessly; also when clicking on epub links
Diffstat (limited to 'js')
-rw-r--r--js/reader.js40
1 files changed, 24 insertions, 16 deletions
diff --git a/js/reader.js b/js/reader.js
index 1c226be..e14fd20 100644
--- a/js/reader.js
+++ b/js/reader.js
@@ -11,6 +11,8 @@ const PAGE_RESET_PROGRESS = -1;
const Reader = {
csrf_token: "",
+ last_stored_cfi: "",
+ prevent_lastread_update: false,
init: function() {
this.csrf_token = Cookie.get('epube_csrf_token');
@@ -246,6 +248,8 @@ const Reader = {
contents.on("linkClicked", function(href) {
console.log('linkClicked', href);
+ Reader.prevent_lastread_update = true;
+
if (href.indexOf("://") == -1) {
$(".prev_location_btn")
.attr("data-location-cfi", book.rendition.currentLocation().start.cfi)
@@ -740,28 +744,32 @@ const Reader = {
$("#chapter_pct").text(parseInt(displayed.page / displayed.total * 100) + '%')
}
- const lastread_timestamp = new Date().getTime();
+ if (Reader.last_stored_cfi != currentCfi && !Reader.prevent_lastread_update) {
+ const lastread_timestamp = new Date().getTime();
- console.log("storing lastread", currentPct, currentCfi, lastread_timestamp);
+ console.log("storing lastread", currentPct, currentCfi, lastread_timestamp);
- localforage.setItem(Reader.cacheId("lastread"),
- {cfi: currentCfi, page: currentPct, total: 100, timestamp: lastread_timestamp});
+ localforage.setItem(Reader.cacheId("lastread"),
+ {cfi: currentCfi, page: currentPct, total: 100, timestamp: lastread_timestamp});
- if (App.isOnline()) {
- console.log("updating remote lastread...")
+ if (App.isOnline()) {
+ console.log("updating remote lastread", currentCfi);
+ Reader.last_stored_cfi = currentCfi;
- $.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPct,
- cfi: currentCfi, timestamp: lastread_timestamp }, function() {
- //
- })
- .fail(function(e) {
- if (e && e.status == 401) {
- window.location = "index.php";
- }
- });
+ $.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPct,
+ cfi: currentCfi, timestamp: lastread_timestamp }).then(() => {
+ //
+ })
+ .fail(function(e) {
+ if (e && e.status == 401) {
+ window.location = "index.php";
+ }
+ });
+ }
}
- });
+ Reader.prevent_lastread_update = false;
+ });
});
},
flattenTocSubItems: function(entry, nest) {