f0ckv1/s/shit.js
2017-12-03 00:06:30 +01:00

23 lines
473 B
JavaScript

const clickOnElementBinding = selector => {
return () => {
const elem = document.querySelector(selector);
if(elem)
elem.click();
};
};
const keybindings = {
"ArrowLeft": clickOnElementBinding("#next"),
"ArrowRight": clickOnElementBinding("#prev"),
"r": clickOnElementBinding("#random")
};
(() => {
document.addEventListener("keydown", e => {
if(e.key in keybindings) {
e.preventDefault();
keybindings[e.key]();
}
});
})();