-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_functions.js
61 lines (52 loc) · 1.37 KB
/
custom_functions.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
window.onload = function() {
var snippets = document.getElementsByClassName('copycode');
for(var i = 0; i < snippets.length; i++) {
var snip = snippets[i];
snip.onmousemove = function(event) {
showHover(event)
}
snip.onmousedown = function(event) {
clickCopy(event)
}
snip.onmouseleave = function(event) {
leaveElement(event)
}
}
}
function showHover(e){
x=e.offsetX;
y=e.offsetY;
if (cursorInCopyButton(x,y)) {
e.target.style.cssText += "--color: orange"
} else {
e.target.style.cssText += "--color: white"
}
}
function leaveElement(e){
e.target.style.cssText += "--color: white"
}
function clickCopy(e){
x=e.offsetX;
y=e.offsetY;
el = e.target;
if (cursorInCopyButton(x,y)) {
selectText = el.textContent;
navigator.clipboard
.writeText(selectText)
.then(() => {
el.style.cssText += "--color: #a6e22e"
setTimeout(function(){
el.style.cssText += "--color: white"
}, 500);
})
.catch((error) => {
alert(`Copy failed! ${error}`);
});
}
}
function cursorInCopyButton(x,y) {
if ((x >= 1087) && (x <= 1146) && (y >= 6) && (y <= 35)) {
return true
}
return false
}