Skip to content

Commit d8b09a9

Browse files
committed
新增 [默认站外直链] 功能
1 parent a2f7ed9 commit d8b09a9

1 file changed

Lines changed: 66 additions & 3 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ==UserScript==
22
// @name 知乎增强
3-
// @version 1.1.8
3+
// @version 1.1.9
44
// @author X.I.U
5-
// @description 移除登录弹窗、一键收起回答、置顶显示时间、区分问题文章、默认高清原图、默认折叠邀请
5+
// @description 移除登录弹窗、一键收起回答、置顶显示时间、区分问题文章、默认高清原图、默认站外直链、默认折叠邀请
66
// @match *://www.zhihu.com/*
77
// @match *://zhuanlan.zhihu.com/*
88
// @icon https://static.zhihu.com/static/favicon.ico
@@ -253,6 +253,68 @@ function topTime_people()
253253
})
254254
}
255255

256+
// 默认站外直链,来自:https://greasyfork.org/scripts/402808
257+
function directLink () {
258+
var equal, colon, external_href, protocol, path, new_href;
259+
//文字链接
260+
$("a[class*=\'external\']").each(function () {
261+
if ($(this).find("span").length > 0) {
262+
new_href = $(this).text();
263+
$(this).attr("href", new_href);
264+
}
265+
else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
266+
external_href = $(this).attr("href");
267+
new_href = external_href.substring(external_href = $(this).attr("href").indexOf("link.zhihu.com/?target=") + "link.zhihu.com/?target=".length);
268+
$(this).attr("href", decodeURIComponent(new_href));
269+
}
270+
else {
271+
external_href = $(this).attr("href");
272+
if (external_href.lastIndexOf("https%3A"))
273+
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("https%3A"));
274+
else if (external_href.lastIndexOf("http%3A%2F%2F"))
275+
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("http%3A"));
276+
$(this).attr("href", decodeURIComponent(new_href));
277+
}
278+
});
279+
280+
//卡片链接
281+
$("a[class*=\'LinkCard\']:not([class*=\'MCNLinkCard\']):not([class*=\'ZVideoLinkCard\'])").each(function () {
282+
if ($(this).find("LinkCard-title").length > 0 && $(this).find("LinkCard-title").indexOf("http") > -1) {
283+
new_href = $(this).find("LinkCard-title").text();
284+
$(this).attr("href", new_href);
285+
}
286+
else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
287+
external_href = $(this).attr("href");
288+
new_href = external_href.substring(external_href = $(this).attr("href").indexOf("link.zhihu.com/?target=") + "link.zhihu.com/?target=".length);
289+
$(this).attr("href", decodeURIComponent(new_href));
290+
}
291+
else {
292+
external_href = $(this).attr("href");
293+
if (external_href.lastIndexOf("https%3A"))
294+
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("https%3A"));
295+
else if (external_href.lastIndexOf("http%3A%2F%2F"))
296+
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("http%3A"));
297+
$(this).attr("href", decodeURIComponent(new_href));
298+
}
299+
});
300+
301+
//旧版视频卡片链接
302+
$("a.VideoCard-link").each(function () {
303+
if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
304+
external_href = $(this).attr("href");
305+
equal = external_href.lastIndexOf("http");
306+
colon = external_href.lastIndexOf("%3A");
307+
protocol = external_href.substring(equal, colon);
308+
path = external_href.substring(colon + 5, external_href.length);
309+
new_href = protocol + "://" + path;
310+
$(this).attr("href", decodeURIComponent(new_href));
311+
}
312+
});
313+
314+
//隐藏首页广告卡片
315+
$(".TopstoryItem--advertCard").hide();
316+
}
317+
256318
// 默认高清原图
257319
function originalPic(){
258320
$("img").each(function(){
@@ -368,7 +430,8 @@ function EventXMLHttpRequest() {
368430
}
369431
})
370432

371-
setInterval(originalPic,100)
433+
setInterval(originalPic,100); // 默认高清原图
434+
setInterval(directLink, 100); // 默认站外直链
372435

373436
//每个页面对应的功能函数
374437
if(window.location.href.indexOf("question") > -1){ // 回答页 //

0 commit comments

Comments
 (0)