Aller au contenu

Utilisateur:Dr Brains/OversightDeluxe.js

Une page de Wikipédia, l'encyclopédie libre.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
if(mw.config.get('wgAction')=="history") addOnloadHook(OversightDeluxe_ModifyButton);
if((document.URL.indexOf("&action=historysubmit&revisiondelete=1")!=-1)&&(document.URL.indexOf("&OversightDeluxe=1")!=-1)) addOnloadHook(OversightDeluxe_HistorySubmitModify);



function OversightDeluxe_ModifyButton(){
    var OldButtons = document.getElementsByName('revisiondelete');
    if(!OldButtons) return;
    for(var a=0;a<OldButtons.length;a++){
        OldButtons[a].style.display = "none";
        var NewButtons = ''
        + '<input type="button" class="historysubmit" '
        + 'title="Sélectionner une suite de versions" value="Sélectionner une suite de versions à afficher/masquer" '
        + ' onclick="OversightDeluxe_Select();" '
        + ' onselect="OversightDeluxe_Select();" '
        + '/>'
        + '<input id="OversightDeluxeInput" type="button" class="historysubmit" '
        + 'title="'+ OldButtons[a].innerHTML+'" value="' +OldButtons[a].innerHTML+'" '
        + ' onclick="OversightDeluxe_GetControlPanel();" '
        + ' onselect="OversightDeluxe_GetControlPanel();" '
        + '/>';
        OldButtons[a].parentNode.innerHTML += NewButtons;
    }
}

function OversightDeluxe_GetControlPanel(){
    var PageHistory = document.getElementById("mw-history-compare");
    if(!PageHistory) return;
    var ControlPanel = document.getElementById("revisiondelete_ControlePanel");
    if(!ControlPanel){
        ControlPanel = document.createElement('div');
        ControlPanel.id = "revisiondelete_ControlePanel";
        PageHistory.insertBefore(ControlPanel, PageHistory.firstChild);
    }
    var Ids = new Array();
    var IdsChecked = new Array();
    var Inputs = PageHistory.getElementsByTagName('input');
    for(var b=0;b<Inputs.length;b++){
        if(Inputs[b].type == "checkbox"){
            var InputName = Inputs[b].name;
            var Id = InputName.replace(/.*\[/, "").replace(/\]/, "");
            Ids.push(Id);
            if(Inputs[b].checked) IdsChecked.push(Id);
        }
    }
    if(!IdsChecked[0]){ 
        alert('Aucune case cochée'); 
        return; 
    }

// http://fr.wikipedia.org/w/index.php?title=Utilisateur%3ADr_Brains%2FChantier_6&action=historysubmit&revisiondelete=1
// &diff=53015553&oldid=53002473&ids[53002464]=1&ids[52962979]=1

    var Adresse = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName') 
               + '&action=historysubmit&revisiondelete=1&OversightDeluxe=1'
               + '&diff='+Ids[0]+'&oldid='+Ids[1]
    for(var a=0;a<IdsChecked.length;a++){
        Adresse += '&ids['+IdsChecked[a]+']=1';
    }

    while(ControlPanel.firstChild){ControlPanel.removeChild(ControlPanel.firstChild); }
    var NewFrame = document.createElement("iframe");
    NewFrame.src=Adresse;
    NewFrame.width="100%";
    NewFrame.height = "300px";
    ControlPanel.appendChild(NewFrame);
    NewFrame.focus();


    var Input = document.getElementById("OversightDeluxeInput");
    var CancelInput = document.createElement('input');
    CancelInput.type = "button";
    CancelInput.className = "historysubmit";
    CancelInput.id = "OversightDeluxeInputCancel";
    CancelInput.value = "Annuler";
    CancelInput.onclick = function(){
        OversightDeluxe_Cancel();
    }
    CancelInput.onselect = function(){
        OversightDeluxe_Cancel();
    }
    $(CancelInput).insertAfter(Input);
}

function OversightDeluxe_Cancel(){
    var ControlPanel = document.getElementById("revisiondelete_ControlePanel");
    if(ControlPanel)while(ControlPanel.firstChild){ControlPanel.removeChild(ControlPanel.firstChild); }
    var Input = document.getElementById("OversightDeluxeInputCancel");
    Input.parentNode.removeChild(Input);
}

function OversightDeluxe_Select(){
    var History = document.getElementById("pagehistory");
    if(!History) return;
    var Lis = History.getElementsByTagName('li');
    var Licount = -1;
    var FirstSelected = false;
    var LastSelected = false;
    while(Licount<Lis.length){
        Licount++
        Li = Lis[Licount];
        if(!Li) break;
        if($(Li).hasClass("selected")){
            OversightDeluxe_Check(Li, true);
            if(!FirstSelected){
                FirstSelected = Li;
            }else{
                LastSelected = Li;
                break;
            }
        }else if((FirstSelected)&&(!LastSelected)){
            OversightDeluxe_Check(Li, true);
        }else{
            OversightDeluxe_Check(Li, false);
        }
    }
}

function OversightDeluxe_Check(Li, Checked){
    var Inputs = Li.getElementsByTagName('input');
    for(var a=0;a<Inputs.length;a++){
        if(Inputs[a].type == "checkbox") Inputs[a].checked = (Checked ? "checked" : "");
    }
}

function OversightDeluxe_HistorySubmitModify(){
    var Content = document.getElementById("bodyContent");
    if(!Content) Content = document.getElementById("mw_contentholder");
    if(!Content) Content = document.getElementById("article");
    if(!Content) return;
    var ContentHTML = Content.innerHTML;
    document.body.innerHTML = ContentHTML;
}