-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
script.js
135 lines (114 loc) · 3.37 KB
/
script.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const input = document.querySelector("#input");
const maskButton = document.querySelector("#mask-button");
const copy = document.querySelector("#copy-button");
const output = document.querySelector(".output");
const modeText = document.querySelector("#mode-button p");
let currentMode = "redirect";
// Event listeners
try {
input.addEventListener("keydown", (e) => {
if (e.key == "Enter") {
encode(input.value);
}
});
maskButton.addEventListener("click", () => {
encode(input.value);
});
copy.addEventListener("click", () => {
if (Boolean(output.querySelector("span")) == true) {
copy.innerText = `❌ Nothing to copy`;
} else {
navigator.clipboard.writeText(output.innerText);
copy.innerText = `✅ Copied Masked URL`;
}
setTimeout(() => {
copy.innerText = "🔗 Copy Masked URL";
}, 2000);
});
} catch (e) {
console.error(e);
}
// Change mode
function modeChange() {
if (currentMode == "text") {
currentMode = "redirect";
} else {
currentMode = "text";
}
modeText.style.transform = "translate(-150%, 0)";
setTimeout(() => {
modeText.innerText = `Mode: ${currentMode}`;
modeText.style.transform = "translate(0, 0)";
}, 350);
}
// Encode
function encode(value) {
if (value.replaceAll(" ", "") == "") {
output.innerHTML = `<span style="user-select: none">Input cannot be empty.</span>`;
} else {
let encodedValue = window.btoa(value);
if (currentMode == "redirect") {
output.innerText = `https://axorax.github.io/urlmskr/${encodedValue}`;
} else if (currentMode == "text") {
output.innerText = `https://axorax.github.io/urlmskr/?t=${encodedValue}`;
}
}
}
// Electric Surge
function createBolt() {
const bolt = document.createElement("div");
bolt.className = "bolt";
bolt.style.left = `${Math.random() * 100}%`;
const electricSurge = document.getElementById("electric-surge");
const electricSurgeRect = electricSurge.getBoundingClientRect();
const boltRect = bolt.getBoundingClientRect();
if (
boltRect.left + boltRect.width >
electricSurgeRect.left + electricSurgeRect.width
) {
const newLeft =
electricSurgeRect.left + electricSurgeRect.width - boltRect.width;
bolt.style.left = `${newLeft}px`;
}
electricSurge.appendChild(bolt);
setTimeout(() => {
bolt.remove();
}, 800);
}
setInterval(createBolt, 1000);
// Stars
const numberOfStars = Math.floor((window.innerWidth + window.innerHeight) / 16);
const starContainer = document.createElement("div");
starContainer.style.cssText = `
position: fixed;
top: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
overflow: hidden;
`;
document.body.appendChild(starContainer);
function createStar() {
const star = document.createElement("div");
const starSize = Math.random() * 3 + 1;
const x = Math.random() * window.innerWidth;
const y = Math.random() * window.innerHeight;
star.classList.add("star");
star.style.width = `${starSize}px`;
star.style.height = `${starSize}px`;
star.style.left = `${x}px`;
star.style.top = `${y}px`;
starContainer.appendChild(star);
}
for (let i = 0; i < numberOfStars; i++) {
createStar();
}
window.addEventListener("resize", function () {
while (starContainer.firstChild) {
starContainer.removeChild(starContainer.firstChild);
}
for (let i = 0; i < numberOfStars; i++) {
createStar();
}
});