// ==UserScript== // @name Next Chapter Shortcut // @namespace https://greasyfork.org/en/users/55535-sllypper // @version 0.4 // @description And insta-scrolling for Mangakakalot & Manganelo // @author sllypper // @match https://mangakakalot.com/chapter/* // @match https://manganelo.com/chapter/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; let scrollAmount = 64; let repeatBy = 32; let scrollActions = {}; let buttons = document.getElementsByClassName('navi-change-chapter-btn'); if (buttons.length === 0) { buttons = document.getElementsByClassName('btn-navigation-chap'); if (buttons.length === 0) return; } buttons = buttons[0].childNodes; let prevButton = buttons[0]; let nextButton = buttons[buttons.length-1]; // if there's only one button if (buttons.length != 2) { // if it's the "next" button if (buttons[0].classList.contains("next") || buttons[0].classList.contains("navi-change-chapter-btn-next")) { // then we're in chapter 1 // and there's no prev button prevButton = null; } else { // else we're in the last chapter // and there's no next button nextButton = null; } } document.addEventListener("keydown", event => { if (event.code === "KeyW" || event.code === "KeyK") { if (scrollActions.up === undefined) { scrollAction(-scrollAmount, repeatBy, 'up'); } } else if (event.code === "KeyS" || event.code === "KeyJ") { if (scrollActions.down === undefined) { scrollAction(scrollAmount, repeatBy, 'down'); } } else if (event.code === "KeyC" && nextButton != null) { nextButton.click(); } else if (event.code === "KeyZ" && prevButton != null) { prevButton.click(); } }); document.addEventListener("keyup", event => { if (event.code === "KeyW" || event.code === "KeyK") { clearScrollAction('up'); } else if (event.code === "KeyS" || event.code === "KeyJ") { clearScrollAction('down'); } }); function scrollAction(amount, freq, id) { scrollActions[id] = setInterval(() => { window.scrollBy(0, amount); }, freq) } function clearScrollAction(id) { clearInterval(scrollActions[id]); scrollActions[id] = undefined; } })();