Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (64 loc) · 2.59 KB
/
Copy pathscript.js
File metadata and controls
71 lines (64 loc) · 2.59 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
const topbar = document.querySelector("[data-topbar]");
if (topbar) {
try {
if (localStorage.getItem("hideTranslateBar")) topbar.hidden = true;
} catch {}
topbar.querySelector("[data-topbar-close]").addEventListener("click", () => {
topbar.hidden = true;
try { localStorage.setItem("hideTranslateBar", "1"); } catch {}
});
}
const platform = navigator.userAgentData?.platform || navigator.platform || "";
const os = /mac/i.test(platform) ? "Mac" : /win/i.test(platform) ? "Windows" : /linux/i.test(platform) ? "Linux" : null;
if (os) {
for (const a of document.querySelectorAll("[data-os-label]")) a.textContent = `Download for ${os}`;
}
const builds = [
{ os: "Mac", label: "Mac with Apple silicon", match: /macos.*\.zip$/ },
{ os: "Windows", label: "Windows", match: /windows.*\.zip$/ },
{ os: "Linux", label: "Linux", match: /\.AppImage$/ },
];
fetch("https://api.github.com/repos/RompEmu/RomP/releases/latest")
.then(r => r.ok ? r.json() : null)
.then(release => {
if (!release) return;
const version = release.tag_name.replace(/^v/, "");
const tag = document.querySelector("[data-tag]");
tag.textContent = release.tag_name;
tag.hidden = false;
const url = build => release.assets.find(a => build.match.test(a.name))?.browser_download_url;
const mine = builds.find(b => b.os === os);
const direct = mine && url(mine);
if (direct) {
for (const a of document.querySelectorAll("[data-os-label]")) a.href = direct;
}
for (const p of document.querySelectorAll("[data-version]")) {
p.textContent = direct ? `Version ${version} for ${mine.label}` : `Version ${version} for macOS, Windows and Linux`;
}
const others = document.querySelector("[data-others]");
for (const build of builds) {
if (build === mine && direct) continue;
const href = url(build);
if (!href) continue;
const a = document.createElement("a");
a.href = href;
a.textContent = build.os;
others.append(a);
}
if (others.children.length) {
others.prepend(direct ? "Also for " : "Download for ");
others.hidden = false;
}
})
.catch(() => {});
for (const switcher of document.querySelectorAll(".switcher")) {
const buttons = switcher.querySelectorAll("button[data-look]");
for (const button of buttons) {
button.addEventListener("click", () => {
for (const b of buttons) b.setAttribute("aria-pressed", String(b === button));
for (const img of switcher.querySelectorAll("img[data-look]")) {
img.classList.toggle("is-on", img.dataset.look === button.dataset.look);
}
});
}
}