Skip to content

Commit c5bcfae

Browse files
committed
调整 [一键收起回答] 为默认关闭(存在缺陷且可被 [默认收起回答] 替代)
1 parent 3719e04 commit c5bcfae

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'use strict';
2525
var menu_ALL = [
2626
['menu_defaultCollapsedAnswer', '默认收起回答', '默认收起回答', true],
27-
['menu_collapsedAnswer', '一键收起回答', '一键收起回答', true],
27+
['menu_collapsedAnswer', '一键收起回答', '一键收起回答', false],
2828
['menu_collapsedNowAnswer', '收起当前回答/评论(点击两侧空白处)', '收起当前回答/评论', true],
2929
['menu_backToTop', '快捷回到顶部(右键两侧空白处)', '快捷回到顶部', true],
3030
['menu_blockUsers', '屏蔽指定用户', '屏蔽指定用户', true],
@@ -108,14 +108,22 @@ function defaultCollapsedAnswer() {
108108
}
109109

110110

111-
// 一键收起回答
111+
// 一键收起回答(全部)
112112
function collapsedAnswer() {
113113
if (!menu_value('menu_collapsedAnswer')) return
114114
if (document.querySelector('.CornerAnimayedFlex')) {
115115
document.head.appendChild(document.createElement('style')).textContent = '.CornerButton{margin-bottom:8px !important;}.CornerButtons{bottom:45px !important;}';
116-
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="Button CornerButton Button--plain"><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>');
116+
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="Button CornerButton Button--plain"><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>');
117117
document.getElementById('collapsed-button').onclick = function () {
118-
document.querySelectorAll('.ContentItem-rightButton[data-zop-retract-question]').forEach(function (el) {el.click()});
118+
document.querySelectorAll('.RichContent').forEach(function (el) {
119+
if (el.querySelector('.RichContent-inner').offsetHeight > 400) {
120+
const button = el.querySelector('.ContentItem-rightButton[data-zop-retract-question]')
121+
if (button) {
122+
el._defaultCollapsed = true
123+
button.click()
124+
}
125+
}
126+
});
119127
}
120128
}
121129
}

0 commit comments

Comments
 (0)