Last active
November 10, 2021 08:05
-
-
Save oa414/006020945cb0686f5c96e351ff3d43ec to your computer and use it in GitHub Desktop.
去除知乎点开外链的安全中心跳转
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ByeZhihuSecurity | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description 去除知乎点开外链的安全中心跳转 | |
// @author Lin Xiangyu | |
// @match https://www.zhihu.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function work(){ | |
// 删除 url 的 http(s)://link.zhihu.com/?target= 前缀,并 decode url | |
var replace = function(rawUrl) { | |
var url = rawUrl.replace('http://link.zhihu.com/?target=', ''); | |
url = url.replace('https://link.zhihu.com/?target=', ''); | |
var decodeUrl= decodeURIComponent(url); | |
return decodeUrl; | |
}; | |
// 找出所有外链链接,替换。 | |
var $elements = $("a[href^='http://link.zhihu.com']"); | |
$elements.each(function(i) { | |
console.log($(this).attr('href')); | |
var rawUrl =($(this).attr('href')); | |
console.log(replace(rawUrl)); | |
$(this).attr('href', replace(rawUrl)); | |
}); | |
$elements = $("a[href^='https://link.zhihu.com']"); | |
$elements.each(function(i) { | |
console.log($(this).attr('href')); | |
var rawUrl =($(this).attr('href')); | |
console.log(replace(rawUrl)); | |
$(this).attr('href', replace(rawUrl)); | |
}); | |
var replace2 = function(rawUrl) { | |
var url = rawUrl.replace('//link.zhihu.com/?target=', ''); | |
var decodeUrl= decodeURIComponent(url); | |
return decodeUrl; | |
}; | |
$elements = $("a[href^='//link.zhihu.com']"); | |
$elements.each(function(i) { | |
console.log($(this).attr('href')); | |
var rawUrl =($(this).attr('href')); | |
console.log(replace2(rawUrl)); | |
$(this).attr('href', replace2(rawUrl)); | |
}); | |
} | |
work(); | |
// 因为在时间线拉到下面动态获取新的问答的时候,Dom 会变化,所以简单粗暴地 6 秒钟检查替换一次。 | |
setInterval(work, 6000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
建议将后缀名改成
.user.js
这样点击raw
大部分插件管理器能直接识别 不需要手动复制raw
链接来手动添加了