Stack Overflow:折叠低分答案
将低于分数阈值的答案折叠成一个条,点击可展开完整内容;跳过已采纳的答案。
可复制的代码
/* Collapse answers below a score threshold, click to expand */
(function () {
var MIN = 1;
function collapse() {
document.querySelectorAll('#answers .answer').forEach(function (a) {
if (a.dataset.sofLow || a.classList.contains('accepted-answer')) return;
var el = a.querySelector('.js-vote-count');
if (!el) return;
var score = parseInt(el.getAttribute('data-value') || el.textContent, 10);
if (isNaN(score) || score >= MIN) return;
a.dataset.sofLow = '1';
var body = a.querySelector('.answercell');
if (!body) return;
body.style.display = 'none';
var bar = document.createElement('div');
bar.textContent = 'Low-score answer (' + score + ') — click to expand';
bar.style.cssText = 'cursor:pointer;background:#f1f2f3;padding:6px 10px;border-radius:4px;font-size:13px;color:#555;';
bar.addEventListener('click', function () {
body.style.display = '';
bar.remove();
});
a.insertBefore(bar, body);
});
}
collapse();
new MutationObserver(collapse).observe(document.body, { childList: true, subtree: true });
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。