-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
71 lines (56 loc) · 2.23 KB
/
index.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
<html lang="en">
<head>
<script>
function LoadSimilarMapping() {
let queryString = window.location.search
console.log(queryString)
const urlParams = new URLSearchParams(queryString)
const regexExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
if (urlParams.has("uuid")) {
let uuid = urlParams.get("uuid")
try {
console.log(uuid)
const uuidValid = regexExp.test(uuid)
console.log(uuidValid)
if (uuidValid) {
console.log("regex successful")
lookupUUID(uuid)
}
} catch (error) {
redirect(uuid)
}
} else {
redirect("error")
}
}
function lookupUUID(uuid) {
console.log("looking up for uuid: " + uuid)
let filePrefix = uuid.slice(0, 2)
let prefix = uuid.slice(0, 3)
let xmlhttp = new XMLHttpRequest();
let url = "https://cdn.jsdelivr.net/gh/CarlosEsco/data@update/similar/" + filePrefix + "/" + prefix + ".html"
console.log("loading url: " + url)
xmlhttp.open("GET", url, false);
xmlhttp.send();
let data = xmlhttp.responseText.split("\n")
let matchingLine = data.find((line) => line.startsWith(uuid))
if (matchingLine != null && matchingLine.length > 0) {
let escapedJson = matchingLine.split(":::||@!@||:::")[1]
let obj = JSON.parse(escapedJson);
document.body.innerHTML = "";
let pre = document.createElement("pre")
pre.appendChild(document.createTextNode(JSON.stringify(obj, null, '\t')))
document.body.appendChild(pre);
} else {
console.log("No matching UUID")
redirect(uuid)
}
}
function redirect(error) {
location.href = error;
}
</script>
<title>MangaDex Similar</title>
</head>
<body onload="LoadSimilarMapping()"></body>
</html>