-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHyblockerThemeHelper.plugin.js
86 lines (76 loc) · 2.77 KB
/
HyblockerThemeHelper.plugin.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @name HyblockerThemeHelper
* @author Hyblocker
* @description Allows Themes to do things which require Javascript such as proper ripple and rendering the cursor as a light
* @version 1.0.0
* @source https://gist.github.com/rauenzi/e5f4d02fc3085a53872b0236cd6f8225
*/
// list of elements which we whitelist giving the mouse position to
const rippleElements = [
'message-2qnXI6',
'container-2Pjhx-',
'containerDefault--pIXnN',
'labelContainer-1BLJti',
'item-PXvHYJ',
'channel-2QD9_O',
'content-1x5b-n',
'listRow-hutiT_',
'resultFocused-3aIoYe',
'item-2J2GlB',
'actionButton-VzECiy',
'autocompleteRowVertical-q1K4ky',
'button-38aScr',
'clickable-1lCRLF',
'listRow-1iDGel',
'role-2irmRk',
];
module.exports = class PixelCordHelper {
constructor() {
this.mouseEventBind = this.mouseEventBind.bind(this)
}
load() {
document.body.addEventListener("mousemove", this.mouseEventBind("mouse"));
document.body.addEventListener("mousedown", this.mouseEventBind("click"));
}
start() {}
stop() {
document.body.removeEventListener("mousemove", this.mouseEventBind("mouse"));
document.body.removeEventListener("mousedown", this.mouseEventBind("click"));
}
mouseEventBind(param) {
return function (e) {
// Get the element
e = e || window.event;
let target = e.target || e.srcElement;
let foundTarget = false;
for (let j = 0; j < rippleElements.length; j++)
{
if (target.classList.contains(rippleElements[j])) {
foundTarget = true;
break;
}
}
// Check up to 5 parents up if the element has an after
for (let i = 0; i < 4 && !foundTarget; i++) {
if (target.parentElement != null) {
target = target.parentElement;
for (let j = 0; j < rippleElements.length && !foundTarget; j++) {
if (target.classList.contains(rippleElements[j]))
foundTarget = true;
}
}
}
if (foundTarget) {
// Get the mouse position relative to the element
const rect = target.getBoundingClientRect();
let x = e.clientX - rect.left; //x position within the element.
let y = e.clientY - rect.top; //y position within the element.
x -= rect.width / 2;
y -= rect.height / 2;
// Tell the CSS
target.style.setProperty("--" + param + "X", x + "px");
target.style.setProperty("--" + param + "Y", y + "px");
}
}
}
}