-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUrlRedirect.user.js
78 lines (71 loc) · 2.4 KB
/
UrlRedirect.user.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
// ==UserScript==
// @name 「水水」链接跳转「废弃」
// @namespace https://www.wdssmq.com/
// @version 0.2
// @author 沉冰浮水
// @description 跳转到正确的链接
// @license MIT
// @null ----------------------------
// @contributionURL https://github.com/wdssmq#%E4%BA%8C%E7%BB%B4%E7%A0%81
// @contributionAmount 5.93
// @null ----------------------------
// @link https://github.com/wdssmq/userscript
// @link https://afdian.net/@wdssmq
// @link https://greasyfork.org/zh-CN/users/6865-wdssmq
// @null ----------------------------
// @noframes
// @match https://jump.bdimg.com/f?kw=*
// @match https://c.pc.qq.com/middlem.html?pfurl=*
// @match https://mail.qq.com/cgi-bin/readtemplate?t=*
// @grant none
// ==/UserScript==
/* jshint esversion:6 */
(function () {
"use strict";
// 基础函数或变量
const curUrl = window.location.href;
// const curDate = new Date();
// const $ = window.$ || unsafeWindow.$;
// const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const _log = (...args) => console.log("[GM_链接跳转助手]\n", ...args);
// const _warn = (...args) => console.warn("[GM_]链接跳转助手\n", ...args);
// const _error = (...args) => console.error("[GM_链接跳转助手]\n", ...args);
// 获取链接中的参数
function fnGetParamInUrl(name, url) {
const match = RegExp("[?&]" + name + "=(?<value>[^&]*)").exec(url);
return match && decodeURIComponent(match.groups.value);
}
// 监测网址是否带有协议
function fnCheckUrl(url) {
if (url.indexOf("http") === 0) {
return url;
}
return "http://" + url;
}
// 各种中转页跳过
(() => {
const arrParamName = [
"pfurl",
"gourl",
];
arrParamName.forEach((paramName) => {
let paramValue = fnGetParamInUrl(paramName, curUrl);
if (paramValue) {
paramValue = fnCheckUrl(paramValue);
// _log(`${paramName}=${paramValue}`);
window.location.href = paramValue;
}
});
})();
// 百度贴吧的各种链接统一
(() => {
const arrHostList = [
"jump.bdimg.com",
];
const curHost = window.location.host;
if (arrHostList.includes(curHost)) {
const newUrl = window.location.href.replace(curHost, "tieba.baidu.com");
window.location.href = newUrl;
}
})();
})();