forked from zZPiglet/Task
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoredirect.js
More file actions
40 lines (33 loc) · 1.22 KB
/
noredirect.js
File metadata and controls
40 lines (33 loc) · 1.22 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
/*
Skip the redirect page.
Quantumult X:
[rewrite_local]
# 简书
^https:\/\/links\.jianshu\.com\/go\?to= url script-echo-response https://raw.githubusercontent.com/zZPiglet/Task/master/noredirect.js
# 知乎
^https:\/\/link\.zhihu\.com\/\?target= url script-echo-response https://raw.githubusercontent.com/zZPiglet/Task/master/noredirect.js
Surge:
[Script]
# 简书
Jianshu = type=http-request,pattern=^https:\/\/links\.jianshu\.com\/go\?to=,script-path=https://raw.githubusercontent.com/zZPiglet/Task/master/noredirect.js
# 知乎
Zhihu = type=http-request,pattern=^https:\/\/link\.zhihu\.com\/\?target=,script-path=https://raw.githubusercontent.com/zZPiglet/Task/master/noredirect.js
[mitm]
hostname = links.jianshu.com, lins.zhihu.com
*/
const jianshur = /https:\/\/links\.jianshu\.com\/go\?to=(.*)/
const zhihur= /https:\/\/link\.zhihu\.com\/\?target=(.*)/
const oldurl = $request.url
let newurl = ''
if (oldurl.indexOf('jianshu') != -1) {
newurl += decodeURIComponent(jianshur.exec(oldurl)[1])
} else if (oldurl.indexOf('zhihu') != -1) {
newurl += decodeURIComponent(zhihur.exec(oldurl)[1])
}
const noredirect = {
status: "HTTP/1.1 302 Temporary Redirect",
headers: {
"Location": newurl
}
}
$done(noredirect)