Utilisateur:Dr Brains/HistoryHideBots.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.
// {{Projet:JavaScript/Script}} 
 
/////////////////////////////////////// RÉCUPÉRATION DE LA LISTE DES BOTS  ///////////////////////////////////////
 
 
// '/api.php?action=query&list=allusers&aulimit=1&auprop=groups&aufrom=' + UserName
 
function HistoryHideBots_UpdateUserList(Group, CookieName, UserList, UserContinue){
      if((!Group)||(!CookieName)) return;
      if(!UserList) UserList = new Array();
      if(!UserContinue) UserContinue = '';
      var APILimit = 499;
      if((mw.config.get('wgUserName')=="sysop")||(mw.config.get('wgUserName')=="bot")) APILimit = 4999;
      var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') 
             + '/api.php?format=xml&action=query&list=allusers'
             + '&aulimit='+APILimit
             + '&augroup='+Group
             + UserContinue;
      var NouvelleRequete = new XMLHttpRequest();      
      NouvelleRequete.open("GET", url, true);
      NouvelleRequete.send(null);
      NouvelleRequete.onreadystatechange = function() {
            if(NouvelleRequete.readyState == 4 && NouvelleRequete.status == 200) {
                  var ObjetXML = NouvelleRequete.responseXML; 
                  var Users = ObjetXML.getElementsByTagName('u');
                  for(a=0;a<Users.length;a++){
                        var UserName = Users[a].getAttribute('name');
                        if(UserName) UserList.push(UserName);
                  } 
                  var UserContinue = ObjetXML.getElementsByTagName('query-continue')[0];          
                  if(UserContinue){
                        var AutreRequeteContinue = '&aufrom=' + UserContinue.getElementsByTagName('allusers')[0].getAttribute('aufrom');
                        HistoryHideBots_UpdateUserList(Group, CookieName, UserList, AutreRequeteContinue);
                  }else{
                        var cookieValue = UserList.join(';');
                        var now = new Date();
                        var CookieDelay = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 7 );
                        document.cookie = escape(CookieName) + '=' + escape(cookieValue) + '; EXPIRES=' + CookieDelay.toGMTString()  + "; PATH=/" ; 
                        window.location.reload();
                  }
            }
      }
}
 
function HistoryHideBots_GetUserList(Group, cookieName){
      var cookieValue = false;
      var posName = document.cookie.indexOf(escape(cookieName) + '=' );
      if (posName != -1) {
            var posValue = posName + (escape(cookieName) + '=' ).length;
            var endPos = document.cookie.indexOf(';', posValue) ;
            if (endPos != -1) {
                  cookieValue = unescape(document.cookie.substring(posValue, endPos));
            } else {
                  cookieValue = unescape(document.cookie.substring(posValue));
            }
      }
      if(cookieValue){
            return decodeURIComponent(cookieValue);
      }else{ 
            return false;
      }
}
 
if(typeof(wgBotMembers)=="undefined"){
      wgBotMembers = HistoryHideBots_GetUserList('bot', 'User-Group-bot');
      if(!wgBotMembers){
            HistoryHideBots_UpdateUserList('bot', 'User-Group-bot');
      }else{
            wgBotMembers = wgBotMembers.split(';');
      }
}

/////////////////////////////////////// FONCTION PRINCIPALE  ///////////////////////////////////////

if(typeof(HistoryHideBots_AutoHide)=="undefined") HistoryHideBots_AutoHide = true;
if(typeof(HistoryHideBots_OnlyInterwikiBots)=="undefined") HistoryHideBots_OnlyInterwikiBots = true;

if(mw.config.get('wgAction')=="history") addOnloadHook(HistoryHideBots_AddLink);

var HistoryHideBots_Text = new Array();
HistoryHideBots_Text["HideText"] = "Masquer les robots";
HistoryHideBots_Text["HideTitle"] = "Masquer les modifications faites par des robots";
HistoryHideBots_Text["ShowText"] = "Afficher les robots";
HistoryHideBots_Text["ShowTitle"] = "Afficher les modifications faites par des robots";

function HistoryHideBots_AddLink(){
      var Form = document.getElementById("mw-history-compare");
      if(!Form) return;
      var NewP = document.createElement('p');
      var NewA = document.createElement('a');
      NewA.id = "BotsToggleLink";
      NewA.title = HistoryHideBots_Text["HideTitle"];
      NewA.innerHTML = HistoryHideBots_Text["HideText"];
      NewA.href = "javascript:HistoryHideBots_ToggleBots();";
      NewP.appendChild(NewA);
      Form.parentNode.insertBefore(NewP, Form);
      if(HistoryHideBots_AutoHide) HistoryHideBots_ToggleBots();
}


function HistoryHideBots_ToggleBots(){
      var Form = document.getElementById("mw-history-compare");
      var Link = document.getElementById("BotsToggleLink");
      if(!Form || !Link) return;
      var Display;
      if(Link.innerHTML == HistoryHideBots_Text["HideText"]){
            Link.innerHTML = HistoryHideBots_Text["ShowText"];
            Link.itle = HistoryHideBots_Text["ShowTitle"];
            Display = "none";
      }else{
            Link.innerHTML = HistoryHideBots_Text["HideText"];
            Link.itle = HistoryHideBots_Text["HideTitle"];
            Display = "";
      }
      var Lis = Form.getElementsByTagName('li');
      for(var a=0,l=Lis.length;a<l;a++){
            var UserName = HistoryHideBots_GetUserName(Lis[a]);
            if(!UserName) continue;
            if(wgBotMembers.indexOf(UserName)==-1) continue;
            if(HistoryHideBots_OnlyInterwikiBots){
                  var IsInterwikiBot = HistoryHideBots_IsInterwikiBot(Lis[a]);
                  if(!IsInterwikiBot) continue;
            }
            Lis[a].style.display = Display;
      }
}


function HistoryHideBots_GetUserName(Li){
      var AllLinks = Li.getElementsByTagName('a');
      var UserName = false;
      for(var a=0;a<AllLinks.length;a++){
            if($(AllLinks[a]).hasClass("mw-userlink")){
                  UserName = AllLinks[a].innerHTML;
                  return UserName;
            }
      }
      return false;
}

function HistoryHideBots_IsInterwikiBot(Li){
      var Links = Li.getElementsByTagName('a');
      for(var a=0,l=Links.length;a<l;a++){
            if($(Links[a]).hasClass("extiw")) return true;
      }
      return false;
}


//</nowiki></pre></source>