前置条件
安装以下任意插件:
- violentmonkey
- tampermonkey
- greasemonkey
为什么? 需要依赖这些插件引用自定义脚本。
具体脚本
// ==UserScript==
// @name use original juejin url
// @namespace Violentmonkey Scripts
// @match https://juejin.cn/*
// @grant none
// @version 1.0
// @author null
// @description 2023/9/4 14:06:26
// ==/UserScript==
window.onload = function() {
var links = document.getElementsByTagName('a')
for (let i = 0, l = links.length; i < l; i++) {
links[i].href = decodeURL(links[i].href)
}
}
function decodeURL(link) {
// 使用replace方法提取并替换目标URL
const modifiedLink = link.replace(/.*?target=([^&]+)/, (match, targetUrl) => {
if (match) {
console.log('before replace url', link)
}
// 解码目标URL并返回替换后的内容
return decodeURIComponent(targetUrl);
});
return modifiedLink;
}