Note : après avoir enregistré vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : Maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac) ;
  • Google Chrome : Appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac) ;
  • Internet Explorer : Maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ;
  • Opera : Allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité & sécurité → Effacer les données d'exploration → Images et fichiers en cache.
// Does a lookup two previous Page:* from the current, extract the rh from
// its content, insert it in the header after trying to increase the rh page
// number. See the FIXME comment(s) for caveats.

function fill_rh(data)
{
    try {
        var header = document.getElementsByName('wpHeaderTextbox')[0];
        if (header && !data.query.pages["-1"]) {
            for (var ids in data.query.pages) {
                var content = data.query.pages[ids].revisions[0]['*'];
                var r = new RegExp("{{rh[^}]*}}");
                var match = r.exec(content);
                if (match) {
                   // FIXME: needs to be tweaked, actually works only if the first
                   // sequence of digit in the rh is the one and only one we want
                   // to modify.
                   var rh = match[0];
                   var r = new RegExp("(\\d+)");
                   var page = Number(r.exec(rh)[1]) + 2;
                   rh = rh.replace(/\d+/, page);
                   header.value = header.value + '\n' +  rh;
                   pr_toggle_visibility()
                }
            
                break;
            }
        }
    }
    catch (err) { }
}

function create_script_obj(url)
{
    var scriptObj = document.createElement("script");
    scriptObj.setAttribute("type", "text/javascript");
    scriptObj.setAttribute("src", url);
    document.body.appendChild(scriptObj);
}

function set_running_header()
{
    var r = new RegExp("(\\d+)$");
    var page = Number(r.exec(wgPageName)[1]) - 2;
    var pagename = wgPageName.replace(/\d+$/g, page);

    var url = wgServer + wgScriptPath
        + "/api.php?action=query&prop=revisions&callback=fill_rh&rvprop=content"
        + "&format=json&titles=" + encodeURIComponent(pagename);

    create_script_obj(url);
}

function addButton2(id,alt,comment,source,onclick){
 
	var tb  = document.getElementById("toolbar"); 
	if(tb){
		var image = document.createElement("img");
		image.width = 46;
		image.height = 22;
		image.border = 0;
		image.className = "mw-toolbar-editbutton";
		image.style.cursor = "pointer";
		image.alt = alt;
		image.title = comment;
		image.src = source;
		image.onclick = onclick;
		tb.appendChild(image);
        }
}

function addRhButton()
{
     // FIXME: change the icon, by one with Rh letter drawn on it.
     addButton2("wpRh", "Running header auto", "Running header",
                "http://upload.wikimedia.org/wikipedia/commons/a/af/Button_Fractur_OCR.png", set_running_header);
}

$(document).ready(addRhButton);