// ==UserScript== // @name Batoto bookmarks // @namespace Doomcat55 // @version 0.1 // @description Add bookmarks to Batoto // @author Doomcat55 // @match *://bato.to/reader // @match *://bato.to/comic/_/comics/* // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== (function matchURL(path) { switch (true) { case /\/reader/.test(path): setBookmarks(); break; case /\/comic\/_\/comics/.test(path): showBookmarks(); break; } })(window.location.pathname); function parseSeriesID(link) { const text = link.match(/-r(\d+)/)[1]; return parseInt(text); } function setBookmarks() { const reader = document.getElementById('reader'); const observer = new MutationObserver(() => { const seriesID = parseSeriesID(document.querySelector('a[href*="/comic/"]').pathname); const pageID = window.location.hash; GM_setValue(seriesID, pageID); }); observer.observe(reader, {childList: true}); } function showBookmarks() { const seriesID = parseSeriesID(window.location.pathname); const currentPage = GM_getValue(seriesID); if (currentPage) { const element = document.createElement('a'); element.href = `/reader${currentPage}`; element.className = 'ipsButton_secondary'; element.innerHTML = 'Resume reading'; const elementParent = document.querySelector('.__like.right'); elementParent.insertBefore(element, elementParent.firstChild); } }