-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path404.html
89 lines (79 loc) · 2.74 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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="style.css">
<html>
<head>
<link rel="shortcut icon" type="image/jpg"
href="https://win98icons.alexmeub.com/icons/png/windows_update_large-2.png" />
<meta charset="utf-8" />
<title>Redirecting...</title>
<script>
/**
* Configuration goes here
*/
// Format: https://api.github.com/repos/{owner}/{repo}/issues/
var GITHUB_ISSUES_LINK =
"https://api.github.com/repos/fluteds/sdb/issues/";
var PATH_SEGMENTS_TO_SKIP = 0;
// Github username (will only redirect for issues by this user)
var ME = "fluteds";
/**
* DO NOT TOUCH ANYTHING BELOW THIS COMMENT UNLESS YOU KNOW WHAT YOU ARE DOING
*/
function isNumeric(num){ return !isNaN(num) }
function isUrl(url) {
// Regex from https://stackoverflow.com/a/3809435, with a modification to allow for TLDs of up to 24 characters
return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,24}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)+$/.test(url);
}
var isQuery = window.location.href.substr(-1) == "?";
var keyword = window.location.pathname.split("/")[PATH_SEGMENTS_TO_SKIP + 1];
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var payload = JSON.parse(xhr.response);
var issue = "";
// keyword is issue number
if (isNumeric(keyword)) {
issue = payload;
// keyword is shortened url name
} else {
for (var i=0; i<payload.length; i++) {
if (payload[i].body == keyword) {
// stop searching after first issue that matches
issue = payload[i];
break;
}
}
}
// if something was returned through GH
if (issue != "") {
// check if author is valid
if (issue.user.login == ME) {
var url = issue.title;
} else {
var url = "Failed authentication (GitHub Issue not created by owner of repository.) Not redirecting."
}
} else {
// no issue matched
var url = index.html;
}
// update page
document.getElementById("link").textContent = url;
// if current url ends in '?', just display the full url
if (isUrl(url) && !isQuery) {
// redirect user
window.location.replace(url);
}
}
// Send XHR request
var api_url = GITHUB_ISSUES_LINK;
// Get /issues/ID
if (isNumeric(keyword)) { api_url += keyword; }
else { api_url = api_url.slice(0, -1); }
xhr.open("GET", api_url);
xhr.send();
</script>
</head>
<body>
<h1 id="link">404</h1>
</body>
</html>