Last active
February 21, 2019 23:58
-
-
Save manciuszz/c88dad5ff44cd171b8ee2c193251285f to your computer and use it in GitHub Desktop.
Does not being able to read manga on KissManga.com just by using your keyboard bother you? Well this quick script will fix that by enabling to change chapters by using keyboard left and right arrow keys while enabling support for W/S scrolling for the left handed people.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name KissManga Quick Enhancements | |
// @author Manciuszz | |
// @version 0.1 | |
// @match *://kissmanga.com/Manga/*/* | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let scrollTo = function(to, duration) { // Credits to https://gist.github.com/andjosh/6764939 for this one. | |
let element = document.scrollingElement || document.documentElement, | |
start = element.scrollTop, | |
change = to - start, | |
startDate = +new Date(), | |
easeInOutQuad = function(t, b, c, d) { | |
t /= d/2; | |
if (t < 1) return c/2*t*t + b; | |
t--; | |
return -c/2 * (t*(t-2) - 1) + b; | |
}, | |
animateScroll = function() { | |
const currentDate = +new Date(); | |
const currentTime = currentDate - startDate; | |
element.scrollTop = parseInt(easeInOutQuad(currentTime, start, change, duration)); | |
if (currentTime < duration) { | |
requestAnimationFrame(animateScroll); | |
} else { | |
element.scrollTop = to; | |
} | |
}; | |
animateScroll(); | |
}; | |
let scrollIncrementor = function(direction = 1, step = 100) { | |
return window.scrollY + step * direction; | |
}; | |
$(document).on('keydown', function(evt) { | |
if (evt.keyCode === 37) { // LEFT | |
window.location.href = $("img.btnPrevious").parent('a').get(0).href; | |
} else if (evt.keyCode === 39) { // RIGHT | |
window.location.href = $("img.btnNext").parent('a').get(0).href; | |
} else if (evt.keyCode === 87) { // W | |
scrollTo(scrollIncrementor(-1, 200), 100); | |
} else if (evt.keyCode === 83) { // S | |
scrollTo(scrollIncrementor(1, 200), 100); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment