Created
August 29, 2016 04:45
-
-
Save JemiloII/d79b1f07375045d59efd54b328fa0403 to your computer and use it in GitHub Desktop.
Keyboard controls for Crunchyroll's manga reader beta. I could have used Es6 easy, however, this should be good for majority of browsers. :)
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
function loadScript(url, callback){ | |
var script = document.createElement("script"); | |
script.type = "text/javascript"; | |
if (script.readyState){ // IEvil | |
script.onreadystatechange = function () { | |
if (script.readyState === "loaded" || script.readyState === "complete"){ | |
script.onreadystatechange = null; | |
callback(); | |
} | |
}; | |
} else { // Real Browsers | |
script.onload = function () { | |
callback(); | |
}; | |
} | |
script.src = url; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} | |
// Load mousetrap for cross-browser keybindings | |
loadScript("https://craig.global.ssl.fastly.net/js/mousetrap/mousetrap.min.js", function () { | |
console.log('Crunchyroll Manga Beta Controls by Brian Jemilo II Loaded!!!'); | |
Mousetrap.bind(['left', 'down'], function () { | |
document.getElementsByClassName('type-next')[0].click(); | |
}); | |
Mousetrap.bind(['right', 'up'], function () { | |
document.getElementsByClassName('type-prev')[0].click(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment