-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhead.js
38 lines (38 loc) · 1.3 KB
/
head.js
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
const endpoint = 'https://www.jsonstore.io/878f503bd43031d79787cb3caa2685bdbef8f8cd478d99037e93310b8f09986b';
const ebox = document.getElementById('erbox');
const fetchJSON = (a) => {
const f = new XMLHttpRequest()
f.open('GET', a, false)
f.onreadystatechange = oEvent => {
if (f.readyState === 4) {
if (f.status === 200) {} else {
ebox.style.display = 'block'
ebox.innerHTML = 'network seems to be offline'
}
}
}
f.onerror = () => {
ebox.style.display = 'block'
ebox.innerHTML = 'network error'
}
f.send()
return f.responseText
}
const isURL = (a) => {
const f = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/
if (f.test(a)) {
return true
} else {
return false
}
}
const hashh = window.location.hash.substr(1)
if (window.location.hash != '') {
const res = JSON.parse(fetchJSON(`${endpoint}/${hashh}`))
const data = res.result
if (data != null) {
if (isURL(data)) {
window.location.href = data
}
}
}