// ==UserScript== // @name Batoto Quick Links // @namespace Doomcat55 // @version 0.2 // @description Add convenient links to Batoto series pages. // @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 bookmarkedPage = GM_getValue(seriesID); const linkedPage = bookmarkedPage || document.querySelector('.chapter_row:nth-last-child(2) td:first-child a').hash; if (linkedPage) { const quickLink = document.createElement('a'); quickLink.href = `/reader${linkedPage}`; quickLink.className = 'ipsButton_secondary'; quickLink.innerHTML = bookmarkedPage ? 'Resume reading' : 'First chapter'; const linkParent = document.querySelector('.__like.right'); linkParent.insertBefore(quickLink, linkParent.firstChild); } }