Skip to content

Instantly share code, notes, and snippets.

@JamesHopbourn
Last active February 24, 2024 13:38
Show Gist options
  • Save JamesHopbourn/ec6c93ec6b1393067b8bc450f6321a6e to your computer and use it in GitHub Desktop.
Save JamesHopbourn/ec6c93ec6b1393067b8bc450f6321a6e to your computer and use it in GitHub Desktop.
const juejin = /https:\/\/link.juejin.cn\/\?target=(.*)/;
const oldurl = $request.url;
let newurl = "";
if (oldurl.indexOf("link.juejin.cn/?target") != -1){
newurl = decodeURIComponent(juejin.exec(oldurl)[1]);
}
newurl = newurl.indexOf("http") == 0 ? newurl : "http://" + newurl;
const isQuanX = typeof $notify != "undefined";
const newstatus = isQuanX ? "HTTP/1.1 302 Temporary Redirect" : 302;
const noredirect = {
status: newstatus,
headers: {
Location: newurl,
},
};
let resp = isQuanX ? noredirect : { response: noredirect };
resp = typeof $response != "undefined" ? noredirect : resp;
$done(resp);
const oldurl = $request.url;
const sspai = /https:\/\/sspai\.com\/link\?target=(.*)/;
let newurl = decodeURIComponent(sspai.exec(oldurl)[1]);
newurl = newurl.indexOf("http") == 0 ? newurl : "https://" + newurl;
const noredirect = {
status: 302,
headers: {
Location: newurl,
},
};
let resp = { response: noredirect };
$done(resp);
/*
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/asset/noredirect.js
^https:\/\/www\.jianshu\.com\/go-wild\?ac=\d&url= url script-echo-response https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
# 知乎
^https:\/\/link\.zhihu\.com\/\?target=(https?)?(%3A|:)?(\/\/|%2F%2F)?(.*?)(&source.*)?$ url 302 http://$4
# ^https:\/\/link\.zhihu\.com\/\?target= url script-echo-response https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
# 微博
^https?:\/\/weibo\.cn\/sinaurl\?(.*&)?(u|toasturl|goto)= url script-echo-response https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
^https:\/\/shop\.sc\.weibo\.com\/h5\/jump\/error\?(.*&)?url= url script-echo-response https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
^https?:\/\/(sinaurl|t)\.cn\/ url script-response-header https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
Surge:
[URL Rewrite]
^https:\/\/link\.zhihu\.com\/\?target=(https?)?(%3A|:)?(\/\/|%2F%2F)?(.*?)(&source.*)?$ http://$4 302
[Script]
# 少数派
sspai = type=http-request,pattern=^https:\/\/sspai\.com\/link\?target=,requires-body=1,max-size=0,script-path=https://gist.githubusercontent.com/JamesHopbourn/ec6c93ec6b1393067b8bc450f6321a6e/raw/url_redirect.js
# 简书
Jianshunoredirect = type=http-request,pattern=^https:\/\/links\.jianshu\.com\/go\?to=,script-path=https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
Jianshunoredirect2 = type=http-request,pattern=^https:\/\/www\.jianshu\.com\/go-wild\?ac=\d&url=,script-path=https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
# 知乎
# Zhihunoredirect = type=http-request,pattern=^https:\/\/link\.zhihu\.com\/\?target=,script-path=https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
# 微博
Weibonoredirect = type=http-request,pattern=^https?:\/\/weibo\.cn\/sinaurl\?(.*&)?(u|toasturl|goto)=,script-path=https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
Weibonoredircet2 = type=http-request,pattern=^https:\/\/shop\.sc\.weibo\.com\/h5\/jump\/error\?(.*&)?url=(.*),script-path=https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
Weibonoredirect3 = type=http-response,pattern=^https?:\/\/(sinaurl|t)\.cn\/,script-path=https://raw.githubusercontent.com/zZPiglet/Task/master/asset/noredirect.js
[mitm]
hostname = links.jianshu.com, www.jianshu.com, link.zhihu.com, weibo.cn, t.cn, sinaurl.cn, shop.sc.weibo.com, sspai.com, leetcode.cn
*/
const leetcode = /https:\/\/leetcode.cn\/link\/\?target=(.*)/
const sspai = /https:\/\/sspai\.com\/link\?target=(.*)/;
const juejin = /https:\/\/link.juejin.cn\/\?target=(.*)/;
const jianshur = /https:\/\/links\.jianshu\.com\/go\?to=(.*)/;
const jianshur2 = /https:\/\/www\.jianshu\.com\/go-wild\?ac=\d&url=(.*)/;
const zhihur = /https:\/\/link\.zhihu\.com\/\?target=(.*)/;
const weibor = /https?:\/\/weibo\.cn\/sinaurl\?(.*&)?(u|toasturl|goto)=(.*?)(&.*)?$/;
const weibor2 = /https:\/\/shop\.sc\.weibo\.com\/h5\/jump\/error\?(.*&)?url=(.*)/;
const oldurl = $request.url;
let newurl = "";
if (oldurl.indexOf("links.jianshu.com/go") != -1) {
newurl = decodeURIComponent(jianshur.exec(oldurl)[1]);
} else if (oldurl.indexOf("www.jianshu.com/go") != -1) {
newurl = decodeURIComponent(jianshur2.exec(oldurl)[1]);
} else if (oldurl.indexOf("link.zhihu.com/?target") != -1) {
newurl = decodeURIComponent(zhihur.exec(oldurl)[1].replace(/&source=.*/, ""));
} else if (oldurl.indexOf("weibo.cn/sinaurl") != -1) {
newurl = decodeURIComponent(weibor.exec(oldurl)[3]);
} else if (oldurl.indexOf("shop.sc.weibo.com/h5/jump/error") != -1) {
newurl = decodeURIComponent(weibor2.exec(oldurl)[2]);
} else if (oldurl.indexOf("sspai.com/link") != -1){
newurl = decodeURIComponent(sspai.exec(oldurl)[1]);
} else if (oldurl.indexOf("link.juejin.cn/?target") != -1){
newurl = decodeURIComponent(juejin.exec(oldurl)[1]);
} else if (oldurl.indexOf("leetcode.cn/link/?target=") != -1){
newurl = decodeURIComponent(leetcode.exec(oldurl)[1]);
} else if (oldurl.indexOf("sinaurl.cn") != -1 || oldurl.indexOf("t.cn") != -1) {
let headers = $response.headers;
newurl = headers.Location;
}
newurl = newurl.indexOf("http") == 0 ? newurl : "http://" + newurl;
const isQuanX = typeof $notify != "undefined";
const newstatus = isQuanX ? "HTTP/1.1 302 Temporary Redirect" : 302;
const noredirect = {
status: newstatus,
headers: {
Location: newurl,
},
};
let resp = isQuanX ? noredirect : { response: noredirect };
resp = typeof $response != "undefined" ? noredirect : resp;
$done(resp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment