-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
100 lines (64 loc) · 2.25 KB
/
script.js
File metadata and controls
100 lines (64 loc) · 2.25 KB
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
let map = new Map();
function loadJSON(filePath) {
let xhr = new XMLHttpRequest();
xhr.overrideMimeType("application/json");
xhr.open('GET', filePath, false);
xhr.send(null);
if (xhr.status === 200) {
return JSON.parse(xhr.responseText);
} else {
console.error('Error loading JSON:', xhr.status);
return null;
}
}
function iterateThroughObjects(data) {
data.forEach(function (item) {
map.set(item.name.toLowerCase(), item.link);
});
}
function startRedirect(){
let filePath = 'links.json';
let jsonData = loadJSON(filePath);
if (!jsonData) {
document.body.innerText = "Fail to load data!";
return;
}
iterateThroughObjects(jsonData);
const urlParams = new URLSearchParams(window.location.search);
let link = urlParams.get('link');
if (!link){
document.body.innerText = "query is empty!";
return;
}
document.body.innerText = "searching for " + link;
link = link.replaceAll(' ','-');
console.log(link)
let redirect = map.get(link.toLowerCase())
if (redirect === undefined){
let list = new Map();
map.forEach((value, key) => {
if (key.includes(link.toLowerCase())){
list.set(key, value)
console.log(value)
}
})
if (list.size === 0){
document.body.innerHTML = '<iframe src="404.html" width="100%" height="500">'
document.title = "Site not found"
return;
}
document.title = `Results for ${link}`
document.body.style.fontFamily = "KanitRegular, \"roboto\", sans-serif"
document.body.style.margin = "auto";
document.body.style.width = "50%";
document.body.innerHTML = `<h2 style="text-align: center">Results for: <span style="color: aqua">${link}</span></h2><hr><ul>`
list.forEach((value, key) => {
document.body.innerHTML += `<li style="text-align: center; list-style: none"><a style="color: white" href="${value}">${key}</a></li>`
})
document.body.innerHTML += `</ul>`
return;
}
document.body.innerText = "redirecting to " + redirect;
window.location.href = redirect;
}
startRedirect()