MCPcopy
hub / github.com/ollm/OpenComic / loadBookmarks

Function loadBookmarks

scripts/reading.js:3656–3774  ·  view source on GitHub ↗
(bookmarksChild = false)

Source from the content-addressed store, hash-verified

3654
3655//Load the bookmarks in the current directory
3656function loadBookmarks(bookmarksChild = false)
3657{
3658 var bookmarksPath = {}, mainPath = dom.history.mainPath;
3659
3660 let images = [];
3661
3662 for(let key in readingCurrentBookmarks)
3663 {
3664 if(typeof readingCurrentBookmarks[key].path != 'undefined')
3665 {
3666 const bookmark = readingCurrentBookmarks[key];
3667 const path = p.join(mainPath, bookmark.path);
3668
3669 let bookmarkDirname = p.dirname(path);
3670
3671 if(typeof bookmarksPath[bookmarkDirname] === 'undefined') bookmarksPath[bookmarkDirname] = [];
3672
3673 let sha = sha1(path);
3674 images.push({path: path, sha: sha});
3675
3676 let name = p.basename(path);
3677 let chapterIndex = +app.extract(/^([0-9]+)\_sortonly/, name, 1);
3678
3679 bookmarksPath[bookmarkDirname].push({
3680 key: key,
3681 name: dom.translatePageName(decodeURI(p.basename(path).replace(/\.[^\.]*$/, ''))),
3682 index: (bookmarkDirname !== readingCurrentPath) ? bookmark.index : imagesPath[path],
3683 sha: sha,
3684 mainPath: mainPath,
3685 path: path,
3686 chapterIndex: chapterIndex,
3687 ebook: bookmark.ebook,
3688 progress: bookmark.progress,
3689 chapterProgress: bookmark.chapterProgress,
3690 });
3691 }
3692 }
3693
3694 let bookmarks = [];
3695
3696 for(let path in bookmarksPath)
3697 {
3698 bookmarksPath[path].sort(function (a, b) {
3699
3700 if (parseInt(a['index']) > parseInt(b['index'])) return 1;
3701
3702 if (parseInt(a['index']) < parseInt(b['index'])) return -1;
3703
3704 return 0;
3705 });
3706
3707 bookmarks.push({
3708 continueReading: false,
3709 current: (path === readingCurrentPath) ? true : false,
3710 path: path,
3711 name: dom.metadataPathName({path: path, name: p.basename(path)}, true),
3712 bookmarks: bookmarksPath[path],
3713 });

Callers 1

deleteBookmarkFunction · 0.85

Calls 1

sha1Function · 0.85

Tested by

no test coverage detected