-
Notifications
You must be signed in to change notification settings - Fork 1
/
copier.js
45 lines (35 loc) · 1.33 KB
/
copier.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
document.addEventListener("mousedown", (e) => {
if (e.target.getAttribute('data-type') != "emoji" || e.ctrlKey == false) {return;}
let targetElement = e.target;
let imgSrc = "";
if (targetElement.tagName == "BUTTON") {
imgSrc = targetElement.children[0].src;
} else {
imgSrc = targetElement.src
}
navigator.clipboard.writeText(parseEmoteUrl(imgSrc));
document.body.appendChild(copySuccess(e.clientX, e.clientY));
});
function parseEmoteUrl(url) {
// sample: https://images-ext-1.discordapp.net/external/4Ffyh1-msFOxj_6OuVMBU_PjoTzy6KjWhMIUfX-xof0/%3Fsize%3D48/https/cdn.discordapp.com/emojis/720638944357646436.png
if (url.includes("/https/")) {
url = "https://" + url.split("/https/")[1];
};
return url.split("?")[0] + "?size=48";
}
function copySuccess(elmPosX, elmPosY) {
let rtnelem = document.createElement("p");
rtnelem.style.borderRadius = "10px"
rtnelem.style.padding = "2px"
rtnelem.style.backgroundColor = "rgb(50, 53, 59)";
rtnelem.style.color = "white";
rtnelem.style.position = "absolute";
rtnelem.style.top = elmPosY + "px";
rtnelem.style.left = elmPosX + "px";
rtnelem.style.zIndex = "9999";
rtnelem.textContent = "Successfully copied";
setTimeout(() => {
rtnelem.remove();
}, 1000);
return rtnelem;
};