|
3 | 3 | // @name:zh-CN 知乎增强 |
4 | 4 | // @name:zh-TW 知乎增強 |
5 | 5 | // @name:en Zhihu enhancement |
6 | | -// @version 2.2.7 |
| 6 | +// @version 2.2.8 |
7 | 7 | // @author X.I.U |
8 | 8 | // @description 移除登录弹窗、屏蔽首页视频、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、屏蔽用户、屏蔽关键词、移除高亮链接、屏蔽盐选内容/热榜杂项、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认高清原图、默认站外直链 |
9 | 9 | // @description:zh-TW 移除登錄彈窗、屏蔽首頁視頻、默認收起回答、快捷收起回答/評論、快捷回到頂部、屏蔽用戶、屏蔽關鍵詞、移除高亮鏈接、屏蔽鹽選內容、淨化搜索熱門、淨化標題消息、置頂顯示時間、完整問題時間、區分問題文章、默認高清原圖、默認站外直鏈... |
|
32 | 32 | 'use strict'; |
33 | 33 | var menu_ALL = [ |
34 | 34 | ['menu_defaultCollapsedAnswer', '默认收起回答', '默认收起回答', true], |
35 | | - ['menu_collapsedAnswer', '一键收起回答', '一键收起回答', true], |
| 35 | + ['menu_collapsedAnswer', '一键收起回答/评论', '一键收起回答/评论', true], |
36 | 36 | ['menu_collapsedNowAnswer', '快捷收起回答/评论 (点击两侧空白处)', '快捷收起回答/评论', true], |
37 | 37 | ['menu_backToTop', '快捷回到顶部 (右键两侧空白处)', '快捷回到顶部', true], |
38 | 38 | ['menu_blockUsers', '屏蔽指定用户', '屏蔽指定用户', true], |
@@ -209,39 +209,42 @@ function defaultCollapsedAnswer() { |
209 | 209 | } |
210 | 210 |
|
211 | 211 |
|
212 | | -// 一键收起回答(全部) |
| 212 | +// 一键收起回答+评论(全部) |
213 | 213 | function collapsedAnswer() { |
214 | 214 | if (!menu_value('menu_collapsedAnswer')) return |
215 | 215 | //console.log('1111', document.querySelector('.CornerAnimayedFlex')) |
216 | 216 | if (document.querySelector('.CornerAnimayedFlex') && !document.getElementById('collapsed-button')) { |
217 | | - //console.log('2222') |
| 217 | + // 向网页中插入收起全部回答按钮+样式+绑定点击事件 |
218 | 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>'); |
| 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 | 220 | document.getElementById('collapsed-button').onclick = function () { |
221 | | - if (location.pathname === '/' || location.pathname === '/hot' || location.pathname === '/follow') { |
222 | | - document.querySelectorAll('.ContentItem-rightButton').forEach(function (el) { |
223 | | - if (el.hasAttribute('data-zop-retract-question')) { |
224 | | - el.click() |
225 | | - } |
226 | | - }); |
| 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();};}); |
227 | 234 | } else { |
228 | | - document.querySelectorAll('[script-collapsed]').forEach(function(scriptCollapsed) { |
229 | | - scriptCollapsed.querySelectorAll('.ContentItem-actions [data-zop-retract-question], .ContentItem-actions.Sticky [data-zop-retract-question]').forEach(function(button) { |
230 | | - button.click(); |
231 | | - }) |
232 | | - }) |
| 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 函数收起过的,悬浮 [收起] 按钮(悬浮底部的横栏) |
233 | 238 | document.querySelectorAll('.RichContent:not([script-collapsed]) .ContentItem-actions.Sticky [data-zop-retract-question]').forEach(function(button) { |
234 | 239 | let el = button.parentElement; |
235 | | - while (!el.classList.contains('RichContent')) { |
236 | | - el = el.parentElement; |
237 | | - } |
238 | | - if (el) { |
239 | | - el.setAttribute('script-collapsed', ''); |
240 | | - } |
| 240 | + while (!el.classList.contains('RichContent')) {el = el.parentElement;} |
| 241 | + if (el) el.setAttribute('script-collapsed', ''); |
241 | 242 | button.click(); |
242 | 243 | }) |
| 244 | + |
243 | 245 | const observer = getCollapsedAnswerObserver(); |
244 | 246 | observer.start(); |
| 247 | + |
245 | 248 | if (!menu_value('menu_defaultCollapsedAnswer') && !observer._disconnectListener) { |
246 | 249 | window.addEventListener('urlchange', function() { |
247 | 250 | observer.end(); |
|
0 commit comments