Save the position of the last read page for comics

This commit is contained in:
Olivier 2022-10-11 23:37:12 +09:00
parent 3d59a78c9f
commit a80735d7d3
3 changed files with 187 additions and 157 deletions

View File

@ -70,8 +70,8 @@ var settings = {
fitMode: kthoom.Key.B, fitMode: kthoom.Key.B,
theme: "light", theme: "light",
direction: 0, // 0 = Left to Right, 1 = Right to Left direction: 0, // 0 = Left to Right, 1 = Right to Left
nextPage: 0, // 0 = Reset to Top, 1 = Remember Position nextPage: 0, // 0 = Reset to Top, 1 = Remember Position
scrollbar: 1 // 0 = Hide Scrollbar, 1 = Show Scrollbar scrollbar: 1 // 0 = Hide Scrollbar, 1 = Show Scrollbar
}; };
kthoom.saveSettings = function() { kthoom.saveSettings = function() {
@ -130,7 +130,7 @@ var createURLFromArray = function(array, mimeType) {
} }
if ((typeof URL !== "function" && typeof URL !== "object") || if ((typeof URL !== "function" && typeof URL !== "object") ||
typeof URL.createObjectURL !== "function") { typeof URL.createObjectURL !== "function") {
throw "Browser support for Object URLs is missing"; throw "Browser support for Object URLs is missing";
} }
@ -186,8 +186,7 @@ function initProgressClick() {
}); });
} }
function loadFromArrayBuffer(ab) { function loadFromArrayBuffer(ab, lastCompletion = 0) {
var lastCompletion = 0;
const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' }); const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' });
loadArchiveFormats(['rar', 'zip', 'tar'], function() { loadArchiveFormats(['rar', 'zip', 'tar'], function() {
// Open the file as an archive // Open the file as an archive
@ -244,7 +243,7 @@ function updatePage() {
// Mark the current page in the TOC // Mark the current page in the TOC
$("#tocView a[data-page]") $("#tocView a[data-page]")
// Remove the currently active thumbnail // Remove the currently active thumbnail
.removeClass("active") .removeClass("active")
// Find the new one // Find the new one
.filter("[data-page=" + (currentImage + 1) + "]") .filter("[data-page=" + (currentImage + 1) + "]")
@ -261,7 +260,7 @@ function updatePage() {
} }
$("body").toggleClass("dark-theme", settings.theme === "dark"); $("body").toggleClass("dark-theme", settings.theme === "dark");
$("#mainContent").toggleClass("disabled-scrollbar", settings.scrollbar === 0); $("#mainContent").toggleClass("disabled-scrollbar", settings.scrollbar === 0);
kthoom.setSettings(); kthoom.setSettings();
kthoom.saveSettings(); kthoom.saveSettings();
@ -335,7 +334,7 @@ function setImage(url) {
x.font = "50px sans-serif"; x.font = "50px sans-serif";
x.strokeStyle = "black"; x.strokeStyle = "black";
x.fillText("Page #" + (currentImage + 1) + " (" + x.fillText("Page #" + (currentImage + 1) + " (" +
imageFiles[currentImage].filename + ")", innerWidth / 2, 100); imageFiles[currentImage].filename + ")", innerWidth / 2, 100);
x.fillStyle = "black"; x.fillStyle = "black";
x.fillText("Is corrupt or not an image", innerWidth / 2, 200); x.fillText("Is corrupt or not an image", innerWidth / 2, 200);
@ -418,9 +417,9 @@ function showPrevPage() {
currentImage++; currentImage++;
} else { } else {
updatePage(); updatePage();
if (settings.nextPage === 0) { if (settings.nextPage === 0) {
$("#mainContent").scrollTop(0); $("#mainContent").scrollTop(0);
} }
} }
} }
@ -431,9 +430,9 @@ function showNextPage() {
currentImage--; currentImage--;
} else { } else {
updatePage(); updatePage();
if (settings.nextPage === 0) { if (settings.nextPage === 0) {
$("#mainContent").scrollTop(0); $("#mainContent").scrollTop(0);
} }
} }
} }
@ -551,7 +550,7 @@ function init(filename) {
request.responseType = "arraybuffer"; request.responseType = "arraybuffer";
request.addEventListener("load", function() { request.addEventListener("load", function() {
if (request.status >= 200 && request.status < 300) { if (request.status >= 200 && request.status < 300) {
loadFromArrayBuffer(request.response); loadFromArrayBuffer(request.response, currentImage);
} else { } else {
console.warn(request.statusText, request.responseText); console.warn(request.statusText, request.responseText);
} }
@ -609,9 +608,9 @@ function init(filename) {
$("#thumbnails").on("click", "a", function() { $("#thumbnails").on("click", "a", function() {
currentImage = $(this).data("page") - 1; currentImage = $(this).data("page") - 1;
updatePage(); updatePage();
if (settings.nextPage === 0) { if (settings.nextPage === 0) {
$("#mainContent").scrollTop(0); $("#mainContent").scrollTop(0);
} }
}); });
// Fullscreen mode // Fullscreen mode

View File

@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
@ -17,78 +18,61 @@
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script> <script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/compress/uncompress.js') }}"></script> <script src="{{ url_for('static', filename='js/compress/uncompress.js') }}"></script>
<script src="{{ url_for('static', filename='js/kthoom.js') }}"></script> <script src="{{ url_for('static', filename='js/kthoom.js') }}"></script>
<script>
var updateArrows = function() {
if ($('input[name="direction"]:checked').val() === "0") {
$("#prev_page_key").html("&larr;");
$("#next_page_key").html("&rarr;");
} else {
$("#prev_page_key").html("&rarr;");
$("#next_page_key").html("&larr;");
}
};
document.onreadystatechange = function () {
if (document.readyState == "complete") {
init("{{ url_for('web.serve_book', book_id=comicfile, book_format=extension) }}");
updateArrows();
}
}
</script>
</head> </head>
<body> <body>
<div id="sidebar"> <div id="sidebar">
<div id="tocView" class="view" tabindex="-1"> <div id="tocView" class="view" tabindex="-1">
<ul id="thumbnails"></ul> <ul id="thumbnails"></ul>
</div>
<div id="bookmarksView" class="view">
<ul id="bookmarks"></ul>
</div>
</div> </div>
<div id="bookmarksView" class="view">
<ul id="bookmarks"></ul>
</div>
</div>
<div id="main" class="main"> <div id="main" class="main">
<div id="titlebar" class="main"> <div id="titlebar" class="main">
<div id="opener"> <div id="opener">
<a id="slider" class="icon-menu">Menu</a> <a id="slider" class="icon-menu">Menu</a>
</div> </div>
<div id="metainfo"> <div id="metainfo">
<span id="book-title">{{ title | shortentitle }}</span> <span id="book-title">{{ title | shortentitle }}</span>
<span id="title-seperator">&nbsp;&nbsp;&nbsp;&nbsp;</span> <span id="title-seperator">&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span id="chapter-title"></span> <span id="chapter-title"></span>
</div> </div>
<div id="title-controls"> <div id="title-controls">
<a id="setting" class="icon-cog">Settings</a> <a id="setting" class="icon-cog">Settings</a>
<a id="fullscreen" class="icon-resize-full">Fullscreen</a> <a id="fullscreen" class="icon-resize-full">Fullscreen</a>
</div> </div>
<div id="progress" role="progressbar" class="loading"> <div id="progress" role="progressbar" class="loading">
<div class="bar-load from-left"> <div class="bar-load from-left">
<div class="text load"> <div class="text load">
Loading... Loading...
</div>
</div>
<div class="bar-read from-left">
<div class="text page"></div>
</div> </div>
</div> </div>
<div class="bar-read from-left">
<div class="text page"></div>
</div>
</div> </div>
<div id="mainContent" tabindex="-1">
<div id="mainText" style="display:none"></div>
<canvas id="mainImage"></canvas>
</div>
<div id="left" class="arrow" onclick="showLeftPage(); setBookmark();"></div>
<div id="right" class="arrow" onclick="showRightPage(); setBookmark();"></div>
</div> </div>
<div id="mainContent" tabindex="-1"> <div class="modal md-effect-1" id="settings-modal">
<div id="mainText" style="display:none"></div> <div class="md-content">
<canvas id="mainImage"></canvas> <h3>{{_('Settings')}}</h3>
</div> <div>
<div id="left" class="arrow" onclick="showLeftPage()"></div> <div class="settings-column">
<div id="right" class="arrow" onclick="showRightPage()"></div> <table>
</div> <thead>
<div class="modal md-effect-1" id="settings-modal">
<div class="md-content">
<h3>{{_('Settings')}}</h3>
<div>
<div class="settings-column">
<table>
<thead>
<tr><th colspan="2">{{_('Keyboard Shortcuts')}}</th></tr> <tr><th colspan="2">{{_('Keyboard Shortcuts')}}</th></tr>
</thead> </thead>
<tbody> <tbody>
<tr><td id="prev_page_key">&larr;</td> <td>{{_('Previous Page')}}</td></tr> <tr><td id="prev_page_key">&larr;</td> <td>{{_('Previous Page')}}</td></tr>
<tr><td id="next_page_key">&rarr;</td> <td>{{_('Next Page')}}</td></tr> <tr><td id="next_page_key">&rarr;</td> <td>{{_('Next Page')}}</td></tr>
<tr><td>B</td> <td>{{_('Scale to Best')}}</td></tr> <tr><td>B</td> <td>{{_('Scale to Best')}}</td></tr>
@ -98,96 +82,143 @@
<tr><td>R</td> <td>{{_('Rotate Right')}}</td></tr> <tr><td>R</td> <td>{{_('Rotate Right')}}</td></tr>
<tr><td>L</td> <td>{{_('Rotate Left')}}</td></tr> <tr><td>L</td> <td>{{_('Rotate Left')}}</td></tr>
<tr><td>F</td> <td>{{_('Flip Image')}}</td></tr> <tr><td>F</td> <td>{{_('Flip Image')}}</td></tr>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="settings-column"> <div class="settings-column">
<table id="settings"> <table id="settings">
<thead> <thead>
<tr> <tr>
<th>{{_('Settings')}}</th> <th>{{_('Settings')}}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<th>{{_('Theme')}}:</th> <th>{{_('Theme')}}:</th>
<td> <td>
<div class="inputs"> <div class="inputs">
<label for="lightTheme"><input type="radio" id="lightTheme" name="theme" value="light" /> {{_('Light')}}</label> <label for="lightTheme"><input type="radio" id="lightTheme" name="theme" value="light" /> {{_('Light')}}</label>
<label for="darkTheme"><input type="radio" id="darkTheme" name="theme" value="dark" /> {{_('Dark')}}</label> <label for="darkTheme"><input type="radio" id="darkTheme" name="theme" value="dark" /> {{_('Dark')}}</label>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<th>{{_('Scale')}}:</th> <th>{{_('Scale')}}:</th>
<td> <td>
<div class="inputs"> <div class="inputs">
<label for="fitBest"><input type="radio" id="fitBest" name="fitMode" value="66" /> {{_('Best')}}</label> <label for="fitBest"><input type="radio" id="fitBest" name="fitMode" value="66" /> {{_('Best')}}</label>
<label for="fitWidth"><input type="radio" id="fitWidth" name="fitMode" value="87" /> {{_('Width')}}</label> <label for="fitWidth"><input type="radio" id="fitWidth" name="fitMode" value="87" /> {{_('Width')}}</label>
<label for="fitHeight"><input type="radio" id="fitHeight" name="fitMode" value="72" /> {{_('Height')}}</label> <label for="fitHeight"><input type="radio" id="fitHeight" name="fitMode" value="72" /> {{_('Height')}}</label>
<label for="fitNative"><input type="radio" id="fitNative" name="fitMode" value="78" /> {{_('Native')}}</label> <label for="fitNative"><input type="radio" id="fitNative" name="fitMode" value="78" /> {{_('Native')}}</label>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<th>{{_('Rotate')}}:</th> <th>{{_('Rotate')}}:</th>
<td> <td>
<div class="inputs"> <div class="inputs">
<label for="r0"><input type="radio" id="r0" name="rotateTimes" value="0" /> 0&deg;</label> <label for="r0"><input type="radio" id="r0" name="rotateTimes" value="0" /> 0&deg;</label>
<label for="r90"><input type="radio" id="r90" name="rotateTimes" value="1" /> 90&deg;</label> <label for="r90"><input type="radio" id="r90" name="rotateTimes" value="1" /> 90&deg;</label>
<label for="r180"><input type="radio" id="r180" name="rotateTimes" value="2" /> 180&deg;</label> <label for="r180"><input type="radio" id="r180" name="rotateTimes" value="2" /> 180&deg;</label>
<label for="r270"><input type="radio" id="r270" name="rotateTimes" value="3" /> 270&deg;</label> <label for="r270"><input type="radio" id="r270" name="rotateTimes" value="3" /> 270&deg;</label>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<th>{{_('Flip')}}:</th> <th>{{_('Flip')}}:</th>
<td> <td>
<div class="inputs"> <div class="inputs">
<label for="vflip"><input type="checkbox" id="vflip" name="vflip" /> {{_('Horizontal')}}</label> <label for="vflip"><input type="checkbox" id="vflip" name="vflip" /> {{_('Horizontal')}}</label>
<label for="hflip"><input type="checkbox" id="hflip" name="hflip" /> {{_('Vertical')}}</label> <label for="hflip"><input type="checkbox" id="hflip" name="hflip" /> {{_('Vertical')}}</label>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<th>{{_('Direction')}}:</th> <th>{{_('Direction')}}:</th>
<td> <td>
<div class="inputs"> <div class="inputs">
<label for="leftToRight"><input type="radio" id="leftToRight" name="direction" value="0" /> {{_('Left to Right')}}</label> <label for="leftToRight"><input type="radio" id="leftToRight" name="direction" value="0" /> {{_('Left to Right')}}</label>
<label for="rightToLeft"><input type="radio" id="rightToLeft" name="direction" value="1" /> {{_('Right to Left')}}</label> <label for="rightToLeft"><input type="radio" id="rightToLeft" name="direction" value="1" /> {{_('Right to Left')}}</label>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<th>{{_('Next Page')}}:</th> <th>{{_('Next Page')}}:</th>
<td> <td>
<div class="inputs"> <div class="inputs">
<label for="resetToTop"><input type="radio" id="resetToTop" name="nextPage" value="0" /> {{_('Reset to Top')}}</label> <label for="resetToTop"><input type="radio" id="resetToTop" name="nextPage" value="0" /> {{_('Reset to Top')}}</label>
<label for="rememberPosition"><input type="radio" id="rememberPosition" name="nextPage" value="1" /> {{_('Remember Position')}}</label> <label for="rememberPosition"><input type="radio" id="rememberPosition" name="nextPage" value="1" /> {{_('Remember Position')}}</label>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<th>{{_('Scrollbar')}}:</th> <th>{{_('Scrollbar')}}:</th>
<td> <td>
<div class="inputs"> <div class="inputs">
<label for="showScrollbar"><input type="radio" id="showScrollbar" name="scrollbar" value="1" /> {{_('Show')}}</label> <label for="showScrollbar"><input type="radio" id="showScrollbar" name="scrollbar" value="1" /> {{_('Show')}}</label>
<label for="hideScrollbar"><input type="radio" id="hideScrollbar" name="scrollbar" value="0" /> {{_('Hide')}}</label> <label for="hideScrollbar"><input type="radio" id="hideScrollbar" name="scrollbar" value="0" /> {{_('Hide')}}</label>
</div> </div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div>
</div> </div>
<div class="closer icon-cancel-circled"></div>
</div> </div>
<div class="closer icon-cancel-circled"></div>
</div> </div>
</div> <div class="overlay"></div>
<div class="overlay"></div> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<script> <script>
$('input[name="direction"]').change(function() { var updateArrows = function () {
updateArrows(); if ($('input[name="direction"]:checked').val() === "0") {
}); $("#prev_page_key").html("&larr;");
</script> $("#next_page_key").html("&rarr;");
} else {
$("#prev_page_key").html("&rarr;");
$("#next_page_key").html("&larr;");
}
};
</script>
<script>
function setBookmark() {
// get csrf_token
let csrf_token = $("input[name='csrf_token']").val();
//This sends a bookmark update to calibreweb.
$.ajax(calibre.bookmarkUrl, {
method: "post",
data: {
csrf_token: csrf_token,
bookmark: currentImage
}
}).fail(function (xhr, status, error) {
console.error(error);
});
}
window.calibre = {
filePath: "{{ url_for('static', filename='js/libs/') }}",
cssPath: "{{ url_for('static', filename='css/') }}",
bookUrl: "{{ url_for('static', filename=comicfile) }}/",
bookmarkUrl: "{{ url_for('web.set_bookmark', book_id=comicfile, book_format=extension.upper()) }}",
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
useBookmarks: "{{ g.user.is_authenticated | tojson }}"
};
if (calibre.useBookmarks) {
currentImage = eval(calibre.bookmark)
}
document.onreadystatechange = function () {
if (document.readyState == "complete") {
init("{{ url_for('web.serve_book', book_id=comicfile, book_format=extension) }}");
updateArrows();
}
}
</script>
<script>
$('input[name="direction"]').change(function() {
updateArrows();
});
</script>
</body> </body>
</html> </html>

View File

@ -1497,7 +1497,7 @@ def read_book(book_id, book_format):
title = title + " #" + '{0:.2f}'.format(book.series_index).rstrip('0').rstrip('.') title = title + " #" + '{0:.2f}'.format(book.series_index).rstrip('0').rstrip('.')
log.debug(u"Start comic reader for %d", book_id) log.debug(u"Start comic reader for %d", book_id)
return render_title_template('readcbr.html', comicfile=all_name, title=title, return render_title_template('readcbr.html', comicfile=all_name, title=title,
extension=fileExt) extension=fileExt, bookmark=bookmark)
log.debug(u"Oops! Selected book title is unavailable. File does not exist or is not accessible") log.debug(u"Oops! Selected book title is unavailable. File does not exist or is not accessible")
flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"), flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"),
category="error") category="error")