// HG log linkify
// version 1.0
// 2008-06-05
// Copyright (c) 2008, Zbigniew Braniecki
// Released under the GPL/MPL/LGPL tri-license
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "hglog linkify", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          hglog linkify
// @namespace     http://labs.braniecki.net
// @description   this script makes bug numbers and revision ids clickable
// @include       http://hg.mozilla.org/*
// ==/UserScript==

var regexps = Array()
regexps.push(Array(/(?:b=|bug |fix |bg | |\,|bug=)([0-9]{4,7})/ig,'<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=$1">$&</a>'))
regexps.push(Array(/(?:changeset |cs=)([a-z0-9]{12})/g,'<a href="http://hg.mozilla.org/index.cgi/mozilla-central/rev/$1">$&</a>'))
// This one makes revision id clickable in the changelog
//regexps.push(Array(/([a-z0-9]{12}):/,'<a href="http://hg.mozilla.org/index.cgi/mozilla-central/rev/$1">$1</a>:'))

function linkify (elems, regexps) {
  for(var i in elems)
    if(elems[i].innerHTML)
      for (var r in regexps)
        elems[i].innerHTML=elems[i].innerHTML.replace(regexps[r][0], regexps[r][1])
}

linkify(document.getElementsByTagName('strong'), regexps)
linkify(document.getElementsByClassName('title'), regexps)

