(type)
| 1067 | |
| 1068 | // 屏蔽指定类别(视频/文章等) |
| 1069 | function blockType(type) { |
| 1070 | let name; |
| 1071 | // 一开始加载的信息流 + 添加标签样式 |
| 1072 | if (type === 'search') { // 搜索页 |
| 1073 | if (!menu_value('menu_blockTypeVideo') && !menu_value('menu_blockTypeArticle') && !menu_value('menu_blockTypePin') && !menu_value('menu_blockTypeTopic') && !menu_value('menu_blockTypeSearch')) return |
| 1074 | if (menu_value('menu_blockTypeSearch') && location.pathname === '/search') setTimeout(function(){document.querySelectorAll('.RelevantQuery').forEach((r)=>{r.parentElement.parentElement.hidden = true});}, 2000) |
| 1075 | name = 'h2.ContentItem-title a:not(.zhihu_e_toQuestion), a.KfeCollection-PcCollegeCard-link, h2.SearchTopicHeader-Title a' |
| 1076 | addSetInterval_(name); |
| 1077 | } else if (type === 'question') { // 问题页 |
| 1078 | if (!menu_value('menu_blockTypeVideo')) return |
| 1079 | document.lastChild.appendChild(document.createElement('style')).textContent = `.VideoAnswerPlayer, .VideoAnswerPlayer video, .VideoAnswerPlayer-video, .VideoAnswerPlayer-iframe {display: none !important;}`; |
| 1080 | name = '.VideoAnswerPlayer' |
| 1081 | document.querySelectorAll(name).forEach(function(item){blockType_(item);}) |
| 1082 | } else if (type === 'follow') { // 首页 - 关注 |
| 1083 | if (!menu_value('menu_blockTypeFollowAgree') && !menu_value('menu_blockTypeFollowQuestion')) return |
| 1084 | if (menu_value('menu_blockTypeFollowAgree')) name = '.TopstoryItem-isFollow .FeedSource-byline' // 赞同了XX |
| 1085 | if (menu_value('menu_blockTypeFollowQuestion')) {if (name) {name += ',.ContentItem[data-za-detail-view-path-module=QuestionItem]:not(.AnswerItem):not(.PinItem)'} else {name = '.ContentItem[data-za-detail-view-path-module=QuestionItem]:not(.AnswerItem):not(.PinItem)'}} // 关注了XX |
| 1086 | if (!name) return |
| 1087 | document.querySelectorAll(name).forEach(function(item){blockType_(item);}) |
| 1088 | } else { // 首页 |
| 1089 | if (!menu_value('menu_blockTypeVideo') && !menu_value('menu_blockTypeArticle') && !menu_value('menu_blockTypePin')) return |
| 1090 | if (menu_value('menu_blockTypeVideo')) document.lastChild.appendChild(document.createElement('style')).textContent = `.Card .ZVideoItem-video, .VideoAnswerPlayer video, nav.TopstoryTabs > a[aria-controls="Topstory-zvideo"] {display: none !important;}`; |
| 1091 | name = 'h2.ContentItem-title a:not(.zhihu_e_toQuestion)' |
| 1092 | if (menu_value('menu_blockTypePin')) name = 'h2.ContentItem-title a:not(.zhihu_e_toQuestion), .ContentItem.PinItem' |
| 1093 | document.querySelectorAll(name).forEach(function(item){blockType_(item);}) |
| 1094 | } |
| 1095 | |
| 1096 | // 后续加载的信息流 |
| 1097 | const observer = new MutationObserver(mutationsList => { |
| 1098 | for (const mutation of mutationsList) { |
| 1099 | for (const target of mutation.addedNodes) { |
| 1100 | if (target.nodeType != 1) return |
| 1101 | if (target.className === "Card SearchResult-Card" && target.dataset.zaDetailViewPathModule === undefined) { |
| 1102 | // 移除相关搜索 |
| 1103 | if (menu_value('menu_blockTypeSearch') && location.pathname === '/search' && location.search.indexOf('type=content') > -1) target.hidden = true; |
| 1104 | } else { |
| 1105 | blockType_(target.querySelector(name)); |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | }); |
| 1110 | observer.observe(document, { childList: true, subtree: true }); |
| 1111 | |
| 1112 | window.addEventListener('urlchange', function(){ |
| 1113 | addSetInterval_(name); |
| 1114 | // 移除相关搜索 |
| 1115 | if (menu_value('menu_blockTypeSearch') && location.pathname === '/search' && location.search.indexOf('type=content') > -1) setTimeout(function(){document.querySelectorAll('.RelevantQuery').forEach((r)=>{r.parentElement.parentElement.hidden = true});}, 1500) |
| 1116 | }) |
| 1117 | |
| 1118 | function blockType_(titleA) { |
| 1119 | if (!titleA) return // 判断是否为真 |
| 1120 | //console.log(titleA.href) |
| 1121 | if (location.pathname === '/search') { // 搜索页 |
| 1122 | if (location.search.indexOf('type=content') === -1) return // 仅限搜索页的 [综合] |
| 1123 | if (titleA.href.indexOf('/zvideo/') > -1 || titleA.href.indexOf('video.zhihu.com') > -1) { // 如果是视频 |
| 1124 | if (menu_value('menu_blockTypeVideo')) findParentElement(titleA, 'Card').remove(); |
| 1125 | } else if (titleA.href.indexOf('zhuanlan.zhihu.com') > -1) { // 如果是文章 |
| 1126 | if (menu_value('menu_blockTypeArticle')) findParentElement(titleA, 'Card SearchResult-Card').hidden = true; |
no test coverage detected