-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathad.js
More file actions
74 lines (60 loc) · 1.98 KB
/
Copy pathad.js
File metadata and controls
74 lines (60 loc) · 1.98 KB
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
(function () {
const items = [
{
img: "https://0800webdev.github.io/UBGdir/logo.png",
link: "https://0800webdev.github.io/UBGdir/"
},
{
img: "https://i.postimg.cc/V6zNPQXW/7ad210998816426cb8bd123081203109-free.png",
link: "https://pgis.x10.mx/"
},
{
img: "https://i.postimg.cc/5Ng9k1mx/28470cf859534f4da1071c04d2f2ee6b-free.png",
link: "https://github.com/0800WebDev"
},
{
img: "https://https://0800webdev.github.io/UBGdir/logos/ubg98.png",
link: "www.ubg98.com"
}
];
function getDomain(url) {
return new URL(url).hostname.replace("www.", "");
}
function showRandom() {
const currentDomain = location.hostname.replace("www.", "");
const allowed = items.some(item => getDomain(item.link) === currentDomain);
if (!allowed) return;
const validItems = items.filter(item => {
return getDomain(item.link) !== currentDomain;
});
if (validItems.length === 0) return;
const randomItem = validItems[Math.floor(Math.random() * validItems.length)];
const container = document.createElement("div");
const a = document.createElement("a");
a.href = randomItem.link;
const img = document.createElement("img");
img.src = randomItem.img;
img.style.maxWidth = "150px";
img.style.cursor = "pointer";
a.appendChild(img);
container.appendChild(a);
// try to insert where script is
let scriptTag = document.currentScript;
// fallback if null (external/defer/async)
if (!scriptTag) {
const scripts = document.getElementsByTagName("script");
scriptTag = scripts[scripts.length - 1];
}
if (scriptTag && scriptTag.parentNode) {
scriptTag.parentNode.insertBefore(container, scriptTag);
} else {
// last fallback → append to body
document.body.appendChild(container);
}
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", showRandom);
} else {
showRandom();
}
})();