← 全部示例

操作 导航 stackoverflow.com

Stack Overflow:浮动答案跳转列表

添加所有答案及其评分的浮动列表,单击即可直接跳转到任意答案。

可复制的代码

/* Floating list of answers to jump between them */
(function () {
  if (document.getElementById('sof-answer-toc')) return;
  var answers = document.querySelectorAll('#answers .answer');
  if (answers.length < 2) return;
  var box = document.createElement('div');
  box.id = 'sof-answer-toc';
  box.style.cssText = 'position:fixed;right:10px;bottom:10px;background:#fff;border:1px solid #ccc;border-radius:6px;padding:6px;font-size:12px;z-index:9999;box-shadow:0 2px 8px rgba(0,0,0,0.2);';
  answers.forEach(function (a, i) {
    var score = a.querySelector('.js-vote-count');
    var link = document.createElement('a');
    link.textContent = 'Answer ' + (i + 1) + (score ? ' (' + score.textContent.trim() + ')' : '');
    link.style.cssText = 'display:block;padding:2px 6px;cursor:pointer;color:#0074cc;';
    link.addEventListener('click', function () {
      a.scrollIntoView({ behavior: 'smooth', block: 'start' });
    });
    box.appendChild(link);
  });
  document.body.appendChild(box);
})();

如何使用此示例

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

为此示例评分

暂无评分 — 成为第一个。

此示例有效吗?

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

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

免费下载 查看应用场景