Created
May 15, 2012 17:15
-
-
Save keeganwitt/2703399 to your computer and use it in GitHub Desktop.
A userscript to change links to tip version in Mercurial web interface if you are navigating from the tip version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name mercurial-stay-on-tip | |
// @version 0.1 | |
// @description Provide changes links to tip version in Mercurial web interface if you are navigating from the tip version. | |
// @author Keegan Witt | |
// @include http://hg.openjdk.java.net/* | |
// ==/UserScript== | |
// a function that loads jQuery and calls a callback function when jQuery has finished loading | |
function addJQuery(callback) { | |
var script = document.createElement('script'); | |
script.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'); | |
script.addEventListener('load', function() { | |
var script = document.createElement('script'); | |
script.textContent = '(' + callback.toString() + ')();'; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
// the guts of this userscript | |
function main() { | |
var pathname = window.location.pathname; | |
if (pathname.indexOf("/tip/") >= 0 && pathname.indexOf("/log/") < 0) { // don't run if not navigating from tip or if viewing log | |
var links = $('table:first > tbody > tr > td > a'); | |
for (var i = 0; i < links.length; i++) { | |
links[i].href = links[i].href.replace(/\/file\/[^\/]+\//, '/file/tip/'); | |
links[i].href = links[i].href.replace(/\/log\/[^\/]+\//, '/log/tip/'); | |
links[i].href = links[i].href.replace(/\/annotate\/[^\/]+\//, '/annotate/tip/'); | |
} | |
} | |
} | |
// load jQuery and execute the main function | |
addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment