-
Notifications
You must be signed in to change notification settings - Fork 0
/
404.html
48 lines (46 loc) · 1.96 KB
/
404.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
48
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Redirecting...</title>
<script type="text/javascript">
const homepage = "https://github.com/dj-ratty/beau-redirect"
// const locationNow = "https://dj-ratty.github.io/beau-redirect/en/part/123";
const locationNow = window.location;
function regexUrlDefaultPartNum(url) {
return /^https?:\/\/dj-ratty\.github\.io\/beau-redirect\/(?<lang>en|en\-ids|ru|es)\/part\/(?<part>\d+)$/.exec(url);
};
const resultRegex = regexUrlDefaultPartNum(locationNow);
if (!resultRegex) {
window.location.replace(homepage);
};
var lang = resultRegex.groups["lang"];
var partNumber = resultRegex.groups["part"];
var xhr = new XMLHttpRequest();
xhr.onload = function() {
try {
var payload = JSON.parse(xhr.response);
// Workaround IE 11 lack of support for new URL()
var url = document.createElement("a");
url.setAttribute("href", payload[partNumber]);
url.innerHTML = payload[partNumber];
document.body.appendChild(url);
var isInvalidPart = !(partNumber in payload);
if (isInvalidPart) {
window.location.replace(homepage);
} else {
location.replace(payload[partNumber]);
};
} catch (e) {
window.location.replace(homepage);
};
};
xhr.onerror = function () {
window.location.replace(homepage);
};
xhr.open("GET", "https://raw.githubusercontent.com/dj-ratty/beau-redirect/master/parts/" + lang + ".json");
xhr.send();
</script>
</head>
<body></body>
</html>