-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
108 lines (91 loc) · 2.92 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const emotes = ["𐐘", "𐑀", "𐐿", "𐐃", "𐐫"];
const seperator = "ඞ";
const ee = {
0: "𐐘𐐘𐐘",
1: "𐐿𐐫𐐘",
2: "𐑀𐐿𐐿",
3: "𐐘𐐫𐐿",
4: "𐐘𐑀𐐃",
5: "𐑀𐐫𐐘",
6: "𐐃𐐃𐑀",
7: "𐐫𐐃𐐘",
8: "𐐃𐐃𐐃",
9: "𐑀𐐘𐐫",
};
window.onhashchange = () => window.location.reload();
const URL = location.href;
const codeFormEle = document.querySelector("#formCode");
const codeInputEle = document.querySelector("#codeLinkInput");
const codeResult = document.querySelector("#codeResult");
codeFormEle.addEventListener("submit", handleCode);
function handleCode(e) {
e.preventDefault();
let link = codeInputEle.value;
if (!link.startsWith("https://") && !link.startsWith("http://")) {
link = "https://" + link;
}
codeResult.value = URL + "#go/" + code(link);
}
if (URL.includes("#go")) {
const SUS_URL = decodeURIComponent(URL.split("go/")[1]);
const finalLink = decode(SUS_URL);
const redirectUrlEle = document.querySelector("#redirectURL");
redirectUrlEle.href = finalLink;
redirectUrlEle.textContent = finalLink;
document.querySelector("#redirectBtn").href = finalLink;
document.querySelector("#redirect-area").classList.remove("hidden");
const redirectWaitTime = 6;
const countdownTimerEle = document.querySelector("#countdownTimer");
countdownTimerEle.textContent = redirectWaitTime;
setInterval(() => {
if (countdownTimerEle.textContent <= 0) return;
countdownTimerEle.textContent = Number(countdownTimerEle.textContent) - 1;
}, 1000);
setTimeout(() => (window.location.href = finalLink), redirectWaitTime * 1000);
} else {
document.querySelector("#main-page").classList.remove("hidden");
}
function code(link) {
let linkCharCode = [];
let result = [];
Array.from(link).forEach((char) => linkCharCode.push(char.charCodeAt()));
linkCharCode.forEach((c) => {
const charArr = Array.from(c.toString());
charArr.forEach((c) => result.push(ee[c] + seperator));
result.push("𐐗");
});
return result.join("");
}
function decode(code) {
const arr = code.split(seperator);
const keys = Object.keys(arr);
let temp = [];
let result = "";
arr.forEach((item) => {
let c = item;
if (c.includes("𐐗")) {
const char = String.fromCharCode(temp.join(""));
result += char;
c = c.replace("𐐗", "");
temp = [];
}
const charCode = keys.find((key) => ee[key] === c);
temp.push(charCode);
});
return result;
}
const copyToClipboard = (str) => {
if (navigator && navigator.clipboard && navigator.clipboard.writeText)
return navigator.clipboard.writeText(str);
return Promise.reject("The Clipboard API is not available.");
};
let timeout;
const copyTextBtn = document.querySelector("#copyText");
copyTextBtn.addEventListener("click", () => {
copyToClipboard(codeResult.value);
copyTextBtn.textContent = "copied";
if(timeout) clearTimeout(timeout);
timeout = setTimeout(() => {
copyTextBtn.textContent = "click to copy";
}, 1000)
});