将百度重定向网址解析为直接网址
当前为
// ==UserScript==
// @name Baidu-unRedirect
// @name:zh-CN 百度反重定向
// @namespace https://greasyfork.org/zh-CN/users/42351
// @version 1.0
// @description Resolve Baidu redirect URL into direct
// @description:zh-CN 将百度重定向网址解析为直接网址
// @icon64 https://antecer.gitlab.io/amusingdevice/icon/antecer.ico
// @icon https://antecer.gitlab.io/amusingdevice/icon/antecer.ico
// @author Antecer
// @include http*://*baidu.com/*
// @grant GM_xmlhttpRequest
// @connect *
// @run-at document-end
// @compatible chrome 测试通过
// @compatible firefox 未测试
// @compatible opera 未测试
// @compatible safari 未测试
// ==/UserScript==
(() => {
// 创建sleep方法(用于async/await的延时处理)
const Sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// 解析百度重定向地址
(async () => {
while (!document.querySelector(`h3 a`)) await Sleep(1000);
let allowUpgrade = document.createElement(`meta`);
allowUpgrade.setAttribute('http-equiv', 'Content-Security-Policy');
allowUpgrade.setAttribute('content', 'upgrade-insecure-requests');
document.head.append(allowUpgrade);
document.querySelectorAll(`[href*="baidu.com/link?"]`).forEach((item) => {
let thisXhr = GM_xmlhttpRequest({
url: item.href,
method: 'HEAD',
onreadystatechange: (result) => {
if (result.readyState > 2) {
item.href = result.finalUrl;
thisXhr.abort();
}
}
});
});
})();
})();