Skip to content

Commit 7de8b48

Browse files
committed
新增 [移除高亮链接] 功能
1 parent 6dd0d7f commit 7de8b48

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ==UserScript==
22
// @name 知乎增强
3-
// @version 1.8.2
3+
// @version 1.8.3
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/heifetz/favicon.ico
@@ -37,6 +37,7 @@ var menu_ALL = [
3737
['menu_blockTypeArticle', '文章 [首页、搜索页]', '文章(首页、搜索页)', false],
3838
['menu_blockTypeTopic', '话题 [搜索页]', '话题(搜索页)', false],
3939
['menu_blockTypeSearch', '杂志文章、相关搜索等 [搜索页]', '相关搜索、杂志等(搜索页)', false],
40+
['menu_removeHighlightLink', '移除高亮链接', '移除高亮链接', true],
4041
['menu_blockYanXuan', '屏蔽盐选内容', '屏蔽盐选内容', false],
4142
['menu_cleanTitles', '净化标题消息 (标题中的私信/消息)', '净化标题提醒', false],
4243
['menu_questionRichTextMore', '展开问题描述', '展开问题描述', false],
@@ -930,6 +931,27 @@ function findParentElement(item, className, type = false) {
930931
}
931932

932933

934+
// 移除高亮链接
935+
function removeHighlightLink() {
936+
if (!menu_value('menu_removeHighlightLink')) return
937+
const callback = (mutationsList, observer) => {
938+
for (const mutation of mutationsList) {
939+
for (const target of mutation.addedNodes) {
940+
if (target.nodeType != 1 || target.tagName != 'A') break
941+
if (target.dataset.zaNotTrackLink && target.href.indexOf('https://www.zhihu.com/search?q=') > -1) {
942+
target.parentElement.replaceWith(target.textContent);
943+
}
944+
}
945+
}
946+
};
947+
const observer = new MutationObserver(callback);
948+
observer.observe(document, { childList: true, subtree: true });
949+
950+
// 针对的是打开网页后直接加载的前面几个回答(上面哪些是针对动态加载的回答)
951+
document.querySelectorAll('span > a[data-za-not-track-link][href^="https://www.zhihu.com/search?q="]').forEach(e => e.parentElement.replaceWith(e.textContent))
952+
}
953+
954+
933955
// 屏蔽盐选内容
934956
function blockYanXuan() {
935957
if (!menu_value('menu_blockYanXuan')) return
@@ -1434,8 +1456,11 @@ function questionInvitation(){
14341456
}
14351457

14361458
function start(){
1437-
if (location.hostname != 'zhuanlan.zhihu.com') collapsedAnswer(); // 一键收起回答
1438-
if (location.hostname != 'zhuanlan.zhihu.com') questionInvitation(); //默认折叠邀请
1459+
removeHighlightLink(); // 移除高亮链接
1460+
if (location.hostname != 'zhuanlan.zhihu.com') {
1461+
collapsedAnswer(); // 一键收起回答
1462+
questionInvitation(); // 默认折叠邀请
1463+
}
14391464
closeFloatingComments(); // 快捷关闭悬浮评论(监听点击事件,点击网页两侧空白处)
14401465
blockKeywords('comment'); // 屏蔽指定关键词(评论)
14411466
if (location.pathname.indexOf('question') > -1) { // 回答页 //

0 commit comments

Comments
 (0)