From 2c52ba99be9380508820f0934ea23fc1d7b96f57 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Sun, 18 Apr 2021 16:39:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20[=E6=94=B6=E8=B5=B7?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E5=9B=9E=E7=AD=94/=E8=AF=84=E8=AE=BA]=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9B=E4=BF=AE=E5=A4=8D=20[=E6=94=B6?= =?UTF-8?q?=E8=B5=B7=E5=BD=93=E5=89=8D=E5=9B=9E=E7=AD=94/=E8=AF=84?= =?UTF-8?q?=E8=AE=BA]=20=E5=8A=9F=E8=83=BD=E5=9C=A8=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=B5=81=E4=B8=AD=EF=BC=88=E5=A6=82=E9=A6=96=E9=A1=B5=EF=BC=89?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=94=B6=E8=B5=B7=E6=96=87=E7=AB=A0=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zhihu-Enhanced.user.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Zhihu-Enhanced.user.js b/Zhihu-Enhanced.user.js index 08d4a66..4e9ca2b 100644 --- a/Zhihu-Enhanced.user.js +++ b/Zhihu-Enhanced.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 知乎增强 -// @version 1.3.4 +// @version 1.3.5 // @author X.I.U // @description 移除登录弹窗、一键收起回答、收起当前回答/评论(点击两侧空白处)、快捷回到顶部(右键两侧空白处)、置顶显示时间、显示问题时间、区分问题文章、默认高清原图、默认站外直链 // @match *://www.zhihu.com/* @@ -96,8 +96,8 @@ function collapsedNowAnswer(selectors) { let rightButton = document.querySelector('.ContentItem-actions.Sticky.RichContent-actions.is-fixed.is-bottom') if (rightButton) { // 悬浮的 [收起回答](此时正在浏览回答内容 [头部区域 + 中间区域]) // 固定的 [收起评论](先看看是否展开评论) - let commentCollapseButton = rightButton.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel') - if (commentCollapseButton && commentCollapseButton.innerText.indexOf("收起评论") > -1) { + let commentCollapseButton = rightButton.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') + if (commentCollapseButton && commentCollapseButton.innerText.indexOf('收起评论') > -1) { commentCollapseButton.click(); } // 再去收起回答 @@ -110,9 +110,9 @@ function collapsedNowAnswer(selectors) { if (el.hasAttribute('data-zop-retract-question')) { if (isElementInViewport(el)) { // 固定的 [收起评论](先看看是否展开评论) - let commentCollapseButton = el.parentNode.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel') - if (commentCollapseButton && commentCollapseButton.innerText.indexOf("收起评论") > -1) { - commentCollapseButton.click(); + let commentCollapseButton = el.parentNode.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') + if (commentCollapseButton && commentCollapseButton.innerText.indexOf('收起评论') > -1) { + commentCollapseButton.click(); // 如果展开了评论,就收起评论 } el.click() // 再去收起回答 break @@ -127,10 +127,10 @@ function collapsedNowAnswer(selectors) { if (commentCollapseButton) { commentCollapseButton.click(); } else { // 固定的 [收起评论](此时正在浏览评论内容 [头部区域]) - let commentCollapseButton_1 = document.querySelectorAll('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel') + 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') if (commentCollapseButton_1.length > 0) { for (let el of commentCollapseButton_1) { - if (el.innerText.indexOf("收起评论") > -1) { + if (el.innerText.indexOf('收起评论') > -1) { if (isElementInViewport(el)) { el.click() commentCollapseButton_ = true // 如果找到并点击了,就没必要执行下面的代码了(可视区域中没有 [收起评论] 时) @@ -144,8 +144,8 @@ function collapsedNowAnswer(selectors) { if (commentCollapseButton_1.length > 0) { for (let el of commentCollapseButton_1) { if (isElementInViewport(el)) { - let commentCollapseButton = el.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector('button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel') - if (commentCollapseButton.innerText.indexOf("收起评论") > -1) { + let commentCollapseButton = el.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector('.ContentItem-actions > button.Button.ContentItem-action.Button--plain.Button--withIcon.Button--withLabel:first-of-type') + if (commentCollapseButton.innerText.indexOf('收起评论') > -1) { commentCollapseButton.click() break }