forked from lovmoon3k/useful-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollByDrag.js
47 lines (45 loc) · 1.4 KB
/
scrollByDrag.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
export default {
icon: `<i class="fa-solid fa-hand"></i>`,
name: {
en: "Scroll by dragging",
vi: "Cuộn web bằng cách kéo thả",
},
description: {
en: "Use this will turn the cursor into a scroller and use it again will return it back to normal.",
vi: "Bấm vào sẽ biến con trỏ thành con lăn và bấm lại nó sẽ đưa con trỏ trở lại bình thường",
},
blackList: [],
whiteList: [],
func: async function () {
let X, Y;
if (document.onmousedown && document.onmouseup && document.onmousemove) {
body.style.cursor = "auto";
document.onmousedown = document.onmouseup = document.onmousemove = null;
alert("Scroll by dragging DISABLED");
} else {
body.style.cursor = "all-scroll";
document.onmousedown = function (e) {
if ((e && !e.button) || (window.event && event.button & 1)) {
X = e.clientX;
Y = e.clientY;
return false;
}
};
document.onmouseup = function (e) {
if ((e && !e.button) || (window.event && event.button & 1)) {
X = Y = null;
return false;
}
};
document.onmousemove = function (e) {
if (X || Y) {
window.scrollBy(X - e.clientX, Y - e.clientY);
X = e.clientX;
Y = e.clientY;
return false;
}
};
alert("Scroll by dragging ENABLED");
}
},
};