mercurial-stay-on-tip

Provide changes links to tip version in Mercurial web interface if you are navigating from the tip version.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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/*
// @namespace https://greasyfork.org/users/9482
// ==/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);