/
main.js
41 lines (36 loc) · 1.51 KB
/
main.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
window.addEventListener("load", () => {
const scrollbox = document.querySelector(".sidebar-scrollbox");
scrollbox.innerHTML = `<div class="version-box"><span>Version: </span></div>${scrollbox.innerHTML}`;
const currentVersion = window.BRIDGE_VERSION || 'latest';
const selectElement = document.createElement("select");
fetch("https://api.github.com/repos/matrix-org/matrix-appservice-irc/releases", {
cache: "force-cache",
}).then(res =>
res.json()
).then(releases => {
selectElement.innerHTML = "";
// N.B. We prefix with v
for (const version of ['latest', ...releases.map(r => r.tag_name)]) {
const option = document.createElement("option");
option.innerHTML = version;
selectElement.add(option);
if (currentVersion === version) {
option.setAttribute('selected', '');
}
}
}).catch(ex => {
console.error("Failed to fetch version data", ex);
})
const option = document.createElement("option");
option.innerHTML = 'loading...';
selectElement.add(option);
selectElement.addEventListener('change', (event) => {
const path = [
...window.location.pathname.split('/').slice(0, 2),
event.target.value,
...window.location.pathname.split('/').slice(3),
].join('/');
window.location = `${window.location.origin}${path}`;
});
document.querySelector(".version-box").appendChild(selectElement);
});