forked from bucketfish/bucket-webring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirect.html
47 lines (36 loc) · 1.3 KB
/
redirect.html
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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="icon" type="image/jpg" href="assets/favicon.jpg"/>
<title>redirecting · bucket webring</title>
</head>
<body>
</body>
<script>
const DATA_FOR_WEBRING = `https://raw.githubusercontent.com/bucketfish/bucket-webring/master/webring.json`;
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const name = urlParams.get('name');
const dir = urlParams.get('to');
fetch(DATA_FOR_WEBRING)
.then((response) => response.json())
.then((sites) => {
// Find the current site in the data
const matchedSiteIndex = sites.findIndex(
(site) => site.name.toLowerCase() == name.toLowerCase()
);
const matchedSite = sites[matchedSiteIndex];
if (dir == "prev"){
let prevSiteIndex = matchedSiteIndex - 1;
if (prevSiteIndex < 0) prevSiteIndex = sites.length - 1;
window.location.replace(sites[prevSiteIndex].url);
}
else if (dir == "next"){
let nextSiteIndex = matchedSiteIndex + 1;
if (nextSiteIndex >= sites.length) nextSiteIndex = 0;
window.location.replace(sites[nextSiteIndex].url);
}
});
</script>
</html>