Utilisateur:Dr Brains/LiveRC/Watchlist.js

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.
/* 
 --------------------------------------------------------------------------------------
 ---------LLLL---------III--------------------------RRRRRRRRRR--------CCCCC------------
 ---------LLLL---------III--------------------------RRRRRRRRRRRR----CCCCCCCCC----------
 ---------LLLL--------------------------------------RRR------RRR---CCC-----CCC---------
 ---------LLLL---------III--VV-----VV--EEEEEEEEE----RRR------RRR--CCC------------------
 ---------LLLL---------III---VV---VV---EEE----------RRRRRRRRRRR---CCC------------------
 ---------LLLL---------III---VV---VV---EEEEEE-------RRRRRRRRRR----CCC------------------
 ---------LLLL---------III----VV-VV----EEEEEE-------RRR-----RRR----CCC-----CCC---------
 ---------LLLLLLLLLLL--III----VVVVV----EEE----------RRR------RRR----CCCCCCCCC----------
 ---------LLLLLLLLLLL--III-----VVV-----EEEEEEEEE----RRR-------RRR-----CCCCC------------
 --------------------------------------------------------------------------------------
 
'''Extension de LiveRC'''
 
Permet de n'afficher que les modifications faites dans la liste de suivi
 
* Licence : ...?
* Documentation :
* Auteur : [[:fr:User:Dr Brains]]
* Développement et maintenance :
 
 
{{Catégorisation JS|LiveRC}}
 
<source lang=javascript> */
if (typeof(lrcHooks)!="undefined") { // DÉBUT IF
 
 
// Options
try{
lrcOptionMenuValues.showWL = false;
}catch(e){ }

// textes
try{
lrcTexts.showWL_SHORT = "LdS";
lrcTexts.showWL_TIP = "Ne montrer que les changements faits dans la liste de suivi";
}catch(e){ }

// Descriptions
try{
lrcParamDesc['DescshowWL']       = '[OnlyWatchlist] Case "LdS"';
lrcParamDesc['DescshowWL_SHORT'] = '[OnlyWatchlist] Texte de la case "LdS"';
lrcParamDesc['DescshowWL_TIP']   = '[OnlyWatchlist] Infobulle de la case "LdS"';
}catch(e){ }



function LiveRC_Watchlist_AddButton(){
    var ModeSelectionForm = document.getElementById('ModeSelectionForm');
    if(!ModeSelectionForm) return;
    var Span = document.createElement("span");
    Span.style.padding = "3px";
    Span.title = lrcMakeText("showWL_TIP");
    var NewInput = document.createElement('input');
    NewInput.id = "showWL";
    NewInput.type = "checkbox";
    NewInput.onclick = function(){ LiveRC_Watchlist_ToggleShowWL(); };
    var NewLabel = document.createElement('label');
    NewLabel.setAttribute('for', "showWL");
    NewLabel.innerHTML = lrcMakeText("showWL_SHORT");
    Span.appendChild(NewInput);
    Span.appendChild(NewLabel);
    ModeSelectionForm.insertBefore(Span, ModeSelectionForm.firstChild);
    if(lrcMakeOption("showWL")){ 
        NewInput.checked = "checked";
        LiveRC_Watchlist_ToggleShowWL();
    }
}
LiveRC_AddHook("AfterOptions", LiveRC_Watchlist_AddButton);

function LiveRC_Watchlist_ToggleShowWL(){
    var showWL = document.getElementById("showWL");
    var OtherInputs = new Array("showRC","showLog");
    if(!showWL) return;
    for(var a=0,l=OtherInputs.length;a<l;a++){
        var Input = document.getElementById(OtherInputs[a]);
        if(!Input) continue;
        Input.disabled = (showWL.checked ? "disabled" : false);
        var Label = Input.nextSibling;
        if(Label) Label.style.color = (showWL.checked ? "silver" : "black" );
    }
}

function LiveRC_Watchlist_makeRequest(){
    var showWL = document.getElementById("showWL");
    if(!showWL) return true;
    if(!showWL.checked) return true;

    var rcns;
    try{ rcns = document.getElementById('showNS0').firstChild.value; }catch(e){ }
    if (rcns == null) return;
    var wlshow = new Array();
    if(document.getElementById("showUsers").value != "ALLNBOTS") wlshow.push("!bot");
    if(document.getElementById("showUsers").value == "IPNEW") wlshow.push("!patrolled");
    if(document.getElementById("showUsers").value == "IPONLY") wlshow.push("anon");
    wlshow = (wlshow.length==0 ? "" : '&wlshow='+ wlshow.join("|") );

    var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath')
            + '/api.php?action=query&list=watchlist&wlnamespace='+rcns
            + '&wlprop=ids|title|flags|user|comment|parsedcomment|timestamp|sizes'+(lrcUserHasRight("autopatrol")?'|patrol':'')
            + wlshow
            + '&wlend=' + LiveRC_Config["LastRCtimestamp"] + '&wllimit=' + LiveRC_Config["UserInfos"].APIlimit
            + '&format=xml';
 
    wpajax.http({ url:URL, 
                  onSuccess:LiveRC_Watchlist_getRequest, 
                  nsfilter:rcns
    });
    return false;
}
LiveRC_AddHook("BeforeRC", LiveRC_Watchlist_makeRequest);

function LiveRC_Watchlist_getRequest(Req, data){
    if (document.getElementById('stopLive').checked){
        lrcDisplayDebug("");
        clearTimeout(lrcTimeout["RCRequest"]);
        lrcTimeout["RCRequest"] = setTimeout("liveRC()",1000);
        return;
    }
    var NSFilter = data.nsfilter; 
    var api = Req.responseXML.getElementsByTagName('api')[0]; 
    if (api.firstChild.nodeName == "error") return; 
    var query = api.getElementsByTagName('query')[0];
    var wls = query.getElementsByTagName('watchlist')[0].getElementsByTagName('item');
    var j,lenj,wl, rc;
 
    goNext(2); // Set lrcAllLinesSeen if we need to preload a line after the function completes.
    leni=wls.length;
    for (i=leni-1; i>=0; i--) { 
        if (wls[i].getAttribute('revid') <= lastrcid) continue;
        rc = new Object();
        rc.state = 0;
 
        lenj = wls[i].attributes.length;
        for (j=0; j<lenj; j++) {
            switch(wls[i].attributes[j].name) {
                case 'anon':
                    rc.state = lrcAddState(rc.state, "IP");
                    break;
                case 'bot':
                    rc.state = lrcAddState(rc.state, "BOT");
                    break;
                case 'new':
                    rc.state = lrcAddState(rc.state, "NEW");
                    break;
                case 'minor':
                    rc.state = lrcAddState(rc.state, "MINOR");
                    break;
                case 'patrolled':
                    rc.state = lrcAddState(rc.state, "PATROLLED");
                    break;
                case 'type':
                    break;
                default:
                    rc[wls[i].attributes[j].name] = wls[i].attributes[j].value;
                    break;
            }
        }  
        if (typeof(rc.comment) != "undefined") {
            lenj = commenttests.length;
            for (j=0; j<lenj; j++)
                if (new RegExp(commenttests[j].regex).test(rc.comment)) rc.state = lrcAddState(rc.state, commenttests[j].state);
        } 
        if (rc.newlen == 0) rc.state = lrcAddState(rc.state, "BLANKING"); 
        if (lrcSpecialLists["Sysop"].indexOf(rc.user) != -1)  rc.state = lrcAddState(rc.state, "SYSOP"); 
        if (lrcParams["GetPageInfos"]) {
            livePageInfos(rc);
        } else {
            getRevision(rc);
        }
    }
    if(wls[0]){
        lastrcid = wls[0].getAttribute('revid');
        lastrctimestamp = wls[0].getAttribute('timestamp').replace(new RegExp(/\D/g), "");
    }
    lrcDisplayDebug("");
    LiveRC_RequestError = 0;
    clearTimeout(lrcTimeout["RCRequest"]);
    lrcTimeout["RCRequest"] = setTimeout("liveRC()",lrcParams["Refresh"]*1000);
}

/* ************************************************************************************************************************************************ */
} // FIN IF

//</source>