Takubeh/assets/javascripts/main.js

24 lines
985 B
JavaScript
Raw Normal View History

2024-05-14 23:53:20 +02:00
const cachecaches = document.getElementsByClassName("cachecache");
for (const element of cachecaches) {
const link = document.createElement("a");
const separators = element.dataset.separators;
const protocol = element.dataset.param1.split("").reverse().join("");
let url = protocol;
for (let i = 0; i < separators.length; i++) {
url += separators[i] + element.dataset["param" + (i+2)].split("").reverse().join("");
}
let text = element.dataset.param2.split("").reverse().join("");
for (let i = 1; i < separators.length; i++) {
text += separators[i] + element.dataset["param" + (i+2)].split("").reverse().join("");
}
if (!element.dataset.noinner) {
link.innerText = url.replace(new RegExp(element.dataset.regex, 'i'), element.dataset.replace);
} else {
link.innerHTML = element.innerHTML;
}
link.href = url;
link.rel = "nofollow";
element.parentElement.insertBefore(link, element);
}
while (cachecaches.length > 0) cachecaches[0].remove();