Stack Overflow:为答案编号
在每个答案开头添加可见的序号,便于在评论中引用它们。
可复制的代码
/* Prefix every answer with a visible index number */
(function () {
function number() {
document.querySelectorAll('#answers .answer').forEach(function (a, i) {
if (a.dataset.sofNum) return;
a.dataset.sofNum = '1';
var cell = a.querySelector('.answercell .js-post-body') || a.querySelector('.answercell');
if (!cell) return;
var tag = document.createElement('div');
tag.textContent = '#' + (i + 1);
tag.style.cssText = 'font-weight:700;font-size:13px;color:#6a737c;margin-bottom:6px;';
cell.insertBefore(tag, cell.firstChild);
});
}
number();
new MutationObserver(number).observe(document.body, { childList: true, subtree: true });
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 启用操作面板,在「操作」选项卡中添加按钮并粘贴代码 — 一键运行。
为此示例评分
暂无评分 — 成为第一个。