I've written a simple greasemonkey script to click the next button on a popup module presentation window when I hit the right-arrow-key.
I haven't been able to find much information about this online. The code seems to work if the window is not a popup, otherwise it just prints the console.log outside of the function and never gets to the inside of the function myEventHandler. I think the problem seems to be with window.addEventListener or that the events are simply not being fired.
// ==UserScript==
// @name Back/Next with Arrow Keys
// @version 1
// @grant none
// @run-at document-end
// ==/UserScript==
window.addEventListener("keypress", myEventHandler, false);
console.log('Outside function');
function myEventHandler(e) {
console.log('fired EventHandler');
var keyCode = e.keyCode;
console.log(e, keyCode, e.which)
if (keyCode === 39) {
console.log('Right arrow key pressed!');
var x = document.getElementsByClassName("btn cs-button inflexible slide-control-button-next slide-lockable");
x[0].click();
}
};
Any help would be greatly appreciated. I'll be happy to provide any more information that's needed.