Faking cleaner URLs in the Debian BTS

By Chris Lamb

Debian bug #846500 requests that the Bug Tracking System moves the canonical URL for a given bug from:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=846500

… to the shorter, cleaner and generally less ugly:

https://bugs.debian.org/846500

(The latter currently redirects to the former.)


However, whilst we wait for a fix we can abuse the window.history object from the HTML History API to fake this locally:

var m = window.location.href
  .match(/https:\/\/bugs.debian.org\/cgi-bin\/bugreport.cgi\?bug=(\d+)(#.*)?$/);
if (!m) return;

for (var x of document.getElementsByTagName("a")) {
  var href = x.getAttribute("href");
  if (href && href.match(/^[^:]+\.cgi/)) {
      // Mangle relative URIs; <base> tag does not DTRT
      x.setAttribute('href', "/cgi-bin/" + href);
  }
}

history.replaceState({}, "", "/" + m[1] + window.location.hash);

This should work with most "user script" managers — I happen to use TamperMonkey in Chrome.


Chris Lamb is a freelance software developer and the current Debian Project Leader. You can read other posts by me, see software I have written or read more about me. You can also follow me @lolamby.


Tags: GNU/Linux Hacks

Planets: ALUG UWCS WUGLUG Debian

Friday 3rd November 2017