您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Add a button to collapse comments of lwn.net
// ==UserScript== // @name Collapse comments // @namespace https://franklinyu.github.io // @match https://lwn.net/Articles/* // @grant none // @version 0.1 // @author FranklinYu // @description Add a button to collapse comments of lwn.net // @license Apache-2.0 // ==/UserScript== const COLLAPSED = '▷' const EXPANDED = '▽' function getTree(comment) { const tree = comment?.nextElementSibling if (tree && tree.classList.contains('Comment')) { return tree } else { return null } } for (const comment of document.getElementsByClassName('CommentBox')) { if (!getTree(comment)) { continue // leaf comment } const toggle = document.createElement('button') comment.append(toggle) toggle.textContent = EXPANDED toggle.addEventListener('click', e => { const button = e.target const tree = getTree(button.parentElement) if (!tree) { console.warn('unexpected comment event: ', e) } if (button.textContent === EXPANDED) { button.textContent = COLLAPSED tree.style.display = 'none' } else { button.textContent = EXPANDED tree.style.display = '' } }) }