-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
55 lines (47 loc) · 1.64 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(() => {
let lastSelected = null;
let isPressedShiftKey = false;
const getCurrentSelection = () => {
if (lastSelected !== null) return lastSelected;
return [...document.querySelectorAll('[role=button]')].filter((img) => getComputedStyle(img).border.includes('rgb(245, 243, 194)'))[0];
}
const emulatePaginate = (direction) => {
const currentSelection = getCurrentSelection();
if (currentSelection === undefined) return;
try {
switch (direction) {
case 'Up': {
lastSelected = currentSelection.previousElementSibling;
break;
}
case 'Down': {
lastSelected = currentSelection.nextElementSibling;
break;
}
}
lastSelected.click();
lastSelected.scrollIntoView();
} catch (_) {}
}
document.body.addEventListener('wheel', ({ deltaY }) => {
if (!isPressedShiftKey) return;
emulatePaginate(deltaY > 0 ? 'Up' : 'Down');
})
document.body.addEventListener('keyup', ({ key }) => {
if (key === 'Shift' && isPressedShiftKey) isPressedShiftKey = false;
})
document.body.addEventListener('keydown', ({ key, shiftKey }) => {
isPressedShiftKey = shiftKey;
if (document.activeElement.nodeName === 'INPUT') return;
switch (key) {
case 'ArrowUp': {
emulatePaginate('Up')
break;
}
case 'ArrowDown': {
emulatePaginate('Down')
break;
}
}
})
})();