rewrite keybindings
This commit is contained in:
parent
cbf41569dc
commit
bc991ca798
47
s/shit.js
47
s/shit.js
|
@ -1,27 +1,22 @@
|
||||||
function arrowKeys(e) {
|
const keybindings = {
|
||||||
switch(e.keyCode) {
|
'ArrowLeft': clickOnElementBinding('#next'),
|
||||||
case 39:
|
'ArrowRight': clickOnElementBinding('#prev'),
|
||||||
var prev = document.getElementById('prev');
|
'r': clickOnElementBinding('#random')
|
||||||
if(prev) prev.click();
|
};
|
||||||
break;
|
|
||||||
case 37:
|
function clickOnElementBinding(selector) {
|
||||||
var next = document.getElementById('next');
|
return () => {
|
||||||
if(next) next.click();
|
let elem = document.querySelector(selector);
|
||||||
break;
|
if(elem)
|
||||||
case 82:
|
elem.click();
|
||||||
var random = document.getElementById('random');
|
};
|
||||||
if(random) random.click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(document.readyState == 'complete' || document.readyState == 'loaded')
|
|
||||||
document.addEventListener('keydown', arrowKeys);
|
|
||||||
else {
|
|
||||||
if(/Chrome/i.test(navigator.userAgent))
|
|
||||||
window.addEventListener('load', function () {
|
|
||||||
document.addEventListener('keydown', arrowKeys);
|
|
||||||
});
|
|
||||||
else
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
|
||||||
document.addEventListener('keydown', arrowKeys);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
document.addEventListener('keydown', e => {
|
||||||
|
if(e.key in keybindings) {
|
||||||
|
e.preventDefault();
|
||||||
|
keybindings[e.key]();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user