4

This is a mere convenience user script. It prevents page reloading when following links to answers that happen to be present on the same page, and instead simply scrolls to the linked answer.

// ==UserScript==
// @name     Stack Exchange: Faster Answer Links
// @version  1
// @grant    none
// @run-at   document-start
// @match    https://*.stackexchange.com/*
// @match    https://*.superuser.com/*
// @match    https://*.stackoverflow.com/*
// @match    https://*.mathoverflow.net/*
// @match    https://*.serverfault.com/*
// @match    https://*.askubuntu.com/*
// @match    https://stackapps.com/*
// @exclude  https://chat.stackexchange.com/*
// @exclude  https://api.stackexchange.com/*
// @exclude  https://data.stackexchange.com/*
// @exclude  https://openid.stackexchange.com/*
// @exclude  https://contests.stackoverflow.com/*
// @exclude  /^https?:\/\/winterbash\d{4,}\.stackexchange\.com\//
// ==/UserScript==

document.addEventListener('click', ev => {
  if (ev.defaultPrevented)
    return;
  if (ev.target.tagName !== 'A')
    return;

  const u = new URL(ev.target.href);
  if (u.origin !== location.origin)
    return;

  let m;
  if (m = /^(?:\/a\/|\/questions\/[^\/]+\/)(\d+)(?=\/|$)/u.exec(u.pathname)) {
    if (!document.getElementById('answer-' + m[1]))
      return;
    ev.preventDefault();
    location.href = '#answer-' + m[1];
  }
}, false);

0

You must log in to answer this question.

Browse other questions tagged .