← 全部示例

操作 导航 stackoverflow.com

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 });
})();

如何使用此示例

  1. 用上方按钮复制代码。
  2. 安装 JustZix(2 分钟),在目标页面打开扩展。
  3. 添加一条匹配该页面的新规则。
  4. 启用操作面板,在「操作」选项卡中添加按钮并粘贴代码 — 一键运行。

为此示例评分

暂无评分 — 成为第一个。

此示例有效吗?

没有可粘贴的地方,代码片段毫无用处。

JustZix 安装只需 2 分钟,并在每个匹配的页面上运行你的代码。无需账户、无需付费。

免费下载 查看应用场景