Skip to content

Commit 4c8ebf7

Browse files
committed
优化 首页/回答页切换后各个页面的脚本功能交叉混淆的处理方案
1 parent 691ad39 commit 4c8ebf7

1 file changed

Lines changed: 26 additions & 43 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN 知乎增强
44
// @name:zh-TW 知乎增強
55
// @name:ru Улучшение Zhihu
6-
// @version 2.3.20
6+
// @version 2.3.21
77
// @author X.I.U
88
// @description A more personalized Zhihu experience~
99
// @description:zh-CN 移除登录弹窗、屏蔽指定类别(视频、盐选、文章、想法、关注[赞同/关注了XX]等)、屏蔽低赞/低评回答、屏蔽用户、屏蔽关键词、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、区分问题文章、移除高亮链接、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、默认高清原图(无水印)、置顶显示时间、完整问题时间、直达问题按钮、默认站外直链...
@@ -1581,33 +1581,14 @@ function blockHotOther() {
15811581
block();
15821582
}
15831583

1584-
// 针对首页互相切换(知乎这里切换是动态加载的),为了避免功能交叉混乱,用户切换后刷新一下网页
1584+
// 将关注/推荐/热榜/专栏的选项去掉默认的点击事件改成静态链接(针对首页互相切换(知乎这里切换是动态加载的),为了避免功能交叉混乱
15851585
function switchHome() {
1586-
document.querySelectorAll('a[aria-controls=Topstory-follow], a[aria-controls=Topstory-hot], a[aria-controls=Topstory-column-square]').forEach((a)=>{
1587-
a.outerHTML = a.outerHTML;
1588-
})
1586+
document.querySelectorAll('a.TopstoryTabs-link').forEach((a)=>{a.outerHTML = a.outerHTML;})
1587+
document.querySelectorAll('a.TopstoryTabs-link[aria-controls=Topstory-recommend]').forEach((a)=>{a.addEventListener('click', function(e){e.preventDefault();document.cookie='tst=r; expires=Thu, 18 Dec 2099 12:00:00 GMT; domain=.zhihu.com; path=/';location.href=this.href;return false;})})
15891588
}
15901589

