禁用知乎外链中转直接跳到目标网站

知乎链接

// ==UserScript==
// @name         禁用知乎外链中转直接跳到目标网站
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  知乎链接
// @author       You
// @match        *.zhihu.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function () {
	"use strict";
  // v1 跳转过去更改url
	// let changeUrl = (function () {
	// 	let reg = /zhihu\.com\/\?target=[^]*/;
	// 	let url = location.href;
	// 	if (reg.test(url)) {
	// 		location.href = decodeURIComponent(location.href.split("target=")[1]);
	// 	}
	// })();

	// let scriptNode = document.createElement("script");
	// scriptNode.appendChild = changeUrl;
  // document.head.insertBefore(scriptNode, document.head.firstChild);
  

  //v2 点击后更新链接,如果使用监听事件,则带有href属性的目标元素获取繁琐
  window.addEventListener(
	"click",
	function (e) {
		let links = document.querySelectorAll('a[href^="https://link.zhihu.com/?target="]');
		for (let i = 0; i < links.length; i++) {
			let link = links[i];
			let url2 = decodeURIComponent(link.href.split("target=")[1]);
			link.href = url2;
		}
	},
	{ useCapture: true }
);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址