-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
139 lines (139 loc) · 4.73 KB
/
main.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function hashsplit(str) {
var list = str.match(/^#\/*(.*?)\/*$/)
if (list !== null && list[1] !== "") return list[1].split(/\/+/)
return null
}
function b62dec(str) {
if (str.length > 16 && /^\d+$/.test(str)) return str
str = require("base")("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").decode(str)
str = require("base")("0123456789").encode(str)
return str
}
function pdec(pointer) {
while (pointer.length % 4 !== 0) pointer += "="
return decodeURI(Base64.decode(pointer))
}
function redirect(dest) {
document.body.innerHTML = ""
document.body.style = "margin: 2.7rem"
console.log(Base64.encode(dest).replace(/=*$/, "").replace(/\+/g, "-").replace(/\//g, "_"))
if (silent === true) {
location.replace(dest)
document.body.innerHTML = `\n\t<h1 style="line-height: 3.14rem; font-weight: normal">Redirecting...</h1>\n\t<br />\n\t<a href="javascript:;" onclick="hash_func()">> Click to retry if needed.</a>\n`
}
if (silent === false) {
document.body.innerHTML = `\n\t<h1 style="line-height: 3.14rem; font-weight: normal">Click to redirect...</h1>\n\t<br />\n\t<a href="${encodeURI(dest)}">> ${dest}</a>\n`
}
}
function hash_func() {
var list = hashsplit(location.hash)
if (list === null) return null
for (var i = 0; i < list.length; i++) {
var para = list[i].replace(/=*\s*$/, "").trim()
if (para.match(/.=./)) {
var k = para.match(/^(.+?)=.+$/)[1]
var v = para.match(/^.+?=(.+)$/)[1]
if (v.startsWith("*")) {
v = v.replace(/^\*+/, "")
silent = false
}
v = clean_illegal(decodeURI(v.replace(/\*/g, "/")).trim())
switch (k) {
case "url":
try {
v = pdec(v)
if (v.startsWith("*")) {
silent = false
v = v.replace(/^\*+/, "")
}
if (v.startsWith("//")) v = v.replace(/^\/+/, "https://")
redirect(v)
} catch (e) {
console.log("Invalid pointer.")
document.body.innerHTML = ""
document.body.style = "margin: 2.7rem"
document.body.innerHTML = `\n\t<h1 style="line-height: 3.14rem; font-weight: normal">Invalid argument</h1>\n\t<br />\n\tPlease check again.\n`
}
break
case "b":
if (0);
else if (/^au/i.test(v)) redirect(`https://www.bilibili.com/audio/${v}`)
else if (/^av/i.test(v)) redirect(`https://www.bilibili.com/video/${v}`)
else if (/^bv/i.test(v)) redirect(`https://www.bilibili.com/video/${v}`)
else if (/^md/i.test(v)) redirect(`https://www.bilibili.com/bangumi/media/${v}`)
else if (/^ss/i.test(v)) redirect(`https://www.bilibili.com/bangumi/play/${v}`)
else (silent = false) || redirect(`https://www.bilibili.com/${v}`)
break
case "bu":
redirect(`https://space.bilibili.com/${v}`)
break
case "bv":
redirect(`https://www.bilibili.com/video/av${v}`)
break
case "e":
case "eg":
redirect(`https://e-hentai.org/g/${v}`)
break
case "es":
redirect(`https://e-hentai.org/s/${v}`)
break
case "ew":
redirect(`https://ehwiki.org/index.php?title=Special:Search&fulltext=Search&search=${encodeURIComponent(v)}`)
break
case "g":
case "gp":
redirect(`https://gelbooru.com/index.php?page=post&s=view&id=${v}`)
break
case "k":
case "kp":
redirect(`https://konachan.com/post/show/${v}`)
break
case "n":
if (0);
else if (v.startsWith("sm")) redirect(`https://www.nicovideo.jp/watch/${v}`)
else if (v.startsWith("ch")) redirect(`https://ch.nicovideo.jp/channel/${v}`)
else if (v.startsWith("im")) redirect(`https://seiga.nicovideo.jp/seiga/${v}`)
else if (v.startsWith("lv")) redirect(`https://live.nicovideo.jp/watch/${v}`)
else if (v.startsWith("mg")) redirect(`https://seiga.nicovideo.jp/watch/${v}`)
else if (v.startsWith("nw")) redirect(`https://news.nicovideo.jp/watch/${v}`)
else if (v.startsWith("so")) redirect(`https://www.nicovideo.jp/watch/${v}`)
break
case "nh":
redirect(`https://nhentai.net/g/${v}`)
break
case "nj":
redirect(`https://nijie.info/view.php?id=${v}`)
break
case "p":
case "pa":
redirect(`https://www.pixiv.net/artworks/${v}`)
break
case "pu":
redirect(`https://www.pixiv.net/users/${v}`)
break
case "t":
case "ts":
redirect(`https://twitter.com/i/status/${b62dec(v)}`)
break
case "ti":
redirect(`https://pbs.twimg.com/media/${v}.jpg?name=orig`)
break
case "w":
redirect(`https://m.weibo.cn/status/${v}`)
break
case "y":
case "yp":
redirect(`https://yande.re/post/show/${v}`)
break
case "yt":
redirect(`https://www.youtube.com/watch?v=${v}`)
break
default:
console.log("Unknown key.")
}
} else console.log("Nothing to do.")
}
}
var silent = true
hash_func()
window.addEventListener("hashchange", hash_func, false)