15911590
(function() {
15921591
if (window.onurlchange === undefined) {addUrlChangeEvent();} // Tampermonkey v4.11 版本添加的 onurlchange 事件 grant,可以监控 pjax 等网页的 URL 变化
1593-
window.addEventListener('urlchange', function(){ // 针对的是从单个回答页跳转到完整回答页时
1594-
if (location.pathname.indexOf('question') > -1 && location.pathname.indexOf('waiting') === -1 && location.pathname.indexOf('/answer/') === -1) { // 回答页 //
1595-
setTimeout(function(){
1596-
collapsedNowAnswer('.QuestionPage'); // 收起当前回答 + 快捷返回顶部
1597-
collapsedNowAnswer('.Question-main'); // 收起当前回答 + 快捷返回顶部
1598-
questionRichTextMore(); // 展开问题描述
1599-
blockUsers('question'); // 屏蔽指定用户
1600-
blockYanXuan(); // 屏蔽盐选内容
1601-
}, 300);
1602-
} else if (location.pathname == '/') { // 首页 - 推荐
1603-
// 针对首页互相切换(知乎这里切换是动态加载的),为了避免功能交叉混乱,用户切换后刷新一下网页
1604-
if (GM_info.scriptHandler === 'Violentmonkey' || (GM_info.scriptHandler === 'Tampermonkey' && parseFloat(GM_info.version.slice(0,4)) >= 4.18)) {
1605-
setTimeout(()=>{location.reload();},200);
1606-
} else {
1607-
location.reload();
1608-
}
1609-
}
1610-
})
16111592

16121593
removeLogin(); // 移除登录弹窗,Violentmonkey 不能延迟执行这个
16131594
cleanTitles(); // 净化标题消息,不能延迟执行
@@ -1639,6 +1620,8 @@ function switchHome() {
16391620
questionRichTextMore(); // 展开问题描述
16401621
if (location.pathname.indexOf('answer') == -1) { // 问题页而不是回答页
16411622
blockLowCount('question'); // 屏蔽低赞/低评回答
1623+
} else { // 将回答页的的查看全部回答选项去掉默认的点击事件改成静态链接,为了避免功能交叉混乱
1624+
document.querySelectorAll('div.Card.ViewAll>a').forEach((a)=>{a.outerHTML = a.outerHTML;})
16421625
}
16431626
blockUsers('question'); // 屏蔽指定用户
16441627
blockYanXuan(); // 屏蔽盐选内容
@@ -1708,32 +1691,32 @@ function switchHome() {
17081691
setInterval(function(){topTime_('.ContentItem.PinItem', 'ContentItem-meta')}, 300); // 置顶显示时间
17091692

17101693
} else { // 首页 //
1711-
switchHome();// 针对首页互相切换(知乎这里切换是动态加载的),为了避免功能交叉混乱,用户切换后刷新一下网页
1694+
switchHome(); // 将关注/推荐/热榜/专栏的选项去掉默认的点击事件改成静态链接(针对首页互相切换(知乎这里切换是动态加载的),为了避免功能交叉混乱
17121695
// 解决屏蔽类别后,因为首页信息流太少而没有滚动条导致无法加载更多内容的问题
17131696
document.lastElementChild.appendChild(document.createElement('style')).textContent = '.Topstory-container {min-height: 1500px;}';
17141697
if (menu_value('menu_blockTypeVideo')) document.lastChild.appendChild(document.createElement('style')).textContent = `.Card .ZVideoItem-video, nav.TopstoryTabs > a[aria-controls="Topstory-zvideo"] {display: none !important;}`;
17151698

17161699
collapsedNowAnswer('main div'); // 收起当前回答 + 快捷返回顶部
17171700
collapsedNowAnswer('.Topstory-container'); // 收起当前回答 + 快捷返回顶部
1718-
setInterval(function(){topTime_('.TopstoryItem', 'ContentItem-meta')}, 300); // 置顶显示时间
1719-
addTypeTips(); // 区分问题文章
1720-
addToQuestion(); // 直达问题按钮
1721-
if (location.pathname == '/') { // 推荐
1722-
blockLowCount('index'); // 屏蔽低赞/低评回答
1723-
blockUsers('index'); // 屏蔽指定用户
1724-
blockKeywords('index'); // 屏蔽指定关键词
1725-
blockType(); // 屏蔽指定类别(视频/文章等)
1726-
} else if (location.pathname == '/hot') { // 热榜
1727-
blockKeywords('index'); // 屏蔽指定关键词
1728-
blockHotOther(); // 屏蔽热榜杂项
1729-
} else if (location.pathname == '/follow') { // 关注
1730-
blockLowCount('follow'); // 屏蔽低赞/低评回答
1731-
blockUsers('follow'); // 屏蔽指定用户
1732-
blockKeywords('follow'); // 屏蔽指定关键词
1733-
blockType(); // 屏蔽指定类别(视频/文章等)
1734-
blockType('follow'); // 屏蔽指定类别(赞同了XX/关注了XX等
1735-
} else {
1736-
blockUsers();
1701+
if (location.pathname !== '/column-square'){ // 不是首页 - 专栏时
1702+
setInterval(function(){topTime_('.TopstoryItem', 'ContentItem-meta')}, 300); // 置顶显示时间
1703+
addTypeTips(); // 区分问题文章
1704+
addToQuestion(); // 直达问题按钮
1705+
if (location.pathname == '/') { // 推荐
1706+
blockLowCount('index'); // 屏蔽低赞/低评回答
1707+
blockUsers('index'); // 屏蔽指定用户
1708+
blockKeywords('index'); // 屏蔽指定关键词
1709+
blockType(); // 屏蔽指定类别(视频/文章等)
1710+
} else if (location.pathname == '/hot') { // 热榜
1711+
blockKeywords('index'); // 屏蔽指定关键词
1712+
blockHotOther(); // 屏蔽热榜杂项
1713+
} else if (location.pathname == '/follow') { // 关注
1714+
blockLowCount('follow'); // 屏蔽低赞/低评回答
1715+
blockUsers('follow'); // 屏蔽指定用户
1716+
blockKeywords('follow'); // 屏蔽指定关键词
1717+
blockType(); // 屏蔽指定类别(视频/文章等
1718+
blockType('follow'); // 屏蔽指定类别(赞同了XX/关注了XX等)
1719+
}
17371720
}
17381721
}
17391722
}

0 commit comments

Comments
 (0)