forked from Coded-Eye/autoscrollext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (43 loc) · 1.37 KB
/
app.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
let x, y, myInterval;
let d=3;
document.addEventListener('contextmenu', (event) => {
if (!event.ctrlKey) event.preventDefault();
});
document.body.addEventListener("mousedown", (e) => {
if (!document.querySelector(".autoscrollCursorManager")) {
if (!e.ctrlKey && ((e.altKey && e.button === 0) || e.button === 2)) {
e.preventDefault();
browser.storage.sync.get(["acceleration", "interval"]).then(({ acceleration = 3, interval = 10 }) => {
d = acceleration;
const div = document.createElement("div");
div.classList.add("autoscrollCursorManager");
// Set initial position
x = e.clientX - d;
y = e.clientY - d;
div.style.left = `${x}px`;
div.style.top = `${y}px`;
document.body.appendChild(div);
// Start scrolling
myInterval = setInterval(() => {
window.scrollBy({
top: (y - e.clientY + d),
left: (x - e.clientX + d),
behavior: "smooth",
});
}, interval);
});
}
} else {
e.preventDefault()
document.querySelector('.autoscrollCursorManager').remove()
x = undefined
y = undefined
d = undefined
clearInterval(myInterval)
document.body.style.cursor = "default"
}
});
document.addEventListener("mousemove", (e) => {
x = e.clientX - d
y = e.clientY - d
});