-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
51 lines (42 loc) · 1.61 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
(function() {
if (document.querySelectorAll(".n-compare-pager").length) {
const HIDDEN_CLASS_FOR_ARROW = "n-compare-pager_hidden_yes";
const arrow = {
left: document.querySelector(".n-compare-pager_side_left"),
right: document.querySelector(".n-compare-pager_side_right"),
};
const canMove = {
toLeft: !arrow.left.classList.contains(HIDDEN_CLASS_FOR_ARROW),
toRight: !arrow.right.classList.contains(HIDDEN_CLASS_FOR_ARROW),
};
const KEYBOARD_ARROW = {
LEFT: 37,
RIGHT: 39,
};
function move({ keyCode }) {
if (keyCode === KEYBOARD_ARROW.LEFT && canMove.toLeft) {
arrow.left.click()
} else if (keyCode === KEYBOARD_ARROW.RIGHT && canMove.toRight) {
arrow.right.click();
}
}
document.addEventListener('keydown', move);
const test = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.target === arrow.right) {
canMove.toRight = !arrow.right.classList.contains(HIDDEN_CLASS_FOR_ARROW);
} else if (mutation.target === arrow.left) {
canMove.toLeft = !arrow.left.classList.contains(HIDDEN_CLASS_FOR_ARROW);
}
});
});
test.observe(arrow.right, {
attributes: true,
attributeFilter: ["class"]
});
test.observe(arrow.left, {
attributes: true,
attributeFilter: ["class"]
});
}
})();