知乎 / CSDN / 简书 外链跳转
2021-05-28 20:07:00

知乎
CSDN
简书

Tempermonkey 代码:

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
// ==UserScript==
// @name 自动跳转 知乎、CSDN、简书 外链地址
// @namespace https://yfun.top/
// @version 0.0.1
// @description 自动跳转 知乎、CSDN、简书 外链地址
// @author YFun (@oCoke)
// @match *://*/*
// @grant none
// ==/UserScript==


(function() {

/* Page Script: 获取页面 URL 中的请求参数 */
function getParam(reqParam) {
reqParam = reqParam.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
const paraReg = new RegExp('[\\?&]' + reqParam + '=([^&#]*)');
const results = paraReg.exec(window.location);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}

/* 知乎 & CSDN 地址跳转 */
function redirectZhihu() {
// URL: https://link.zhihu.com/?target=https%3A//yfun.top/
window.location.href = getParam("target");
}
/* 简书地址跳转 */
function redirectJianShu() {
// URL: https://link.zhihu.com/?target=https%3A//yfun.top/
window.location.href = getParam("url");
}

/* Page Script: 嵌入页面脚本 */
if ((window.location.hostname == "link.zhihu.com" || window.location.hostname == "link.csdn.net") && window.location.pathname == '/') {
redirectZhihu();
}
if (window.location.hostname == "www.jianshu.com" && window.location.pathname == '/go-wild') {
redirectJianShu();
}
})();