Skip to content

Commit 792a9e5

Browse files
authored
Merge pull request XIU2#312 from huangcheng/master
新增 [屏蔽热榜直播] 功能
2 parents 8fa205b + 143f0c4 commit 792a9e5

1 file changed

Lines changed: 73 additions & 2 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var menu_ALL = [
4444
['menu_blockTypeTopic', '话题 [搜索页]', '话题(搜索页)', false],
4545
['menu_blockTypeSearch', '杂志文章、盐选专栏、相关搜索等 [搜索页]', '相关搜索、杂志、盐选等(搜索页)', false],
4646
['menu_blockYanXuan', '屏蔽盐选内容 [问题页]', '屏蔽盐选内容(问题页)', false],
47+
['menu_blockLive', '屏蔽直播内容 [热榜]', '屏蔽直播内容 [热榜]', true],
4748
['menu_cleanSearch', '净化搜索热门 (默认搜索词及热门搜索)', '净化搜索热门', false],
4849
['menu_cleanTitles', '净化标题消息 (标题中的私信/消息)', '净化标题提醒', false],
4950
['menu_questionRichTextMore', '展开问题描述', '展开问题描述', false],
@@ -1377,6 +1378,70 @@ function questionInvitation(){
13771378
});
13781379
}
13791380

1381+
// 屏蔽热榜直播
1382+
function blockLive() {
1383+
if (!menu_value('menu_blockLive')) {
1384+
return;
1385+
}
1386+
1387+
const isLiveItem = (hotItem) => {
1388+
const linkItem = hotItem.querySelector('.HotItem-content a');
1389+
1390+
if (linkItem === null) {
1391+
return false;
1392+
}
1393+
1394+
const link = linkItem.href;
1395+
1396+
return /\/theater\/\d+/.test(link);
1397+
}
1398+
1399+
const block = () => {
1400+
removeLiveItems();
1401+
fixItemRank();
1402+
};
1403+
1404+
// 移除直播项
1405+
const removeLiveItems = () => {
1406+
const hotItems = document.querySelectorAll('.HotList-list .HotItem');
1407+
1408+
for (const item of hotItems) {
1409+
if (isLiveItem(item)) {
1410+
item.remove();
1411+
}
1412+
}
1413+
}
1414+
1415+
// 修复排行榜
1416+
const fixItemRank = () => {
1417+
const hotItems = document.querySelectorAll('.HotList-list .HotItem');
1418+
1419+
hotItems.forEach((item, index) => {
1420+
const rank = item.querySelector('.HotItem-index .HotItem-rank');
1421+
1422+
if (rank !== null) {
1423+
rank.innerText = index + 1;
1424+
}
1425+
});
1426+
}
1427+
1428+
const blockLive_content = (mutationsList, observer) => {
1429+
for (const mutation of mutationsList) {
1430+
for (const target of mutation.addedNodes) {
1431+
if (target.classList.contains('.HotItem')) {
1432+
block();
1433+
}
1434+
}
1435+
}
1436+
}
1437+
1438+
const observer = new MutationObserver(blockLive_content);
1439+
observer.observe(document, { childList: true, subtree: true });
1440+
1441+
// 初始移除
1442+
block();
1443+
}
1444+
13801445

13811446
(function() {
13821447
if (window.onurlchange === undefined) {addUrlChangeEvent();} // Tampermonkey v4.11 版本添加的 onurlchange 事件 grant,可以监控 pjax 等网页的 URL 变化
@@ -1396,7 +1461,12 @@ function questionInvitation(){
13961461
blockType(); // 屏蔽指定类别(视频/文章等)
13971462
}, 500);
13981463
} else if (location.pathname == '/hot') {
1399-
setTimeout(()=>{blockKeywords('index');}, 500);// 屏蔽指定关键词
1464+
setTimeout(()=>{
1465+
//屏蔽指定关键词
1466+
blockKeywords('index');
1467+
// 移除直播项
1468+
blockLive();
1469+
}, 500);
14001470
}
14011471
})
14021472

@@ -1507,9 +1577,10 @@ function questionInvitation(){
15071577
blockType(); // 屏蔽指定类别(视频/文章等)
15081578
} else if (location.pathname == '/hot') {
15091579
blockKeywords('index'); // 屏蔽指定关键词
1580+
blockLive(); // 屏蔽热榜直播
15101581
} else {
15111582
blockUsers();
15121583
}
15131584
}
15141585
}
1515-
})();
1586+
})();

0 commit comments

Comments
 (0)