← All examples

Action Navigation stackoverflow.com

Stack Overflow: floating answer jump list

Adds a floating list of all answers with their score so a single click jumps you straight to any of them.

Code to copy

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

How to use this example

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. Enable the action panel, add a button in the Actions tab and paste the code into it — run it with one click.

Rate this example

No ratings yet — be the first.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases