知乎增强

移除登录弹窗、屏蔽首页视频、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、屏蔽用户、屏蔽关键词、移除高亮链接、屏蔽盐选内容/热榜杂项、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认高清原图、默认站外直链

目前为 2023-08-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 知乎增强
  3. // @name:zh-CN 知乎增强
  4. // @name:zh-TW 知乎增強
  5. // @name:en Zhihu enhancement
  6. // @version 2.2.12
  7. // @author X.I.U
  8. // @description 移除登录弹窗、屏蔽首页视频、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、屏蔽用户、屏蔽关键词、移除高亮链接、屏蔽盐选内容/热榜杂项、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认高清原图、默认站外直链
  9. // @description:zh-TW 移除登錄彈窗、屏蔽首頁視頻、默認收起回答、快捷收起回答/評論、快捷回到頂部、屏蔽用戶、屏蔽關鍵詞、移除高亮鏈接、屏蔽鹽選內容、淨化搜索熱門、淨化標題消息、置頂顯示時間、完整問題時間、區分問題文章、默認高清原圖、默認站外直鏈...
  10. // @description:en A more personalized Zhihu experience~
  11. // @match *://www.zhihu.com/*
  12. // @match *://zhuanlan.zhihu.com/*
  13. // @exclude https://www.zhihu.com/signin*
  14. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAFo0lEQVR4nJWXT4hlVxHGf9/tJyYuzJtxIziQN8RBFDEtIWB0MW+Mi4CIk4UuAtqvAxPcqAkJRNxMshDUTc8s3TjdO3c9QbIKod+o4CIuZtRFDEi3EIgEM/02jpPIPZ+LqnPv6TeB4IHLPfeeP1X11VdV54i2vewtOhaITcQDdEgdthAdINAGNkgd0IEVbwR17rAmx1TniSVil6e0V0UKgJc8pWdfG5yvwqRhs1FQIyQ3trvcpxsVGd4xf/gelO24yV0usK1VB6APOMDMKSADBShIBWNwj1WwjClAzLEL0CMc86jj9cl/LgRs8ZjCJvexH5r/xAuJa260TatG6DosIee4lHO0ZnWDXH5bgYQ8uql122Iis2Xnj4JtRH675AIHMAQKuAsdrLV3dYXTwQ7Bir1jrzJ+Wyw698yVkLmgxgVg+PGjcPw8zD6JKcgFUcD94AoNa0eXkO600lVqXOPqPrPZNT6tjylYBRZfgp0n4GgFR7dDkEieeNys6ZPCBq4MCicXdFLWdIKBHtMFfC4JY8Hf/nxEyY0jmD+IM7Cgy77gxtto+jF4+NMj8+tY84YOLd8JnZJPpiDxI7shUigimJ2Gwxf5yLb9aryvffOj5+pXKbzJDxOVoIw7REkLhedno7+6CzffgdkpmE3z+5/Nrq7JJMfejc3bNj+TnT4tTyRtmLiAlARKliK09Uis2fsTPPcqvvwNdPlxuP4mbO+P4aQObz0cG958F77+mxMJh9kDcPh0IpCcUIerqycYuc8FGX7zczB/CI6O4cofAA9GjuRjUFhN2I0hmISlNFCUzCGMSkxqfFJw3XD6cXjuOt57A1YfpM/KSSEqY9zLo4w0psLsVnknyhkVYgNPMlRQh+qE63+GSsaBoK2VJcdTKTcKDLmhA/o1BDKFKzKl3aOJcoNBu3SHAAe4ahwwKgBkFRhdMMIc6Chzf+VphruT6urwZBh1aEQXjL/2fZidHoVP74/3xS8GP1IBLQ/hxuGonCLFxpZKjtTpDpRrSjYwYa2p4GcvoPm59ZFU5L54apvP4MZhY2XJMh1u+DB0Qk7ybaIR2EGHl34LV1/HGU5CsP8MbH4Gnvw1vPJX7G48pGw/OiLgyoEKf4PAYH0f6VtdIOAmlwCwugOrO0mDOHRodjrG/vGv9HvyQEprRwQjPB3rWg5oXBNR0A+Vf2wtJwDZaP5ZPL0fVv+B4zto5yJjKK6R0CUPMI7K6jUEsgpKGYqTwXpneGiExKnR4iuZ6d6Ggx/C7FNwdBuu/C6ROBmiUU/6PDuWhh9tEssQHxFQVlmP3wKfPY23Hotfe3+Eq8tYf/kJmE2jdK8pIPWJTDmJAFmq1We57iNnDQol9HWFDbr8rfg8eg+Wb8KV19DyrQjLa08hNal4/hD4l3D+LNr/HvhncPhC49+Ev5475DHfeUjjGrPt4jHY+upgvZOAPL0XRJ2fgwdPNS7IdvADuPgF7m15UDEDOhaXXKQT6RyAzTNw8DxMPxHWn/1p6ObMjc8+DjvfhVMvwOr9EcLjnwc6V38PL78Gq7vYG8PBxAqTzUbInJwoGtlbfA3tfCeEL/8G23sZEaAMIV99HW2egdW/m9Is/Mpf0O4bsPw7tY4os+OAbuUXHZKe8W3gVDLeEjr/uTgRHb0Hy7fyf0PUQd2YH4eZesrRmMBqDhF5gRFiIxSRQoGJxS0Kc8XNRSasHlqStOZ3Nf1aKVQzIKkMzeHTGZaRoEzWmyxIyw6zW6FRQ6c2NapC5pCjuAl5+Od7Tru41vxagEpTOeN0LAq7oe0lH0DeC6uVH0Lito03kbVUnmSrp+yE/967Y8dNfqEvdwD+L09a3BrgbqA/IZS4H4osLE3mHlDzYB30iUJ7XwwklrzPhXWk4ZIXdGxROM//g0ZbQrKXVza0EQcQiWNvcIuOXXbG6/n/AAwhLDO9HaqBAAAAAElFTkSuQmCC
  15. // @grant GM_xmlhttpRequest
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_unregisterMenuCommand
  18. // @grant GM_openInTab
  19. // @grant GM_getValue
  20. // @grant GM_setValue
  21. // @grant GM_notification
  22. // @grant GM_info
  23. // @grant window.onurlchange
  24. // @sandbox JavaScript
  25. // @license GPL-3.0 License
  26. // @run-at document-end
  27. // @namespace https://greasyfork.org/scripts/4122051
  28. // @supportURL https://github.com/XIU2/UserScript
  29. // @homepageURL https://github.com/XIU2/UserScript
  30. // ==/UserScript==
  31.  
  32. 'use strict';
  33. var menu_ALL = [
  34. ['menu_defaultCollapsedAnswer', '默认收起回答', '默认收起回答', true],
  35. ['menu_collapsedAnswer', '一键收起回答/评论', '一键收起回答/评论', true],
  36. ['menu_collapsedNowAnswer', '快捷收起回答/评论 (点击两侧空白处)', '快捷收起回答/评论', true],
  37. ['menu_backToTop', '快捷回到顶部 (右键两侧空白处)', '快捷回到顶部', true],
  38. ['menu_blockUsers', '屏蔽指定用户', '屏蔽指定用户', true],
  39. ['menu_customBlockUsers', '自定义屏蔽用户', '自定义屏蔽用户', ['故事档案局', '盐选推荐', '盐选科普', '盐选成长计划', '知乎盐选会员', '知乎盐选创作者', '盐选心理', '盐选健康必修课', '盐选奇妙物语', '盐选生活馆', '盐选职场', '盐选文学甄选', '盐选作者小管家', '盐选博物馆', '盐选点金', '盐选测评室', '盐选科技前沿', '盐选会员精品']],
  40. ['menu_blockKeywords', '屏蔽指定关键词', '屏蔽指定关键词', true],
  41. ['menu_customBlockKeywords', '自定义屏蔽关键词', '自定义屏蔽关键词', []],
  42. ['menu_blockType', '屏蔽指定类别 (视频/文章等)', '勾选 = 屏蔽该类别的信息流', ''],
  43. ['menu_blockTypeVideo', '视频 [首页、搜索页、问题页]', '视频(首页、搜索页、问题页)', true],
  44. ['menu_blockTypeArticle', '文章 [首页、搜索页]', '文章(首页、搜索页)', false],
  45. ['menu_blockTypeTopic', '话题 [搜索页]', '话题(搜索页)', false],
  46. ['menu_blockTypeSearch', '杂志文章、盐选专栏、相关搜索等 [搜索页]', '相关搜索、杂志、盐选等(搜索页)', false],
  47. ['menu_blockYanXuan', '盐选内容 [问题页]', '盐选内容(问题页)', false],
  48. ['menu_blockTypeLiveHot', '热榜文章、直播、广告等 [热榜]', '热榜文章、直播、广告等 [热榜]', true],
  49. ['menu_cleanSearch', '净化搜索热门 (默认搜索词及热门搜索)', '净化搜索热门', false],
  50. ['menu_cleanTitles', '净化标题消息 (标题中的私信/消息)', '净化标题提醒', false],
  51. ['menu_questionRichTextMore', '展开问题描述', '展开问题描述', false],
  52. ['menu_publishTop', '置顶显示时间', '置顶显示时间', true],
  53. ['menu_typeTips', '区分问题文章', '区分问题文章', true],
  54. ['menu_toQuestion', '直达问题按钮', '直达问题按钮', true]
  55. ], menu_ID = [];
  56. for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
  57. if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
  58. }
  59. registerMenuCommand();
  60.  
  61. // 注册脚本菜单
  62. function registerMenuCommand() {
  63. if (menu_ID.length > menu_ALL.length){ // 如果菜单ID数组多于菜单数组,说明不是首次添加菜单,需要卸载所有脚本菜单
  64. for (let i=0;i<menu_ID.length;i++){
  65. GM_unregisterMenuCommand(menu_ID[i]);
  66. }
  67. }
  68. for (let i=0;i<menu_ALL.length;i++){ // 循环注册脚本菜单
  69. menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]);
  70. if (menu_ALL[i][0] === 'menu_customBlockUsers') {
  71. if (menu_value('menu_blockUsers')) menu_ID[i] = GM_registerMenuCommand(`#️⃣ ${menu_ALL[i][1]}`, function(){customBlockUsers()});
  72. } else if (menu_ALL[i][0] === 'menu_customBlockKeywords') {
  73. if (menu_value('menu_blockKeywords')) menu_ID[i] = GM_registerMenuCommand(`#️⃣ ${menu_ALL[i][1]}`, function(){customBlockKeywords()});
  74. } else if (menu_ALL[i][0] === 'menu_blockType') {
  75. menu_ID[i] = GM_registerMenuCommand(`#️⃣ ${menu_ALL[i][1]}`, function(){menu_setting('checkbox', menu_ALL[i][1], menu_ALL[i][2], true, [menu_ALL[i+1], menu_ALL[i+2], menu_ALL[i+3], menu_ALL[i+4], menu_ALL[i+5], menu_ALL[i+6]])});
  76. } else if (menu_ALL[i][0] != 'menu_blockTypeVideo' && menu_ALL[i][0] != 'menu_blockTypeArticle' && menu_ALL[i][0] != 'menu_blockTypeTopic' && menu_ALL[i][0] != 'menu_blockTypeSearch' && menu_ALL[i][0] != 'menu_blockYanXuan' && menu_ALL[i][0] != 'menu_blockTypeLiveHot') {
  77. menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][3]?'✅':'❌'} ${menu_ALL[i][1]}`, function(){menu_switch(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`,`${menu_ALL[i][2]}`)});
  78. }
  79. }
  80. menu_ID[menu_ID.length] = GM_registerMenuCommand('💬 反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/419081/feedback', {active: true,insert: true,setParent: true});});
  81. }
  82.  
  83.  
  84. // 菜单开关
  85. function menu_switch(menu_status, Name, Tips) {
  86. if (menu_status == 'true'){
  87. GM_setValue(`${Name}`, false);
  88. GM_notification({text: `已关闭 [${Tips}] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});
  89. }else{
  90. GM_setValue(`${Name}`, true);
  91. GM_notification({text: `已开启 [${Tips}] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});
  92. }
  93. registerMenuCommand(); // 重新注册脚本菜单
  94. };
  95.  
  96.  
  97. // 返回菜单值
  98. function menu_value(menuName) {
  99. for (let menu of menu_ALL) {
  100. if (menu[0] == menuName) {
  101. return menu[3]
  102. }
  103. }
  104. }
  105.  
  106.  
  107. // 脚本设置
  108. function menu_setting(type, title, tips, line, menu) {
  109. let _br = '', _html = `<style class="zhihuE_SettingStyle">.zhihuE_SettingRoot {position: absolute;top: 50%;left: 50%;-webkit-transform: translate(-50%, -50%);-moz-transform: translate(-50%, -50%);-ms-transform: translate(-50%, -50%);-o-transform: translate(-50%, -50%);transform: translate(-50%, -50%);width: auto;min-width: 400px;max-width: 600px;height: auto;min-height: 150px;max-height: 400px;color: #535353;background-color: #fff;border-radius: 3px;}
  110. .zhihuE_SettingBackdrop_1 {position: fixed;top: 0;right: 0;bottom: 0;left: 0;z-index: 203;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;overflow-x: hidden;overflow-y: auto;-webkit-transition: opacity .3s ease-out;transition: opacity .3s ease-out;}
  111. .zhihuE_SettingBackdrop_2 {position: absolute;top: 0;right: 0;bottom: 0;left: 0;z-index: 0;background-color: rgba(18,18,18,.65);-webkit-transition: background-color .3s ease-out;transition: background-color .3s ease-out;}
  112. .zhihuE_SettingRoot .zhihuE_SettingHeader {padding: 10px 20px;color: #fff;font-weight: bold;background-color: #3994ff;border-radius: 3px 3px 0 0;}
  113. .zhihuE_SettingRoot .zhihuE_SettingMain {padding: 10px 20px;border-radius: 0 0 3px 3px;}
  114. .zhihuE_SettingHeader span {float: right;cursor: pointer;}
  115. .zhihuE_SettingMain input {margin: 10px 6px 10px 0;cursor: pointer;vertical-align:middle}
  116. .zhihuE_SettingMain label {margin-right: 20px;user-select: none;cursor: pointer;vertical-align:middle}
  117. .zhihuE_SettingMain hr {border: 0.5px solid #f4f4f4;}
  118. [data-theme="dark"] .zhihuE_SettingRoot {color: #adbac7;background-color: #343A44;}
  119. [data-theme="dark"] .zhihuE_SettingHeader {color: #d0d0d0;background-color: #2D333B;}
  120. [data-theme="dark"] .zhihuE_SettingMain hr {border: 0.5px solid #2d333b;}</style>
  121. <div class="zhihuE_SettingBackdrop_1"><div class="zhihuE_SettingBackdrop_2"></div><div class="zhihuE_SettingRoot">
  122. <div class="zhihuE_SettingHeader">${title}<span class="zhihuE_SettingClose" title="点击关闭"><svg class="Zi Zi--Close Modal-closeIcon" fill="currentColor" viewBox="0 0 24 24" width="24" height="24"><path d="M13.486 12l5.208-5.207a1.048 1.048 0 0 0-.006-1.483 1.046 1.046 0 0 0-1.482-.005L12 10.514 6.793 5.305a1.048 1.048 0 0 0-1.483.005 1.046 1.046 0 0 0-.005 1.483L10.514 12l-5.208 5.207a1.048 1.048 0 0 0 .006 1.483 1.046 1.046 0 0 0 1.482.005L12 13.486l5.207 5.208a1.048 1.048 0 0 0 1.483-.006 1.046 1.046 0 0 0 .005-1.482L13.486 12z" fill-rule="evenodd"></path></svg></span></div>
  123. <div class="zhihuE_SettingMain"><p>${tips}</p><hr>`
  124. if (line) _br = '<br>'
  125. for (let i=0; i<menu.length; i++) {
  126. if (GM_getValue(menu[i][0])) {
  127. _html += `<label><input name="zhihuE_Setting" type="checkbox" value="${menu[i][0]}" checked="checked">${menu[i][1]}</label>${_br}`
  128. } else {
  129. _html += `<label><input name="zhihuE_Setting" type="checkbox" value="${menu[i][0]}">${menu[i][1]}</label>${_br}`
  130. }
  131. }
  132. _html += `</div></div></div>`
  133. document.body.insertAdjacentHTML('beforeend', _html); // 插入网页末尾
  134. setTimeout(function() { // 延迟 100 毫秒,避免太快
  135. // 关闭按钮 点击事件
  136. document.querySelector('.zhihuE_SettingClose').onclick = function(){this.parentElement.parentElement.parentElement.remove();document.querySelector('.zhihuE_SettingStyle').remove();}
  137. // 点击周围空白处 = 点击关闭按钮
  138. document.querySelector('.zhihuE_SettingBackdrop_2').onclick = function(event){if (event.target == this) {document.querySelector('.zhihuE_SettingClose').click();};}
  139. // 复选框 点击事件
  140. document.getElementsByName('zhihuE_Setting').forEach(function (checkBox) {
  141. checkBox.addEventListener('click', function(){if (this.checked) {GM_setValue(this.value, true);} else {GM_setValue(this.value, false);}});
  142. })
  143. }, 100)
  144. }
  145.  
  146.  
  147. // 添加收起回答观察器
  148. function getCollapsedAnswerObserver() {
  149. if (!window._collapsedAnswerObserver) {
  150. const observer = new MutationObserver(mutations => {
  151. for (const mutation of mutations) {
  152. if (mutation.target.hasAttribute('script-collapsed')) return
  153. // 短的回答
  154. if (mutation.target.classList.contains('RichContent')) {
  155. for (const addedNode of mutation.addedNodes) {
  156. if (addedNode.nodeType != Node.ELEMENT_NODE) continue
  157. if (addedNode.className != 'RichContent-inner') continue
  158. if (addedNode.offsetHeight < 400) break
  159. //console.log('111',addedNode, addedNode.classList, addedNode.classList.contains('RichContent-inner'), addedNode.offsetHeight, addedNode.textContent.length)
  160. const button = mutation.target.querySelector('.ContentItem-actions.Sticky [data-zop-retract-question]');
  161. if (button) {
  162. mutation.target.setAttribute('script-collapsed', '');
  163. button.click();
  164. return
  165. }
  166. }
  167. // 长的回答
  168. } else if (mutation.target.tagName === 'DIV' && !mutation.target.style.cssText && !mutation.target.className) {
  169. if (mutation.target.parentElement.hasAttribute('script-collapsed')) return
  170. //console.log('222',mutation.target, mutation.target.querySelector('.ContentItem-actions.Sticky [data-zop-retract-question]'))
  171. const button = mutation.target.querySelector('.ContentItem-actions.Sticky [data-zop-retract-question]');
  172. if (button) {
  173. mutation.target.parentElement.setAttribute('script-collapsed', '');
  174. button.click();
  175. return
  176. }
  177. }
  178. }
  179. })
  180.  
  181. observer.start = function() {
  182. if (!this._active) {
  183. this.observe(document, { childList: true, subtree: true });
  184. this._active = true;
  185. }
  186. }
  187. observer.end = function() {
  188. if (this._active) {
  189. this.disconnect();
  190. }
  191. }
  192.  
  193. window.addEventListener('urlchange', function() {
  194. observer[location.href.indexOf('/answer/') === -1 ? 'start' : 'end']();
  195. })
  196. window._collapsedAnswerObserver = observer;
  197. }
  198. return window._collapsedAnswerObserver
  199. }
  200.  
  201.  
  202. // 默认收起回答
  203. function defaultCollapsedAnswer() {
  204. if (!menu_value('menu_defaultCollapsedAnswer')) return
  205. const observer = getCollapsedAnswerObserver();
  206. if (location.href.indexOf('/answer/') === -1) {
  207. observer.start();
  208. }
  209. }
  210.  
  211.  
  212. // 一键收起回答+评论(全部)
  213. function collapsedAnswer() {
  214. if (!menu_value('menu_collapsedAnswer')) return
  215. //console.log('1111', document.querySelector('.CornerAnimayedFlex'))
  216. if (document.querySelector('.CornerAnimayedFlex') && !document.getElementById('collapsed-button')) {
  217. // 向网页中插入收起全部回答按钮+样式+绑定点击事件
  218. document.head.appendChild(document.createElement('style')).textContent = '.CornerButton{margin-bottom:8px !important;}.CornerButtons{bottom:45px !important;}';
  219. document.querySelector('.CornerAnimayedFlex').insertAdjacentHTML('afterBegin', '<button id="collapsed-button" data-tooltip="收起全部回答/评论" data-tooltip-position="left" data-tooltip-will-hide-on-click="false" aria-label="收起全部回答/评论" type="button" class="' + document.querySelector('.CornerAnimayedFlex>button').className + '"><svg class="ContentItem-arrowIcon is-active" aria-label="收起全部回答/评论" fill="currentColor" viewBox="0 0 24 24" width="24" height="24"><path d="M16.036 19.59a1 1 0 0 1-.997.995H9.032a.996.996 0 0 1-.997-.996v-7.005H5.03c-1.1 0-1.36-.633-.578-1.416L11.33 4.29a1.003 1.003 0 0 1 1.412 0l6.878 6.88c.782.78.523 1.415-.58 1.415h-3.004v7.005z"></path></svg></button>');
  220. document.getElementById('collapsed-button').onclick = function () {
  221.  
  222. // 收起所有评论(悬浮的 [收起评论])
  223. document.querySelectorAll('.Comments-container').forEach(function (el) {
  224. let commentCollapseButton = getXpath('//button[text()="收起评论"]', el)
  225. if (commentCollapseButton) commentCollapseButton.click();
  226. });
  227. // 收起所有评论(固定的 [收起评论])
  228. document.querySelectorAll('.RichContent >.ContentItem-actions>button:first-of-type').forEach(function (el) {
  229. if (el.textContent.indexOf('收起评论') > -1) el.click()
  230. });
  231.  
  232. if (location.pathname === '/' || location.pathname === '/hot' || location.pathname === '/follow') {// 对于首页的关注、推荐、热榜
  233. document.querySelectorAll('.ContentItem-rightButton').forEach(function (el) {if (el.hasAttribute('data-zop-retract-question')) {el.click();};});
  234. } else {
  235. // 被 getCollapsedAnswerObserver 函数收起过的,固定 [收起] 按钮
  236. document.querySelectorAll('[script-collapsed]').forEach(function(scriptCollapsed) {scriptCollapsed.querySelectorAll('.ContentItem-actions [data-zop-retract-question], .ContentItem-actions.Sticky [data-zop-retract-question]').forEach(function(button) {button.click();});})
  237. // 被 getCollapsedAnswerObserver 函数收起过的,悬浮 [收起] 按钮(悬浮底部的横栏)
  238. document.querySelectorAll('.RichContent:not([script-collapsed]) .ContentItem-actions.Sticky [data-zop-retract-question]').forEach(function(button) {
  239. let el = button.parentElement;
  240. while (!el.classList.contains('RichContent')) {el = el.parentElement;}
  241. if (el) el.setAttribute('script-collapsed', '');
  242. button.click();
  243. })
  244.  
  245. const observer = getCollapsedAnswerObserver();
  246. observer.start();
  247.  
  248. if (!menu_value('menu_defaultCollapsedAnswer') && !observer._disconnectListener) {
  249. window.addEventListener('urlchange', function() {
  250. observer.end();
  251. window._collapsedAnswerObserver = null;
  252. })
  253. observer._disconnectListener = true;
  254. }
  255. }
  256. }
  257. }
  258. }
  259.  
  260.  
  261. // 收起当前回答、评论(监听点击事件,点击网页两侧空白处)
  262. function collapsedNowAnswer(selectors) {
  263. backToTop(selectors) // 快捷回到顶部
  264. if (!menu_value('menu_collapsedNowAnswer')) return
  265. document.querySelector(selectors).onclick = function(event){
  266. if (event.target == this) {
  267. // 下面这段主要是 [收起回答],顺便 [收起评论](如果展开了的话)
  268. let rightButton = document.querySelector('.ContentItem-actions.Sticky.RichContent-actions.is-fixed.is-bottom')
  269. if (rightButton) { // 悬浮在底部的 [收起回答](此时正在浏览回答内容 [中间区域])
  270. // 固定的 [收起评论](先看看是否展开评论)
  271. let commentCollapseButton = rightButton.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type')
  272. //console.log('111')
  273. if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) commentCollapseButton.click();
  274. // 再去收起回答
  275. rightButton = rightButton.querySelector('.ContentItem-rightButton[data-zop-retract-question]')
  276. //console.log('222')
  277. if (rightButton) rightButton.click();
  278.  
  279. } else { // 固定在回答底部的 [收起回答](此时正在浏览回答内容 [尾部区域])
  280.  
  281. // 悬浮的 [收起评论](此时正在浏览评论内容 [中间区域])
  282. //if (getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container'))) {getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container')).click();console.log('asfaf')}
  283.  
  284. let answerCollapseButton_ = false;
  285. for (let el of document.querySelectorAll('.ContentItem-rightButton[data-zop-retract-question]')) { // 遍历所有回答底部的 [收起] 按钮
  286. if (isElementInViewport(el)) { // 判断该 [收起] 按钮是否在可视区域内
  287. // 固定的 [收起评论](先看看是否展开评论,即存在 [收起评论] 按钮)
  288. let commentCollapseButton = el.parentNode.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type')
  289. // 如果展开了评论,就收起评论
  290. //console.log('333')
  291. //if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) commentCollapseButton.click();
  292. if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) {
  293. commentCollapseButton.click();
  294. if (!isElementInViewport(commentCollapseButton)) scrollTo(0,el.offsetTop+50)
  295. }
  296. //console.log('444')
  297. el.click() // 再去收起回答
  298. answerCollapseButton_ = true; // 如果找到并点击收起了,就没必要执行下面的代码了(可视区域中没有 [收起回答] 时)
  299. break
  300. }
  301. }
  302. // 针对完全看不到 [收起回答] 按钮时(如 [头部区域],以及部分明明很长却不显示悬浮横条的回答)
  303. if (!answerCollapseButton_) {
  304. for (let el of document.querySelectorAll('.List-item, .Card.AnswerCard, .Card.TopstoryItem')) { // 遍历所有回答主体元素
  305. if (isElementInViewport_(el)) { // 判断该回答是否在可视区域内
  306. // 固定的 [收起评论](先看看是否展开评论,即存在 [收起评论] 按钮)
  307. let commentCollapseButton = el.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type')
  308. // 如果展开了评论,就收起评论
  309. //console.log('555',commentCollapseButton)
  310. if (commentCollapseButton && commentCollapseButton.textContent.indexOf('收起评论') > -1) {
  311. commentCollapseButton.click();
  312. if (!isElementInViewport(commentCollapseButton)) scrollTo(0,el.offsetTop+50)
  313. }
  314. let answerCollapseButton__ = el.querySelector('.ContentItem-rightButton[data-zop-retract-question]');
  315. //console.log('666')
  316. if (answerCollapseButton__) answerCollapseButton__.click() // 再去收起回答
  317. break
  318. }
  319. }
  320. }
  321. }
  322.  
  323. // 下面这段只针对 [收起评论](如果展开了的话)
  324. let commentCollapseButton_ = false, commentCollapseButton__ = false;
  325. // 悬浮的 [收起评论](此时正在浏览评论内容 [中间区域])
  326. let commentCollapseButton = getXpath('//button[text()="收起评论"]',document.querySelector('.Comments-container'))
  327. if (commentCollapseButton) {
  328. //console.log('777', commentCollapseButton)
  329. commentCollapseButton.click();
  330. } else { // 固定的 [收起评论](此时正在浏览评论内容 [头部区域])
  331. let commentCollapseButton_1 = document.querySelectorAll('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type, .ContentItem-action > button.Button.Button--plain.Button--withIcon.Button--withLabel:first-of-type')
  332. if (commentCollapseButton_1.length > 0) {
  333. for (let el of commentCollapseButton_1) {
  334. if (el.textContent.indexOf('收起评论') > -1) {
  335. if (isElementInViewport(el)) {
  336. //console.log('888')
  337. el.click()
  338. commentCollapseButton_ = true // 如果找到并点击了,就没必要执行下面的代码了(可视区域中没有 [收起评论] 时)
  339. break
  340. }
  341. }
  342. }
  343. }
  344. if (commentCollapseButton_ == false) { // 可视区域中没有 [收起评论] 时(此时正在浏览评论内容 [头部区域] + [尾部区域](不上不下的,既看不到固定的 [收起评论] 又看不到悬浮的 [收起评论])),需要判断可视区域中是否存在评论元素
  345. let commentCollapseButton_1 = document.querySelectorAll('.Comments-container')
  346. if (commentCollapseButton_1.length > 0) {
  347. for (let el of commentCollapseButton_1) {
  348. if (isElementInViewport(el)) {
  349. let parentElement = findParentElement(el, 'List-item') || findParentElement(el, 'Card '),
  350. commentCollapseButton = parentElement.querySelector('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type')
  351. if (commentCollapseButton.textContent.indexOf('收起评论') > -1) {
  352. //console.log('999')
  353. commentCollapseButton.click()
  354. if (!isElementInViewport(commentCollapseButton)) {console.log(parentElement,parentElement.offsetTop,parentElement.offsetHeight);scrollTo(0,parentElement.offsetTop+parentElement.offsetHeight-50)}
  355. commentCollapseButton__ = true // 如果找到并点击了,就没必要执行下面的代码了(可视区域中没有 评论元素 时)
  356. break
  357. }
  358. }
  359. }
  360. }
  361. if (commentCollapseButton__ == false) { // 如果上面的都没找到,那么就尝试寻找评论末尾的 [评论回复框]
  362. let commentCollapseButton_2 = document.querySelectorAll('.Editable-content')
  363. if (commentCollapseButton_2.length > 0) {
  364. for (let el of commentCollapseButton_2) {
  365. if (isElementInViewport(el)) {
  366. let parentElement = findParentElement(el, 'List-item') || findParentElement(el, 'Card '),
  367. commentCollapseButton = parentElement.querySelector('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type')
  368. //console.log(commentCollapseButton)
  369. if (commentCollapseButton.textContent.indexOf('收起评论') > -1) {
  370. //console.log('101010')
  371. commentCollapseButton.click()
  372. if (!isElementInViewport(commentCollapseButton)) {console.log(parentElement,parentElement.offsetTop,parentElement.offsetHeight);scrollTo(0,parentElement.offsetTop+parentElement.offsetHeight-50)}
  373. break
  374. }
  375. }
  376. }
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. }
  384.  
  385.  
  386. // 回到顶部(监听点击事件,鼠标右键点击网页两侧空白处)
  387. function backToTop(selectors) {
  388. if (!menu_value('menu_backToTop')) return
  389. document.querySelector(selectors).oncontextmenu = function(event){
  390. if (event.target == this) {
  391. event.preventDefault();
  392. window.scrollTo(0,0)
  393. }
  394. }
  395. }
  396.  
  397.  
  398. //获取元素是否在可视区域(完全可见)
  399. function isElementInViewport(el) {
  400. let rect = el.getBoundingClientRect();
  401. return (
  402. rect.top >= 0 &&
  403. rect.left >= 0 &&
  404. rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
  405. rect.right <= (window.innerWidth || document.documentElement.clientWidth)
  406. );
  407. }
  408. //获取元素是否在可视区域(部分可见)
  409. function isElementInViewport_(el) {
  410. let rect = el.getBoundingClientRect();
  411. return (
  412. rect.top < (window.innerHeight || document.documentElement.clientHeight) &&
  413. rect.bottom > 0
  414. );
  415. }
  416.  
  417.  
  418. // 自定义屏蔽用户
  419. function customBlockUsers() {
  420. let nowBlockUsers = '';
  421. menu_value('menu_customBlockUsers').forEach(function(item){nowBlockUsers += '|' + item})
  422. //console.log(nowBlockUsers.replace('|',''))
  423. let newBlockUsers = prompt('编辑 [自定义屏蔽用户]\n(不同用户名之间使用 "|" 分隔,例如:用户A|用户B|用户C )', nowBlockUsers.replace('|',''));
  424. if (newBlockUsers === '') {
  425. GM_setValue('menu_customBlockUsers', []);
  426. registerMenuCommand(); // 重新注册脚本菜单
  427. } else if (newBlockUsers != null) {
  428. GM_setValue('menu_customBlockUsers', newBlockUsers.split('|'));
  429. registerMenuCommand(); // 重新注册脚本菜单
  430. }
  431. };
  432.  
  433.  
  434. // 屏蔽指定用户
  435. function blockUsers(type) {
  436. if (!menu_value('menu_blockUsers')) return
  437. if (!menu_value('menu_customBlockUsers') || menu_value('menu_customBlockUsers').length < 1) return
  438. switch(type) {
  439. case 'index':
  440. blockUsers_('.Card.TopstoryItem.TopstoryItem-isRecommend', 'Card TopstoryItem TopstoryItem-isRecommend');
  441. break;
  442. case 'question':
  443. blockUsers_question();
  444. break;
  445. case 'search':
  446. blockUsers_search();
  447. break;
  448. case 'topic':
  449. blockUsers_('.List-item.TopicFeedItem', 'List-item TopicFeedItem');
  450. break;
  451. case 'people':
  452. blockUsers_button_people(); // 添加屏蔽用户按钮(用户主页)
  453. break;
  454. }
  455. blockUsers_comment(); // 评论区
  456. blockUsers_button(); // 加入黑名单按钮
  457.  
  458. function blockUsers_(className1, className2) {
  459. // 前几条因为是直接加载的,而不是动态插入网页的,所以需要单独判断
  460. function blockKeywords_now() {
  461. document.querySelectorAll(className1).forEach(function(item1){
  462. let item = item1.querySelector('.ContentItem.AnswerItem, .ContentItem.ArticleItem'); // 用户名所在元素
  463. if (item) {
  464. for (const keyword of menu_value('menu_customBlockUsers')) { // 遍历用户名黑名单
  465. if (keyword != '' && item.dataset.zop.indexOf('authorName":"' + keyword + '",') > -1) { // 找到就删除该信息流
  466. console.log('已屏蔽:' + item.dataset.zop);
  467. item1.hidden = true;
  468. break;
  469. }
  470. }
  471. }
  472. })
  473. }
  474.  
  475. blockKeywords_now();
  476. window.addEventListener('urlchange', function(){
  477. setTimeout(blockKeywords_now, 1000); // 网页 URL 变化后再次执行
  478. })
  479.  
  480. // 这个是监听网页插入事件,用来判断后续网页动态插入的元素
  481. const callback = (mutationsList, observer) => {
  482. for (const mutation of mutationsList) {
  483. for (const target of mutation.addedNodes) {
  484. if (target.nodeType != 1) return
  485. if (target.className === className2) {
  486. let item = target.querySelector('.ContentItem.AnswerItem, .ContentItem.ArticleItem'); // 用户名所在元素
  487. if (item) {
  488. for (const keyword of menu_value('menu_customBlockUsers')) { // 遍历用户名黑名单
  489. if (keyword != '' && item.dataset.zop.indexOf('authorName":"' + keyword + '",') > -1) { // 找到就删除该信息流
  490. console.log('已屏蔽:' + item.dataset.zop);
  491. target.hidden = true;
  492. break;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499. };
  500. const observer = new MutationObserver(callback);
  501. observer.observe(document, { childList: true, subtree: true });
  502. }
  503.  
  504.  
  505. function blockUsers_question() {
  506. const blockUsers_question_ = (mutationsList, observer) => {
  507. for (const mutation of mutationsList) {
  508. for (const target of mutation.addedNodes) {
  509. if (target.nodeType != 1) return
  510. if (target.className === 'List-item' || target.className === 'Card AnswerCard') {
  511. let item1 = target.querySelector('.ContentItem.AnswerItem');
  512. if (item1) {
  513. menu_value('menu_customBlockUsers').forEach(function(item2){ // 遍历用户黑名单
  514. if (item1.dataset.zop.indexOf('authorName":"' + item2 + '",') > -1) { // 找到就删除该回答
  515. console.log('已屏蔽:' + item1.dataset.zop)
  516. target.hidden = true;
  517. }
  518. })
  519. }
  520. }
  521. }
  522. }
  523. };
  524.  
  525. const blockUsers_question_answer_ = (mutationsList, observer) => {
  526. for (const mutation of mutationsList) {
  527. for (const target of mutation.addedNodes) {
  528. if (target.nodeType != 1) return
  529. target.querySelectorAll('.List-item, .Card.AnswerCard').forEach(function(item){
  530. let item1 = item.querySelector('.ContentItem.AnswerItem');
  531. if (item1) {
  532. menu_value('menu_customBlockUsers').forEach(function(item2){ // 遍历用户黑名单
  533. if (item1.dataset.zop.indexOf('authorName":"' + item2 + '",') > -1) { // 找到就删除该回答
  534. console.log('已屏蔽:' + item1.dataset.zop)
  535. item.hidden = true;
  536. }
  537. })
  538. }
  539. })
  540. }
  541. }
  542. };
  543.  
  544. if (location.pathname.indexOf('/answer/') > -1) { // 回答页(就是只有三个回答的页面)
  545. const observer = new MutationObserver(blockUsers_question_answer_);
  546. observer.observe(document, { childList: true, subtree: true });
  547. } else { // 问题页(可以显示所有回答的页面)
  548. const observer = new MutationObserver(blockUsers_question_);
  549. observer.observe(document, { childList: true, subtree: true });
  550. }
  551.  
  552. // 针对的是打开网页后直接加载的前面几个回答(上面哪些是针对动态加载的回答)
  553. document.querySelectorAll('.List-item, .Card.AnswerCard').forEach(function(item){
  554. let item1 = item.querySelector('.ContentItem.AnswerItem');
  555. if (item1) {
  556. menu_value('menu_customBlockUsers').forEach(function(item2){ // 遍历用户黑名单
  557. if (item1.dataset.zop.indexOf('authorName":"' + item2 + '",') > -1) { // 找到就删除该回答
  558. console.log('已屏蔽:' + item1.dataset.zop)
  559. item.hidden = true;
  560. }
  561. })
  562. }
  563. })
  564. }
  565.  
  566. function blockUsers_search() {
  567. function blockUsers_now() {
  568. if (location.search.indexOf('type=content') === -1) return // 目前只支持搜索页的 [综合]
  569. document.querySelectorAll('.Card.SearchResult-Card[data-za-detail-view-path-module="AnswerItem"], .Card.SearchResult-Card[data-za-detail-view-path-module="PostItem"]').forEach(function(item1){
  570. let item = item1.querySelector('.RichText.ztext.CopyrightRichText-richText b'); // 用户名所在元素
  571. if (item) {
  572. for (const keyword of menu_value('menu_customBlockUsers')) { // 遍历用户名黑名单
  573. if (keyword != '' && item.textContent === keyword) { // 找到就删除该信息流
  574. console.log('已屏蔽:' + item.textContent);
  575. item1.hidden = true;
  576. break;
  577. }
  578. }
  579. }
  580. })
  581. }
  582.  
  583. setTimeout(blockUsers_now, 2000);
  584. window.addEventListener('urlchange', function(){
  585. setTimeout(blockUsers_now, 1000); // 网页 URL 变化后再次执行
  586. })
  587.  
  588. const callback = (mutationsList, observer) => {
  589. if (location.search.indexOf('type=content') === -1) return // 目前只支持搜索页的 [综合]
  590. for (const mutation of mutationsList) {
  591. for (const target of mutation.addedNodes) {
  592. if (target.nodeType != 1) return
  593. let item = target.querySelector('.Card.SearchResult-Card[data-za-detail-view-path-module="AnswerItem"] .RichText.ztext.CopyrightRichText-richText b, .Card.SearchResult-Card[data-za-detail-view-path-module="PostItem"] .RichText.ztext.CopyrightRichText-richText b');
  594. if (item) {
  595. for (const keyword of menu_value('menu_customBlockUsers')) { // 遍历用户名黑名单
  596. if (keyword != '' && item.textContent === keyword) { // 找到就删除该信息流
  597. console.log('已屏蔽:' + item.textContent);
  598. target.hidden = true;
  599. break;
  600. }
  601. }
  602. }
  603. }
  604. }
  605. };
  606. const observer = new MutationObserver(callback);
  607. observer.observe(document, { childList: true, subtree: true });
  608. }
  609.  
  610. function blockUsers_comment() {
  611. const callback = (mutationsList, observer) => {
  612. for (const mutation of mutationsList) {
  613. for (const target of mutation.addedNodes) {
  614. if (target.nodeType != 1) return
  615. let item = target.querySelector('img.Avatar[width="24"]')
  616. if (item) {
  617. //console.log(item)
  618. menu_value('menu_customBlockUsers').forEach(function(item1){ // 遍历用户黑名单
  619. //console.log(item.alt,item1)
  620. if (item.alt === item1) { // 找到就删除该搜索结果
  621. item.parentElement.parentElement.style.display = "none";
  622. }
  623. })
  624.  
  625. // 添加屏蔽用户按钮(点赞、回复等按钮后面)
  626. /*if (item) {
  627. let footer = findParentElement(item, 'CommentItemV2-meta', true).parentElement.querySelector('.CommentItemV2-metaSibling > .CommentItemV2-footer'),
  628. userid = item.parentElement;
  629. if (userid && footer && !footer.lastElementChild.dataset.name) {
  630. userid = userid.href.split('/')[4];
  631. footer.insertAdjacentHTML('beforeend',`<button type="button" data-name="${item.alt}" data-userid="${userid}" class="Button CommentItemV2-hoverBtn Button--plain"><span style="display: inline-flex; align-items: center;">&#8203;<svg class="Zi Zi--Like" fill="currentColor" viewBox="0 0 24 24" width="16" height="16" style="transform: rotate(180deg); margin-right: 5px;"><path d="M18.376 5.624c-3.498-3.499-9.254-3.499-12.752 0-3.499 3.498-3.499 9.254 0 12.752 3.498 3.499 9.254 3.499 12.752 0 3.499-3.498 3.499-9.14 0-12.752zm-1.693 1.693c2.37 2.37 2.596 6.094.678 8.69l-9.367-9.48c2.708-1.919 6.32-1.58 8.69.79zm-9.48 9.48c-2.37-2.37-2.595-6.095-.676-8.69l9.48 9.48c-2.822 1.918-6.433 1.58-8.803-.79z" fill-rule="evenodd"></path></svg></span>屏蔽用户</button>`);
  632. footer.lastElementChild.onclick = function(){blockUsers_button_add(this.dataset.name, this.dataset.userid, false)}
  633. }
  634. }*/
  635. }
  636. }
  637. }
  638. };
  639. const observer = new MutationObserver(callback);
  640. observer.observe(document, { childList: true, subtree: true });
  641. }
  642.  
  643.  
  644. // 添加屏蔽用户按钮(用户信息悬浮框中)
  645. function blockUsers_button() {
  646. const callback = (mutationsList, observer) => {
  647. for (const mutation of mutationsList) {
  648. for (const target of mutation.addedNodes) {
  649. if (target.nodeType != 1) return
  650. //console.log(target, target.className)
  651. if (target.className && (target.className.indexOf('Popover-content Popover-content--top HoverCard-popoverTarget') > -1 || target.className.indexOf('Popover-content Popover-content--bottom HoverCard-popoverTarget') > -1) || target.querySelector('.Popover-content.Popover-content--top.HoverCard-popoverTarget') || target.querySelector('.Popover-content.Popover-content--bottom.HoverCard-popoverTarget')) {
  652. let item = target.querySelector('.MemberButtonGroup.ProfileButtonGroup.HoverCard-buttons'),
  653. item1 = target.querySelector('a.UserLink-link'),
  654. name = item1.textContent,
  655. userid = item1.href.split('/')[4];
  656. if (item && !target.querySelector('button[data-name][data-userid]')) {
  657. item.insertAdjacentHTML('beforeend', `<button type="button" data-name="${name}" data-userid="${userid}" class="Button FollowButton Button--primary Button--red" style="width: 100%;margin: 7px 0 0 0;"><span style="display: inline-flex; align-items: center;">​<svg class="Zi Zi--Plus FollowButton-icon" fill="currentColor" viewBox="0 0 24 24" width="1.2em" height="1.2em"><path d="M18.376 5.624c-3.498-3.499-9.254-3.499-12.752 0-3.499 3.498-3.499 9.254 0 12.752 3.498 3.499 9.254 3.499 12.752 0 3.499-3.498 3.499-9.14 0-12.752zm-1.693 1.693c2.37 2.37 2.596 6.094.678 8.69l-9.367-9.48c2.708-1.919 6.32-1.58 8.69.79zm-9.48 9.48c-2.37-2.37-2.595-6.095-.676-8.69l9.48 9.48c-2.822 1.918-6.433 1.58-8.803-.79z" fill-rule="evenodd"></path></svg></span>屏蔽用户</button>`);
  658. item.lastElementChild.onclick = function(){blockUsers_button_add(this.dataset.name, this.dataset.userid, false)}
  659. }
  660. }
  661. }
  662. }
  663. };
  664. const observer = new MutationObserver(callback);
  665. observer.observe(document, { childList: true, subtree: true });
  666. }
  667.  
  668. // 添加屏蔽用户按钮(用户主页)
  669. function blockUsers_button_people() {
  670. let item = document.querySelector('.MemberButtonGroup.ProfileButtonGroup.ProfileHeader-buttons'), // 获取按钮元素位置
  671. name = document.querySelector('.ProfileHeader-name').firstChild.textContent, // 获取用户名
  672. users = menu_value('menu_customBlockUsers'), // 读取屏蔽列表
  673. userid = location.href.split('/')[4];
  674. for (let num = 0;num<users.length;num++) { // 判断是否已存在
  675. if (users[num] === name) { // 已存在
  676. document.querySelectorAll('.Button.Button--primary.Button--red').forEach(function(item){item.style.display = 'none';}) // 隐藏知乎自带的已屏蔽按钮
  677. item.insertAdjacentHTML('beforeend', `<button type="button" data-name="${name}" data-userid="${userid}" class="Button FollowButton Button--primary Button--red" style="margin: 0 0 0 12px;"><span style="display: inline-flex; align-items: center;">​<svg class="Zi Zi--Plus FollowButton-icon" fill="currentColor" viewBox="0 0 24 24" width="1.2em" height="1.2em"><path d="M18.376 5.624c-3.498-3.499-9.254-3.499-12.752 0-3.499 3.498-3.499 9.254 0 12.752 3.498 3.499 9.254 3.499 12.752 0 3.499-3.498 3.499-9.14 0-12.752zm-1.693 1.693c2.37 2.37 2.596 6.094.678 8.69l-9.367-9.48c2.708-1.919 6.32-1.58 8.69.79zm-9.48 9.48c-2.37-2.37-2.595-6.095-.676-8.69l9.48 9.48c-2.822 1.918-6.433 1.58-8.803-.79z" fill-rule="evenodd"></path></svg></span>取消屏蔽</button>`);
  678. item.lastElementChild.onclick = function(){blockUsers_button_del(this.dataset.name, this.dataset.userid, true)}
  679. return
  680. }
  681. };
  682. if (item) {
  683. item.insertAdjacentHTML('beforeend', `<button type="button" data-name="${name}" data-userid="${userid}" class="Button FollowButton Button--primary Button--red" style="margin: 0 0 0 12px;"><span style="display: inline-flex; align-items: center;">​<svg class="Zi Zi--Plus FollowButton-icon" fill="currentColor" viewBox="0 0 24 24" width="1.2em" height="1.2em"><path d="M18.376 5.624c-3.498-3.499-9.254-3.499-12.752 0-3.499 3.498-3.499 9.254 0 12.752 3.498 3.499 9.254 3.499 12.752 0 3.499-3.498 3.499-9.14 0-12.752zm-1.693 1.693c2.37 2.37 2.596 6.094.678 8.69l-9.367-9.48c2.708-1.919 6.32-1.58 8.69.79zm-9.48 9.48c-2.37-2.37-2.595-6.095-.676-8.69l9.48 9.48c-2.822 1.918-6.433 1.58-8.803-.79z" fill-rule="evenodd"></path></svg></span>屏蔽用户</button>`);
  684. item.lastElementChild.onclick = function(){blockUsers_button_add(this.dataset.name, this.dataset.userid, true)}
  685. }
  686. }
  687.  
  688. // 屏蔽用户按钮绑定事件(添加)
  689. function blockUsers_button_add(name, userid, reload) {
  690. if (!name || !userid) return
  691. let users = menu_value('menu_customBlockUsers'), // 读取屏蔽列表
  692. index = users.indexOf(name);
  693. if (index === -1) {
  694. users.push(name); // 追加用户名
  695. GM_setValue('menu_customBlockUsers', users); // 写入屏蔽列表
  696. // 加入知乎自带的黑名单(和本脚本互补~
  697. GM_xmlhttpRequest({url: `https://www.zhihu.com/api/v4/members/${userid}/actions/block`,method: 'POST',timeout: 2000});
  698. // 是否刷新本页
  699. if (reload) {
  700. setTimeout(function(){location.reload()}, 200); // 刷新网页,延迟 200 毫秒,避免知乎反应慢~
  701. } else {
  702. GM_notification({text: `该用户已被屏蔽~\n刷新网页后生效~`, timeout: 3000});
  703. }
  704. } else {
  705. GM_notification({text: `该用户已经被屏蔽啦,无需重复屏蔽~`, timeout: 3000});
  706. }
  707. }
  708.  
  709.  
  710. // 屏蔽用户按钮绑定事件(删除)
  711. function blockUsers_button_del(name, userid, reload) {
  712. if (!name || !userid) return
  713. let users = menu_value('menu_customBlockUsers'), // 读取屏蔽列表
  714. index = users.indexOf(name);
  715. if (index > -1) {
  716. users.splice(index, 1); // 移除用户名
  717. GM_setValue('menu_customBlockUsers', users); // 写入屏蔽列表
  718. // 移除知乎自带的黑名单
  719. GM_xmlhttpRequest({url: `https://www.zhihu.com/api/v4/members/${userid}/actions/block`,method: 'DELETE',timeout: 2000});
  720. // 是否刷新本页
  721. if (reload) {
  722. setTimeout(function(){location.reload()}, 200); // 刷新网页,延迟 200 毫秒,避免知乎反应慢~
  723. } else {
  724. GM_notification({text: `该用户已取消屏蔽啦~\n刷新网页后生效~`, timeout: 3000});
  725. }
  726. } else {
  727. GM_notification({text: `没有在屏蔽列表中找到该用户...`, timeout: 3000});
  728. }
  729. }
  730. }
  731.  
  732.  
  733. // 自定义屏蔽关键词(标题)
  734. function customBlockKeywords() {
  735. let nowBlockKeywords = '';
  736. menu_value('menu_customBlockKeywords').forEach(function(item){nowBlockKeywords += '|' + item})
  737. let newBlockKeywords = prompt('编辑 [自定义屏蔽关键词]\n(不同关键词之间使用 "|" 分隔,例如:关键词A|关键词B|关键词C \n(关键词不区分大小写,支持表情如:[捂脸]|[飙泪笑]', nowBlockKeywords.replace('|',''));
  738. if (newBlockKeywords === '') {
  739. GM_setValue('menu_customBlockKeywords', []);
  740. registerMenuCommand(); // 重新注册脚本菜单
  741. } else if (newBlockKeywords != null) {
  742. GM_setValue('menu_customBlockKeywords', newBlockKeywords.split('|'));
  743. registerMenuCommand(); // 重新注册脚本菜单
  744. }
  745. };
  746.  
  747.  
  748. // 屏蔽指定关键词
  749. function blockKeywords(type) {
  750. if (!menu_value('menu_blockKeywords')) return
  751. if (!menu_value('menu_customBlockKeywords') || menu_value('menu_customBlockKeywords').length < 1) return
  752. switch(type) {
  753. case 'index':
  754. blockKeywords_('.Card.TopstoryItem.TopstoryItem-isRecommend', 'Card TopstoryItem TopstoryItem-isRecommend');
  755. break;
  756. case 'topic':
  757. blockKeywords_('.List-item.TopicFeedItem', 'List-item TopicFeedItem');
  758. break;
  759. case 'people':
  760. blockKeywords_('.List-item', 'List-item');
  761. break;
  762. case 'collection':
  763. blockKeywords_('.Card.CollectionDetailPageItem', 'Card CollectionDetailPageItem');
  764. break;
  765. case 'search':
  766. blockKeywords_search();
  767. break;
  768. case 'comment':
  769. blockKeywords_comment();
  770. break;
  771. }
  772.  
  773.  
  774. function blockKeywords_(className1, className2) {
  775. // 前几条因为是直接加载的,而不是动态插入网页的,所以需要单独判断
  776. function blockKeywords_now() {
  777. if (location.pathname === '/hot') {
  778. document.querySelectorAll('.HotItem').forEach(function(item1){blockKeywords_1(item1, 'h2.HotItem-title');})
  779. } else {
  780. document.querySelectorAll(className1).forEach(function(item1){blockKeywords_1(item1, 'h2.ContentItem-title meta[itemprop="name"], meta[itemprop="headline"]');})
  781. }
  782. }
  783.  
  784. blockKeywords_now();
  785. window.addEventListener('urlchange', function(){
  786. setTimeout(blockKeywords_now, 1000); // 网页 URL 变化后再次执行
  787. })
  788.  
  789. // 这个是监听网页插入事件,用来判断后续网页动态插入的元素
  790. const callback = (mutationsList, observer) => {
  791. for (const mutation of mutationsList) {
  792. for (const target of mutation.addedNodes) {
  793. if (target.nodeType != 1) return
  794. if (target.className === className2) {blockKeywords_1(target, 'h2.ContentItem-title meta[itemprop="name"], meta[itemprop="headline"]');}
  795. }
  796. }
  797. };
  798. const observer = new MutationObserver(callback);
  799. observer.observe(document, { childList: true, subtree: true });
  800. }
  801.  
  802.  
  803. function blockKeywords_search() {
  804. function blockKeywords_now() {
  805. if (location.search.indexOf('type=content') === -1) return // 目前只支持搜索页的 [综合]
  806. document.querySelectorAll('.HotLanding-contentItem, .Card.SearchResult-Card[data-za-detail-view-path-module="AnswerItem"], .Card.SearchResult-Card[data-za-detail-view-path-module="PostItem"]').forEach(function(item1){blockKeywords_1(item1, 'a[data-za-detail-view-id]');})
  807. }
  808.  
  809. setTimeout(blockKeywords_now, 2000);
  810. window.addEventListener('urlchange', function(){
  811. setTimeout(blockKeywords_now, 1000); // 网页 URL 变化后再次执行
  812. })
  813.  
  814. const callback = (mutationsList, observer) => {
  815. if (location.search.indexOf('type=content') === -1) return // 目前只支持搜索页的 [综合]
  816. for (const mutation of mutationsList) {
  817. for (const target of mutation.addedNodes) {
  818. if (target.nodeType != 1) return
  819. if (target.className === 'Card SearchResult-Card' && (target.dataset.zaDetailViewPathModule === 'AnswerItem' || target.dataset.zaDetailViewPathModule === 'PostItem')) {blockKeywords_1(target, 'a[data-za-detail-view-id]');}
  820. }
  821. }
  822. };
  823. const observer = new MutationObserver(callback);
  824. observer.observe(document, { childList: true, subtree: true });
  825. }
  826.  
  827.  
  828. function blockKeywords_comment() {
  829. function filterComment(comment) {
  830. let content = comment.querySelector('.RichText'); // 寻找评论文字所在元素
  831. let texts = [content.textContent.toLowerCase()]; // 因为要针对评论中的表情,所以需要整个数组并全部转为小写(用来不区分大小写)
  832. for (let i = 0; i < content.children.length; i++) { // 该条针对的是评论中的表情
  833. let emoticonValue = content.children[i].getAttribute('data-zhihu-emoticon'); // 确定是表情就将其添加到稍后遍历的数组中
  834. if (emoticonValue) {
  835. texts.push(emoticonValue)
  836. }
  837. }
  838.  
  839. let keywords = menu_value('menu_customBlockKeywords');
  840. for (const text of texts) {
  841. for (const keyword of keywords) { // 遍历关键词黑名单
  842. if (keyword != '' && text.indexOf(keyword.toLowerCase()) > -1) { // 找到就删除该评论
  843. console.log('已屏蔽评论:' + text);
  844. content.textContent = '[该评论已屏蔽]';
  845. break;
  846. }
  847. }
  848. }
  849. }
  850.  
  851. const callback = (mutationsList, observer) => {
  852. for (const mutation of mutationsList) {
  853. for (const target of mutation.addedNodes) {
  854. if (target.nodeType != 1) return
  855. for (const node of target.querySelectorAll('*')) {
  856. if (node.className === 'CommentItemV2-metaSibling') filterComment(node);
  857. }
  858. }
  859. }
  860. };
  861. const observer = new MutationObserver(callback);
  862. observer.observe(document, { childList: true, subtree: true });
  863. }
  864.  
  865. function blockKeywords_1(item1, css) {
  866. let item = item1.querySelector(css); // 标题所在元素
  867. //console.log(item)
  868. if (item) {
  869. for (const keyword of menu_value('menu_customBlockKeywords')) { // 遍历关键词黑名单
  870. let text = item.content || item.textContent;
  871. if (keyword != '' && text.toLowerCase().indexOf(keyword.toLowerCase()) > -1) { // 找到就删除该信息流
  872. console.log('已屏蔽:' + text);
  873. item1.hidden = true;
  874. item1.style.display = 'none';
  875. break;
  876. }
  877. }
  878. }
  879. }
  880. }
  881.  
  882.  
  883. // 屏蔽指定类别(视频/文章等)
  884. function blockType(type) {
  885. let name;
  886. // 一开始加载的信息流 + 添加标签样式
  887. if (type === 'search') { // 搜索页
  888. if (!menu_value('menu_blockTypeVideo') && !menu_value('menu_blockTypeArticle') && !menu_value('menu_blockTypeTopic') && !menu_value('menu_blockTypeSearch')) return
  889. if (menu_value('menu_blockTypeSearch') && location.pathname === '/search') setTimeout(function(){document.querySelector('.RelevantQuery').parentElement.parentElement.hidden = true;}, 2000)
  890. name = 'h2.ContentItem-title a:not(.zhihu_e_toQuestion), a.KfeCollection-PcCollegeCard-link, h2.SearchTopicHeader-Title a'
  891. addSetInterval_(name);
  892. } else if (type === 'question') { // 问题页
  893. if (!menu_value('menu_blockTypeVideo')) return
  894. document.lastChild.appendChild(document.createElement('style')).textContent = `.VideoAnswerPlayer, .VideoAnswerPlayer video, .VideoAnswerPlayer-video, .VideoAnswerPlayer-iframe {display: none !important;}`;
  895. name = '.VideoAnswerPlayer'
  896. document.querySelectorAll(name).forEach(function(item){blockType_(item);})
  897. } else { // 首页
  898. if (!menu_value('menu_blockTypeVideo') && !menu_value('menu_blockTypeArticle')) return
  899. 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;}`;
  900. name = 'h2.ContentItem-title a:not(.zhihu_e_toQuestion)'
  901. document.querySelectorAll(name).forEach(function(item){blockType_(item);})
  902. }
  903.  
  904. // 后续加载的信息流
  905. const observer = new MutationObserver(mutationsList => {
  906. for (const mutation of mutationsList) {
  907. for (const target of mutation.addedNodes) {
  908. if (target.nodeType != 1) return
  909. blockType_(target.querySelector(name));
  910. }
  911. }
  912. });
  913. observer.observe(document, { childList: true, subtree: true });
  914.  
  915. window.addEventListener('urlchange', function(){
  916. addSetInterval_(name);
  917. // 移除相关搜索
  918. if (menu_value('menu_blockTypeSearch') && location.pathname === '/search' && location.search.indexOf('type=content') > -1) setTimeout(function(){document.querySelector('.RelevantQuery').parentElement.parentElement.hidden = true;}, 1500)
  919. })
  920.  
  921. function blockType_(titleA) {
  922. if (!titleA) return // 判断是否为真
  923. //console.log(titleA.href)
  924. if (location.pathname === '/search') { // 搜索页
  925. if (location.search.indexOf('type=content') === -1) return // 仅限搜索页的 [综合]
  926. if (titleA.href.indexOf('/zvideo/') > -1 || titleA.href.indexOf('video.zhihu.com') > -1) { // 如果是视频
  927. if (menu_value('menu_blockTypeVideo')) findParentElement(titleA, 'Card').remove();
  928. } else if (titleA.href.indexOf('zhuanlan.zhihu.com') > -1) { // 如果是文章
  929. if (menu_value('menu_blockTypeArticle')) findParentElement(titleA, 'Card SearchResult-Card').hidden = true;
  930. } else if (titleA.href.indexOf('/topic/') > -1) { // 如果是话题
  931. if (menu_value('menu_blockTypeTopic')) findParentElement(titleA, 'Card SearchResult-Card').hidden = true;
  932. } else if (titleA.href.indexOf('/market/') > -1) { // 如果是杂志文章等乱七八糟的
  933. if (menu_value('menu_blockTypeSearch')) findParentElement(titleA, 'Card SearchResult-Card').hidden = true;
  934. }
  935. } else if (location.pathname.indexOf('/question/') > -1) { // 问题页
  936. if (menu_value('menu_blockTypeVideo')) findParentElement(titleA, 'List-item').hidden = true;
  937. } else { // 首页
  938. if (titleA.href.indexOf('/zvideo/') > -1 || titleA.href.indexOf('video.zhihu.com') > -1) { // 如果是视频
  939. if (menu_value('menu_blockTypeVideo')) {findParentElement(titleA, 'Card TopstoryItem TopstoryItem-isRecommend').hidden = true;}
  940. } else if (titleA.href.indexOf('/answer/') > -1) { // 如果是问题(视频回答)
  941. if (findParentElement(titleA, 'ContentItem AnswerItem').querySelector('.VideoAnswerPlayer')) {
  942. if (menu_value('menu_blockTypeVideo')) {findParentElement(titleA, 'Card TopstoryItem TopstoryItem-isRecommend').hidden = true; findParentElement(titleA, 'ContentItem AnswerItem').remove();}
  943. }
  944. } else if (titleA.href.indexOf('/education/video-course/') > -1) { // 如果是視頻課程
  945. if (menu_value('menu_blockTypeVideo')) {findParentElement(titleA, 'Card TopstoryItem TopstoryItem-isRecommend').hidden = true;}
  946. } else if (titleA.href.indexOf('zhuanlan.zhihu.com') > -1) { // 如果是文章
  947. if (menu_value('menu_blockTypeArticle')) findParentElement(titleA, 'Card TopstoryItem TopstoryItem-isRecommend').hidden = true;
  948. }
  949. }
  950. }
  951.  
  952. function addSetInterval_(A) {
  953. let timer = setInterval(function(){
  954. let aTag = document.querySelectorAll(A);
  955. if (aTag.length > 0) {
  956. clearInterval(timer);
  957. aTag.forEach(function(item){blockType_(item);})
  958. }
  959. });
  960. }
  961. }
  962.  
  963.  
  964. // 寻找父元素
  965. function findParentElement(item, className, type = false) {
  966. if (item.parentElement) {
  967. //console.log(item.parentElement)
  968. if (type) { // true = 完全一致,false = 包含即可
  969. if (item.parentElement.className && item.parentElement.className === className) {
  970. //console.log(item.parentElement.className)
  971. return item.parentElement;
  972. } else {
  973. let temp = findParentElement(item.parentElement, className, true)
  974. if (temp) return temp
  975. }
  976. } else {
  977. if (item.parentElement.className && item.parentElement.className.indexOf(className) > -1) {
  978. return item.parentElement;
  979. } else {
  980. let temp = findParentElement(item.parentElement, className)
  981. if (temp) return temp
  982. }
  983. }
  984. }
  985. return
  986. }
  987.  
  988.  
  989. // 移除高亮链接
  990. function removeHighlightLink() {
  991. const callback = (mutationsList, observer) => {
  992. for (const mutation of mutationsList) {
  993. for (const target of mutation.addedNodes) {
  994. if (target.nodeType != 1 || target.tagName != 'A') break
  995. if (target.dataset.zaNotTrackLink && target.href.indexOf('https://www.zhihu.com/search?q=') > -1) {
  996. target.parentElement.replaceWith(target.textContent);
  997. }
  998. }
  999. }
  1000. };
  1001. const observer = new MutationObserver(callback);
  1002. observer.observe(document, { childList: true, subtree: true });
  1003.  
  1004. // 针对的是打开网页后直接加载的前面几个回答(上面哪些是针对动态加载的回答)
  1005. document.querySelectorAll('span > a[data-za-not-track-link][href^="https://www.zhihu.com/search?q="]').forEach(e => e.parentElement.replaceWith(e.textContent))
  1006. }
  1007.  
  1008.  
  1009. // 屏蔽盐选内容
  1010. function blockYanXuan() {
  1011. if (!menu_value('menu_blockYanXuan')) return
  1012. const blockYanXuan_question = (mutationsList, observer) => {
  1013. for (const mutation of mutationsList) {
  1014. for (const target of mutation.addedNodes) {
  1015. if (target.nodeType != 1) return
  1016. if (target.className === 'List-item' || target.className === 'Card AnswerCard') {
  1017. if (target.querySelector('.KfeCollection-AnswerTopCard-Container, .KfeCollection-PurchaseBtn')) {
  1018. target.hidden = true;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. };
  1024.  
  1025. const blockYanXuan_question_answer = (mutationsList, observer) => {
  1026. for (const mutation of mutationsList) {
  1027. for (const target of mutation.addedNodes) {
  1028. if (target.nodeType != 1) return
  1029. target.querySelectorAll('.List-item, .Card.AnswerCard').forEach(function(item){
  1030. if (item.querySelector('.KfeCollection-AnswerTopCard-Container, .KfeCollection-PurchaseBtn')) {
  1031. item.hidden = true;
  1032. }
  1033. })
  1034. }
  1035. }
  1036. };
  1037.  
  1038. if (location.pathname.indexOf('/answer/') > -1) { // 回答页(就是只有三个回答的页面)
  1039. const observer = new MutationObserver(blockYanXuan_question_answer);
  1040. observer.observe(document, { childList: true, subtree: true });
  1041. } else { // 问题页(可以显示所有回答的页面)
  1042. const observer = new MutationObserver(blockYanXuan_question);
  1043. observer.observe(document, { childList: true, subtree: true });
  1044. }
  1045.  
  1046. // 针对的是打开网页后直接加载的前面几个回答(上面哪些是针对动态加载的回答)
  1047. document.querySelectorAll('.List-item, .Card.AnswerCard').forEach(function(item){
  1048. if (item.querySelector('.KfeCollection-AnswerTopCard-Container, .KfeCollection-PurchaseBtn')) {
  1049. item.hidden = true;
  1050. }
  1051. })
  1052. }
  1053.  
  1054.  
  1055. // 区分问题文章
  1056. function addTypeTips() {
  1057. if (!menu_value('menu_typeTips')) return
  1058. let style = `font-weight: bold;font-size: 13px;padding: 1px 4px 0;border-radius: 2px;display: inline-block;vertical-align: top;margin: ${(location.pathname === '/search') ? '2' : '4'}px 4px 0 0;`
  1059. document.body.appendChild(document.createElement('style')).textContent = `/* 区分问题文章 */
  1060. .AnswerItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'问题';color: #f68b83;background-color: #f68b8333;${style}}
  1061. .TopstoryQuestionAskItem .ContentItem-title a:not(.zhihu_e_toQuestion)::before {content:'问题';color: #ff5a4e;background-color: #ff5a4e33;${style}}
  1062. .ZVideoItem .ContentItem-title a::before, .ZvideoItem .ContentItem-title a::before {content:'视频';color: #00BCD4;background-color: #00BCD433;${style}}
  1063. .ArticleItem .ContentItem-title a::before {content:'文章';color: #2196F3;background-color: #2196F333;${style}}`;
  1064. }
  1065.  
  1066.  
  1067. // 直达问题按钮
  1068. function addToQuestion() {
  1069. if (!menu_value('menu_toQuestion')) return
  1070.  
  1071. // 一开始加载的信息流 + 添加按钮样式
  1072. if (location.pathname === '/search') {
  1073. document.lastChild.appendChild(document.createElement('style')).textContent = `a.zhihu_e_toQuestion {font-size: 13px !important;font-weight: normal !important;padding: 1px 6px 0 !important;border-radius: 2px !important;display: inline-block !important;vertical-align: top !important;height: 20.67px !important;line-height: 20.67px !important;margin-top: 2px !important;}`;
  1074. addSetInterval_('h2.ContentItem-title a:not(.zhihu_e_tips)');
  1075. } else {
  1076. document.lastChild.appendChild(document.createElement('style')).textContent = `a.zhihu_e_toQuestion {font-size: 13px !important;font-weight: normal !important;padding: 1px 6px 0 !important;border-radius: 2px !important;display: inline-block !important;vertical-align: top !important;margin-top: 4px !important;}`;
  1077. document.querySelectorAll('h2.ContentItem-title a:not(.zhihu_e_tips)').forEach(function(item){addTypeTips_(item);})
  1078. }
  1079.  
  1080. // 后续加载的信息流
  1081. const observer = new MutationObserver(mutationsList => {
  1082. for (const mutation of mutationsList) {
  1083. for (const target of mutation.addedNodes) {
  1084. if (target.nodeType != 1) return
  1085. addTypeTips_(target.querySelector('h2.ContentItem-title a:not(.zhihu_e_tips)'));
  1086. }
  1087. }
  1088. });
  1089. observer.observe(document, { childList: true, subtree: true });
  1090.  
  1091. window.addEventListener('urlchange', function(){
  1092. addSetInterval_('h2.ContentItem-title a:not(.zhihu_e_tips)');
  1093. })
  1094.  
  1095. function addTypeTips_(titleA) {
  1096. if (!titleA) return // 判断是否为真
  1097. if (titleA.parentElement.querySelector('a.zhihu_e_toQuestion')) return // 判断是否已添加
  1098. if (titleA.textContent.indexOf('?') != -1) { // 把问题末尾英文问好 [?] 的替换为中文问好 [?],这样按钮与标题之间的间距就刚刚好~
  1099. titleA.innerHTML = titleA.innerHTML.replace('?', "?")
  1100. }
  1101. if (/answer\/\d+/.test(titleA.href)) { // 如果是指向回答的问题(而非指向纯问题的链接)
  1102. titleA.insertAdjacentHTML('afterend', `<a class="zhihu_e_toQuestion VoteButton" href="${titleA.parentElement.querySelector('meta[itemprop="url"]').content}" target="_blank">直达问题</a>`);
  1103. }
  1104. }
  1105.  
  1106. function addSetInterval_(A) {
  1107. let timer = setInterval(function(){
  1108. let aTag = document.querySelectorAll(A);
  1109. if (aTag.length > 0) {
  1110. clearInterval(timer);
  1111. aTag.forEach(function(item){addTypeTips_(item);})
  1112. }
  1113. });
  1114. }
  1115. }
  1116.  
  1117.  
  1118. // 展开问题描述
  1119. function questionRichTextMore() {
  1120. if (!menu_value('menu_questionRichTextMore')) return
  1121. let button = document.querySelector('button.QuestionRichText-more');
  1122. if (button) button.click()
  1123. }
  1124.  
  1125.  
  1126. // 知乎免登录
  1127. function removeLogin() {
  1128. const removeLoginModal = (mutationsList, observer) => {
  1129. for (const mutation of mutationsList) {
  1130. for (const target of mutation.addedNodes) {
  1131. if (target.nodeType != 1) return
  1132. if (target.querySelector('.signFlowModal')) {
  1133. let button = target.querySelector('.Button.Modal-closeButton.Button--plain');
  1134. if (button) button.click();
  1135. } else if (getXpath('//button[text()="立即登录/注册"]',target)) {
  1136. target.remove();
  1137. }
  1138. }
  1139. }
  1140. };
  1141.  
  1142. // 未登录时才会监听并移除登录弹窗
  1143. if(location.hostname === 'zhuanlan.zhihu.com') { // 如果是文章页
  1144. if (!document.querySelector('.ColumnPageHeader-profile>.AppHeader-menu')) { // 未登录
  1145. const observer = new MutationObserver(removeLoginModal);
  1146. observer.observe(document, { childList: true, subtree: true });
  1147. if (getXpath('//button[text()="登录/注册"]')) getXpath('//button[text()="登录/注册"]').outerHTML = '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录/注册</a>'; // [登录] 按钮跳转至登录页面
  1148. }
  1149. } else { // 不是文章页
  1150. if (!document.querySelector('.AppHeader-profile>.AppHeader-menu')) { // 未登录
  1151. const observer = new MutationObserver(removeLoginModal);
  1152. observer.observe(document, { childList: true, subtree: true });
  1153. document.lastElementChild.appendChild(document.createElement('style')).textContent = '.Question-mainColumnLogin, button.AppHeader-login {display: none !important;}'; // 屏蔽问题页中间的登录提示
  1154. if (getXpath('//button[text()="登录/注册"]')) getXpath('//button[text()="登录/注册"]').outerHTML = '<a class="Button AppHeader-login Button--blue" href="https://www.zhihu.com/signin" target="_blank">登录/注册</a>'; // [登录] 按钮跳转至登录页面
  1155. }
  1156. }
  1157. }
  1158.  
  1159.  
  1160. // 净化标题消息
  1161. function cleanTitles() {
  1162. if (!menu_value('menu_cleanTitles')) return
  1163.  
  1164. // 方案一
  1165. const elTitle = document.head.querySelector('title');
  1166. const original = elTitle.textContent;
  1167. const observer = new MutationObserver(function() {
  1168. if (elTitle.textContent != original) { // 避免重复执行
  1169. elTitle.textContent = original;
  1170. }
  1171. });
  1172. observer.observe(elTitle, { childList: true });
  1173.  
  1174. // 方案二
  1175. // if (Reflect.getOwnPropertyDescriptor(document, 'title')) {
  1176. // const elTitle = document.head.querySelector('title');
  1177. // const original = elTitle.textContent;
  1178. // const observer = new MutationObserver(function() {
  1179. // if (elTitle.textContent != original) { // 避免重复执行
  1180. // elTitle.textContent = original;
  1181. // }
  1182. // });
  1183. // observer.observe(elTitle, { childList: true });
  1184. // } else {
  1185. // const title = document.title;
  1186. // Reflect.defineProperty(document, 'title', {
  1187. // set: () => {},
  1188. // get: () => title,
  1189. // });
  1190. // }
  1191. }
  1192.  
  1193.  
  1194. // 净化搜索热门
  1195. function cleanSearch() {
  1196. if (!menu_value('menu_cleanSearch')) return
  1197.  
  1198. const el = document.querySelector('.SearchBar-input > input');
  1199. const observer = new MutationObserver((mutationsList, observer) => {
  1200. if (mutationsList[0].attributeName === 'placeholder' && mutationsList[0].target.placeholder != '') mutationsList[0].target.placeholder = '';
  1201. });
  1202. el.placeholder = '';
  1203. observer.observe(el, { attributes: true });
  1204. document.documentElement.appendChild(document.createElement('style')).textContent = '.AutoComplete-group > .SearchBar-label:not(.SearchBar-label--history), .AutoComplete-group > [id^="AutoComplete2-topSearch-"], .AutoComplete-group > [id^="AutoComplete3-topSearch-"] {display: none !important;}';
  1205. }
  1206.  
  1207.  
  1208. // 快捷关闭悬浮评论(监听点击事件,点击网页两侧空白处)
  1209. function closeFloatingComments() {
  1210. const closeFloatingCommentsModal = (mutationsList, observer) => {
  1211. for (const mutation of mutationsList) {
  1212. for (const target of mutation.addedNodes) {
  1213. if (target.nodeType != 1) return
  1214. let button = document.querySelector('button[aria-label="关闭"]');
  1215. if (button) {button.parentElement.parentElement.onclick = function(event){if (event.target.parentElement == this) {button.click();}}}
  1216. }
  1217. }
  1218. };
  1219. const observer = new MutationObserver(closeFloatingCommentsModal);
  1220. observer.observe(document, { childList: true, subtree: true });
  1221. }
  1222.  
  1223.  
  1224. // 监听 XMLHttpRequest 事件
  1225. /*function EventXMLHttpRequest() {
  1226. var _send = window.XMLHttpRequest.prototype.send
  1227. function sendReplacement(data) {
  1228. addTypeTips();
  1229. return _send.apply(this, arguments);
  1230. }
  1231. window.XMLHttpRequest.prototype.send = sendReplacement;
  1232. }*/
  1233.  
  1234.  
  1235. // 自定义 urlchange 事件(用来监听 URL 变化)
  1236. function addUrlChangeEvent() {
  1237. history.pushState = ( f => function pushState(){
  1238. var ret = f.apply(this, arguments);
  1239. window.dispatchEvent(new Event('pushstate'));
  1240. window.dispatchEvent(new Event('urlchange'));
  1241. return ret;
  1242. })(history.pushState);
  1243.  
  1244. history.replaceState = ( f => function replaceState(){
  1245. var ret = f.apply(this, arguments);
  1246. window.dispatchEvent(new Event('replacestate'));
  1247. window.dispatchEvent(new Event('urlchange'));
  1248. return ret;
  1249. })(history.replaceState);
  1250.  
  1251. window.addEventListener('popstate',()=>{
  1252. window.dispatchEvent(new Event('urlchange'))
  1253. });
  1254. }
  1255.  
  1256.  
  1257. function getXpath(xpath, contextNode, doc = document) {
  1258. contextNode = contextNode || doc;
  1259. try {
  1260. const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  1261. // 应该总是返回一个元素节点
  1262. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  1263. } catch (err) {
  1264. throw new Error(`无效 Xpath: ${xpath}`);
  1265. }
  1266. }
  1267.  
  1268.  
  1269. // 显示问题作者
  1270. function question_author() {
  1271. if (document.querySelector('.BrandQuestionSymbol, .QuestionAuthor')) return
  1272. let qJson = JSON.parse(document.querySelector('#js-initialData').textContent).initialState.entities.questions[/\d+/.exec(location.pathname)[0]].author,
  1273. html = `<div class="BrandQuestionSymbol"><a class="BrandQuestionSymbol-brandLink" href="/people/${qJson.urlToken}"><img role="presentation" src="${qJson.avatarUrl}" class="BrandQuestionSymbol-logo" alt=""><span class="BrandQuestionSymbol-name">${qJson.name}</span></a><div class="BrandQuestionSymbol-divider" style="margin-left: 5px;margin-right: 10px;"></div></div>`;
  1274. //html = `<div class="QuestionAuthor"><div class="AuthorInfo AuthorInfo--plain" itemprop="author" itemscope="" itemtype="http://schema.org/Person"><div class="AuthorInfo"><span class="UserLink AuthorInfo-avatarWrapper"><div class="Popover"><div id="Popover18-toggle" aria-haspopup="true" aria-expanded="false" aria-owns="Popover18-content"><a class="UserLink-link" data-za-detail-view-element_name="User" target="_blank" href="${qJson.urlToken}"><img class="Avatar AuthorInfo-avatar" width="24" height="24" src="${qJson.avatarUrl}"></a></div></div></span><div class="AuthorInfo-content"><div class="AuthorInfo-head"><span class="UserLink AuthorInfo-name"><div class="Popover"><div id="Popover19-toggle" aria-haspopup="true" aria-expanded="false" aria-owns="Popover19-content"><a class="UserLink-link" data-za-detail-view-element_name="User" target="_blank" href="${qJson.urlToken}">${qJson.name}</a></div></div></span></div></div></div></div></div>`
  1275. document.querySelector('.QuestionHeader-topics').insertAdjacentHTML('beforebegin', html);
  1276. //document.querySelector('.QuestionPage h1.QuestionHeader-title').insertAdjacentHTML('afterend', html);
  1277. }
  1278.  
  1279.  
  1280. // [完整显示时间 + 置顶显示时间] 功能修改自:https://greasyfork.org/scripts/402808(从 JQuery 改为原生 JavaScript,且精简、优化了代码)
  1281. // 完整显示时间 + 置顶显示时间
  1282. function topTime_(css, classs) {
  1283. document.querySelectorAll(css).forEach(function(_this) {
  1284. let t = _this.querySelector('.ContentItem-time'); if (!t) return
  1285. if (!(t.classList.contains('full')) && t.querySelector('span') && t.querySelector('span').textContent != null) {
  1286. // 完整显示时间
  1287. topTime_allTime(t)
  1288. // 发布时间置顶
  1289. topTime_publishTop(t, _this, classs)
  1290. }
  1291. });
  1292. }
  1293.  
  1294.  
  1295. // 完整显示时间 + 置顶显示时间 - 文章
  1296. function topTime_post() {
  1297. let t = document.querySelector('.ContentItem-time:not(.xiu-time)'); if (!t) return
  1298. // 完整显示时间
  1299. if (t.textContent.indexOf('编辑于') > -1 && !(t.classList.contains('xiu-time'))) {
  1300. let tt = t.textContent;
  1301. t.click();
  1302. t.textContent = (t.textContent + ' ,' + tt)
  1303. t.classList.add('xiu-time');
  1304. }
  1305.  
  1306. //发布时间置顶
  1307. if (menu_value('menu_publishTop') && !(document.querySelector('.Post-Header > .ContentItem-time')) && !(document.querySelector('.ContentItem-meta > .ContentItem-time'))) {
  1308. let temp_time = t.cloneNode(true);
  1309. temp_time.style.padding = '0px';
  1310. document.querySelector('.Post-Header').insertAdjacentElement('beforeEnd', temp_time);
  1311. }
  1312. }
  1313.  
  1314.  
  1315. // 完整显示时间
  1316. function topTime_allTime(t) {
  1317. if (t.textContent.indexOf('发布于') > -1 && t.textContent.indexOf('编辑于') == -1) {
  1318. t.querySelector('span').textContent = (t.querySelector('span').dataset.tooltip);
  1319. t.classList.add('full');
  1320. } else if (t.textContent.indexOf('发布于') == -1 && t.textContent.indexOf('编辑于') > -1) {
  1321. t.querySelector('span').textContent = (t.querySelector('span').dataset.tooltip) + ' ,' + (t.querySelector('span').textContent);
  1322. t.classList.add('full');
  1323. }
  1324. }
  1325.  
  1326.  
  1327. // 发布时间置顶
  1328. function topTime_publishTop(t, _this, _class) {
  1329. if (!menu_value('menu_publishTop')) return
  1330. if (!t.parentNode.classList.contains(_class)) {
  1331. let temp_time = t.cloneNode(true);
  1332. temp_time.style.padding = '0px';
  1333. // 对于较短的回答,隐藏回答底部的时间
  1334. if (_this.offsetHeight < 400) t.style.display = 'none';
  1335. _this.querySelector('.' + _class).insertAdjacentElement('beforeEnd', temp_time);
  1336. }
  1337. }
  1338.  
  1339.  
  1340. // 问题创建时间
  1341. function question_time() {
  1342. if (!(document.querySelector('.QuestionPage .QuestionHeader-side .QuestionTime-xiu'))) {
  1343. document.querySelector('.QuestionPage .QuestionHeader-side').insertAdjacentHTML('beforeEnd', '<div class="QuestionTime-xiu" style="color: #9098ac; margin-top: 5px; font-size: 13px; font-style: italic;"><p>创建时间:' + getUTC8(new Date(document.querySelector('.QuestionPage > meta[itemprop=dateCreated]').content)) + '</p><p>最后编辑:' + getUTC8(new Date(document.querySelector('.QuestionPage > meta[itemprop=dateModified]').content)) + '</p></div>');
  1344. }
  1345. }
  1346.  
  1347.  
  1348. // UTC 标准时转 UTC+8 北京时间,修改自:https://greasyfork.org/zh-CN/scripts/402808(精简)
  1349. function getUTC8(t) {
  1350. return (t.getFullYear() + '-' + (((t.getMonth() + 1) < 10) ? ('0' + (t.getMonth() + 1)) : (t.getMonth() + 1)) + '-' + ((t.getDate() < 10) ? ('0' + t.getDate()) : t.getDate()) + '\xa0\xa0' + ((t.getHours() < 10) ? ('0' + t.getHours()) : t.getHours()) + ':' + ((t.getMinutes() < 10) ? ('0' + t.getMinutes()) : t.getMinutes()) + ':' + ((t.getSeconds() < 10) ? ('0' + t.getSeconds()) : t.getSeconds()));
  1351. }
  1352.  
  1353.  
  1354. // 默认站外直链,修改自:https://greasyfork.org/scripts/402808(从 JQuery 改为原生 JavaScript,且精简、优化了代码)
  1355. function directLink () {
  1356. document.querySelectorAll('a.external[href*="link.zhihu.com/?target="], a.LinkCard[href*="link.zhihu.com/?target="]:not(.MCNLinkCard):not(.ZVideoLinkCard):not(.ADLinkCardContainer)').forEach(function (_this) {_this.href = decodeURIComponent(_this.href.substring(_this.href.indexOf('link.zhihu.com/?target=') + 23));});
  1357. }
  1358.  
  1359.  
  1360. // 默认高清原图,修改自:https://greasyfork.org/scripts/402808(从 JQuery 改为原生 JavaScript,且精简、优化了代码)
  1361. function originalPic(){
  1362. document.querySelectorAll('img[data-original]:not(.comment_sticker):not(.Avatar)').forEach(function(one){if (one.src != one.dataset.original) {one.src = one.dataset.original}});
  1363. }
  1364.  
  1365.  
  1366. // 默认折叠邀请,修改自:https://greasyfork.org/scripts/402808(从 JQuery 改为原生 JavaScript,且精简、优化了代码)
  1367. function questionInvitation(){
  1368. let time = setInterval(function(){
  1369. let q = document.querySelector('.QuestionInvitation-content'); if (!q) return
  1370. clearInterval(time);
  1371. q.style.display = 'none';
  1372. document.querySelector('.QuestionInvitation-title').innerHTML = document.querySelector('.QuestionInvitation-title').innerText + '<span style="cursor: pointer; font-size: 14px; color: #919aae;"> 展开/折叠</span>'
  1373. // 点击事件(展开/折叠)
  1374. document.querySelector('.Topbar').onclick = function(){
  1375. let q = document.querySelector('.QuestionInvitation-content')
  1376. if (q.style.display == 'none') {
  1377. q.style.display = ''
  1378. } else {
  1379. q.style.display = 'none'
  1380. }
  1381. }
  1382. });
  1383. }
  1384.  
  1385. // 屏蔽热榜杂项
  1386. function blockHotOther() {
  1387. if (!menu_value('menu_blockTypeLiveHot')) return;
  1388.  
  1389. const isQuestionItem = (hotItem) => {
  1390. const linkItem = hotItem.querySelector('.HotItem-content a');
  1391. if (linkItem === null) return false;
  1392. return /\/question\/\d+/.test(linkItem.href);
  1393. }
  1394.  
  1395. const block = () => {
  1396. removeLiveItems();
  1397. fixItemRank();
  1398. };
  1399.  
  1400. // 移除非问题的内容
  1401. const removeLiveItems = () => {
  1402. const hotItems = document.querySelectorAll('.HotList-list .HotItem');
  1403. for (const item of hotItems) {
  1404. if (!isQuestionItem(item)) item.remove();
  1405. }
  1406. }
  1407.  
  1408. // 修复排行榜序号
  1409. const fixItemRank = () => {
  1410. const hotItems = document.querySelectorAll('.HotList-list .HotItem:not([hidden])');
  1411. hotItems.forEach((item, index) => {
  1412. const rank = item.querySelector('.HotItem-index .HotItem-rank');
  1413. if (rank !== null) rank.innerText = index + 1;
  1414. });
  1415. }
  1416.  
  1417. const blockLive_content = (mutationsList, observer) => {
  1418. for (const mutation of mutationsList) {
  1419. for (const target of mutation.addedNodes) {
  1420. if (target.classList.contains('.HotItem')) {
  1421. block();
  1422. }
  1423. }
  1424. }
  1425. }
  1426.  
  1427. const observer = new MutationObserver(blockLive_content);
  1428. observer.observe(document, { childList: true, subtree: true });
  1429.  
  1430. // 初始移除
  1431. block();
  1432. }
  1433.  
  1434.  
  1435. (function() {
  1436. if (window.onurlchange === undefined) {addUrlChangeEvent();} // Tampermonkey v4.11 版本添加的 onurlchange 事件 grant,可以监控 pjax 等网页的 URL 变化
  1437. window.addEventListener('urlchange', function(){ // 针对的是从单个回答页跳转到完整回答页时
  1438. if (location.pathname.indexOf('question') > -1 && location.pathname.indexOf('waiting') === -1 && location.pathname.indexOf('/answer/') === -1) { // 回答页 //
  1439. setTimeout(function(){
  1440. collapsedNowAnswer('.QuestionPage'); // 收起当前回答 + 快捷返回顶部
  1441. collapsedNowAnswer('.Question-main'); // 收起当前回答 + 快捷返回顶部
  1442. questionRichTextMore(); // 展开问题描述
  1443. blockUsers('question'); // 屏蔽指定用户
  1444. blockYanXuan(); // 屏蔽盐选内容
  1445. }, 300);
  1446. } else if (location.pathname == '/') {
  1447. setTimeout(()=>{
  1448. blockUsers('index'); // 屏蔽指定用户
  1449. blockKeywords('index'); // 屏蔽指定关键词
  1450. blockType(); // 屏蔽指定类别(视频/文章等)
  1451. }, 500);
  1452. } else if (location.pathname == '/hot') {
  1453. setTimeout(()=>{
  1454. //屏蔽指定关键词
  1455. blockKeywords('index');
  1456. // 移除热播杂项
  1457. blockHotOther();
  1458. }, 500);
  1459. }
  1460. })
  1461.  
  1462. removeLogin(); // 移除登录弹窗,Violentmonkey 不能延迟执行这个
  1463. cleanTitles(); // 净化标题消息,不能延迟执行
  1464. // Violentmonkey 比 Tampermonkey 加载更早,会导致一些元素还没加载,因此需要延迟一会儿
  1465. // Tampermonkey 4.18.0 版本可能需要延迟一会执行
  1466. if (GM_info.scriptHandler === 'Violentmonkey' || (GM_info.scriptHandler === 'Tampermonkey' && parseFloat(GM_info.version.slice(0,4)) >= 4.18)) {
  1467. setTimeout(start, 300);
  1468. } else {
  1469. start();
  1470. }
  1471.  
  1472. function start(){
  1473. removeHighlightLink(); // 移除高亮链接
  1474. setInterval(originalPic,100); // 默认高清原图
  1475. setInterval(directLink, 100); // 默认站外直链
  1476. if (location.hostname != 'zhuanlan.zhihu.com') {
  1477. if (location.pathname.indexOf('/column/') === -1) cleanSearch(); //净化搜索热门
  1478. collapsedAnswer(); // 一键收起回答
  1479. }
  1480. closeFloatingComments(); // 快捷关闭悬浮评论(监听点击事件,点击网页两侧空白处)
  1481. blockKeywords('comment'); // 屏蔽指定关键词(评论)
  1482.  
  1483.  
  1484. if (location.pathname.indexOf('question') > -1 && location.href.indexOf('/log') == -1) { // 回答页 //
  1485. if (location.pathname.indexOf('waiting') == -1) {
  1486. collapsedNowAnswer('.QuestionPage'); // 收起当前回答 + 快捷返回顶部
  1487. collapsedNowAnswer('.Question-main'); // 收起当前回答 + 快捷返回顶部
  1488. questionRichTextMore(); // 展开问题描述
  1489. blockUsers('question'); // 屏蔽指定用户
  1490. blockYanXuan(); // 屏蔽盐选内容
  1491. blockType('question'); // 屏蔽指定类别(视频/文章等)
  1492. defaultCollapsedAnswer(); // 默认收起回答
  1493. }
  1494. setInterval(function(){topTime_('.ContentItem.AnswerItem', 'ContentItem-meta')}, 300); // 置顶显示时间
  1495. setTimeout(function(){question_time(); question_author()}, 100); //问题创建时间 + 显示问题作者
  1496. questionInvitation(); // 默认折叠邀请
  1497.  
  1498. } else if (location.pathname === '/search') { // 搜索结果页 //
  1499. collapsedNowAnswer('main div'); // 收起当前回答 + 快捷返回顶部
  1500. collapsedNowAnswer('.Search-container'); // 收起当前回答 + 快捷返回顶部
  1501. setInterval(function(){topTime_('.ContentItem.AnswerItem, .ContentItem.ArticleItem', 'SearchItem-meta')}, 300); // 置顶显示时间
  1502. addTypeTips(); // 区分问题文章
  1503. addToQuestion(); // 直达问题按钮
  1504. blockUsers('search'); // 屏蔽指定用户
  1505. blockKeywords('search'); // 屏蔽指定关键词
  1506. blockType('search'); // 屏蔽指定类别(视频/文章等)
  1507.  
  1508.  
  1509. } else if (location.pathname.indexOf('/topic/') > -1) { // 话题页 //
  1510. if (location.pathname.indexOf('/hot') > -1 || location.href.indexOf('/top-answers') > -1) { // 仅限 [讨论] [精华]
  1511. collapsedNowAnswer('main.App-main'); // 收起当前回答 + 快捷返回顶部
  1512. setInterval(function(){topTime_('.ContentItem.AnswerItem, .ContentItem.ArticleItem', 'ContentItem-meta')}, 300); // 置顶显示时间
  1513. addTypeTips(); // 区分问题文章
  1514. addToQuestion(); // 直达问题按钮
  1515. blockUsers('topic'); // 屏蔽指定用户
  1516. blockKeywords('topic'); // 屏蔽指定关键词
  1517. }
  1518.  
  1519. } else if (location.hostname === 'zhuanlan.zhihu.com'){ // 文章 //
  1520. backToTop('article.Post-Main.Post-NormalMain'); // 快捷返回顶部
  1521. backToTop('div.Post-Sub.Post-NormalSub'); // 快捷返回顶部
  1522. setTimeout(topTime_post, 300); // 置顶显示时间
  1523. blockUsers(); // 屏蔽指定用户
  1524.  
  1525.  
  1526. } else if (location.pathname.indexOf('/column/') > -1) { // 专栏 //
  1527. setTimeout(function(){
  1528. collapsedAnswer(); // 一键收起回答
  1529. collapsedNowAnswer('main div'); // 收起当前回答 + 快捷返回顶部
  1530. setInterval(function(){topTime_('.ContentItem.AnswerItem, .ContentItem.ArticleItem', 'ContentItem-meta')}, 300); // 置顶显示时间
  1531. blockUsers(); // 屏蔽指定用户
  1532. }, 300);
  1533.  
  1534.  
  1535. } else if (location.pathname.indexOf('/people/') > -1 || location.href.indexOf('org') > -1) { // 用户主页 //
  1536. if (location.pathname.split('/').length === 3) addTypeTips();addToQuestion(); // 区分问题文章、直达问题按钮
  1537. collapsedNowAnswer('main div'); // 收起当前回答 + 快捷返回顶部
  1538. collapsedNowAnswer('.Profile-main'); // 收起当前回答 + 快捷返回顶部
  1539. setInterval(function(){topTime_('.ContentItem.AnswerItem, .ContentItem.ArticleItem', 'ContentItem-meta')}, 300); // 置顶显示时间
  1540. blockUsers('people'); // 屏蔽指定用户
  1541. blockKeywords('people'); // 屏蔽指定关键词
  1542.  
  1543.  
  1544. } else if (location.pathname.indexOf('/collection/') > -1) { // 收藏夹 //
  1545. addTypeTips(); // 区分问题文章
  1546. addToQuestion(); // 直达问题按钮
  1547. collapsedNowAnswer('main'); // 收起当前回答 + 快捷返回顶部
  1548. collapsedNowAnswer('.CollectionsDetailPage'); // 收起当前回答 + 快捷返回顶部
  1549. setInterval(function(){topTime_('.ContentItem.AnswerItem, .ContentItem.ArticleItem', 'ContentItem-meta')}, 300); // 置顶显示时间
  1550. blockKeywords('collection'); // 屏蔽指定关键词
  1551.  
  1552.  
  1553. } else { // 首页 //
  1554. // 解决屏蔽类别后,因为首页信息流太少而没有滚动条导致无法加载更多内容的问题
  1555. document.lastElementChild.appendChild(document.createElement('style')).textContent = '.Topstory-container {min-height: 1500px;}';
  1556. 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;}`;
  1557.  
  1558. collapsedNowAnswer('main div'); // 收起当前回答 + 快捷返回顶部
  1559. collapsedNowAnswer('.Topstory-container'); // 收起当前回答 + 快捷返回顶部
  1560. setInterval(function(){topTime_('.TopstoryItem', 'ContentItem-meta')}, 300); // 置顶显示时间
  1561. addTypeTips(); // 区分问题文章
  1562. addToQuestion(); // 直达问题按钮
  1563. if (location.pathname == '/') {
  1564. blockUsers('index'); // 屏蔽指定用户
  1565. blockKeywords('index'); // 屏蔽指定关键词
  1566. blockType(); // 屏蔽指定类别(视频/文章等)
  1567. } else if (location.pathname == '/hot') {
  1568. blockKeywords('index'); // 屏蔽指定关键词
  1569. blockHotOther(); // 屏蔽热榜杂项
  1570. } else {
  1571. blockUsers();
  1572. }
  1573. }
  1574. }
  1575. })();