()
| 244 | |
| 245 | // 一键收起回答+评论(全部) |
| 246 | function collapsedAnswer() { |
| 247 | if (!menu_value('menu_collapsedAnswer')) return |
| 248 | //console.log('1111', document.querySelector('.CornerAnimayedFlex')) |
| 249 | if (document.querySelector('.CornerAnimayedFlex') && !document.getElementById('collapsed-button')) { |
| 250 | // 向网页中插入收起全部回答按钮+样式+绑定点击事件 |
| 251 | document.head.appendChild(document.createElement('style')).textContent = '.CornerButton{margin-bottom:8px !important;}.CornerButtons{bottom:45px !important;}'; |
| 252 | 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>'); |
| 253 | document.getElementById('collapsed-button').onclick = function () { |
| 254 | |
| 255 | // 收起所有评论(悬浮的 [收起评论]) |
| 256 | document.querySelectorAll('.Comments-container').forEach(function (el) { |
| 257 | let commentCollapseButton = getXpath('//button[text()="收起评论"]', el) |
| 258 | if (commentCollapseButton) commentCollapseButton.click(); |
| 259 | }); |
| 260 | // 收起所有评论(固定的 [收起评论]) |
| 261 | document.querySelectorAll('.RichContent >.ContentItem-actions>button:first-of-type').forEach(function (el) { |
| 262 | if (el.textContent.indexOf('收起评论') > -1) el.click() |
| 263 | }); |
| 264 | |
| 265 | if (location.pathname === '/' || location.pathname === '/hot' || location.pathname === '/follow') {// 对于首页的关注、推荐、热榜 |
| 266 | document.querySelectorAll('.ContentItem-rightButton').forEach(function (el) {if (el.hasAttribute('data-zop-retract-question')) {el.click();};}); |
| 267 | } else { |
| 268 | // 被 getCollapsedAnswerObserver 函数收起过的,固定 [收起] 按钮 |
| 269 | 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();});}) |
| 270 | // 被 getCollapsedAnswerObserver 函数收起过的,悬浮 [收起] 按钮(悬浮底部的横栏) |
| 271 | document.querySelectorAll('.RichContent:not([script-collapsed]) .ContentItem-actions.Sticky [data-zop-retract-question]').forEach(function(button) { |
| 272 | let el = button.parentElement; |
| 273 | while (!el.classList.contains('RichContent')) {el = el.parentElement;} |
| 274 | if (el) el.setAttribute('script-collapsed', ''); |
| 275 | button.click(); |
| 276 | }) |
| 277 | |
| 278 | const observer = getCollapsedAnswerObserver(); |
| 279 | observer.start(); |
| 280 | |
| 281 | if (!menu_value('menu_defaultCollapsedAnswer') && !observer._disconnectListener) { |
| 282 | window.addEventListener('urlchange', function() { |
| 283 | observer.end(); |
| 284 | window._collapsedAnswerObserver = null; |
| 285 | }) |
| 286 | observer._disconnectListener = true; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | |
| 294 | // 收起当前回答、评论(监听点击事件,点击网页两侧空白处) |
no test coverage detected