Utilisateur:Gonioul/navigationsupp.js

Un article de Wikipédia, l'encyclopédie libre.

Note : Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements : Mozilla / Konqueror / Firefox : Shift-Ctrl-R, Internet Explorer / Opera : Ctrl-F5, Safari : Cmd-R.

// <pre><nowiki>
// Source: Dake + Goto
 
function NSclientSideGet(url, req, callback) {
  if ((req != null && callback == null)
    ||(req == null && callback != null)) {
    return("I need req && callback defined or not");
  }
 
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
  if (req) {
    if (callback == null) {
      // Synchronous request, wait till we have it all
      req.open('GET', url, false);
      req.send(null);
      return (req.responseText);
    } else {
      // Asynchronous request, set callback and go
      req.open('GET', url, true);
      req.onreadystatechange = callback;
      req.send(null);
      return (null);
    }
  } else {
    return ("XMLHTTPRequest not supported");
  }
}
 
//function NSclientSideGetResponse()
//{
//  if (NSreq.readyState != 4)
//    return;
//  return(NSreq.responseText);
//}
 
function NSTodayDate()
{
        var m = new Array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre")
        var today = new Date()
        var day = today.getDate()
        var year = today.getYear()
 
        if (year < 2000)
                year += 1900
 
        return (day + " " + m[today.getMonth()] + " " + year)
}
 
function getWikiDefCon() 
{
  var nswikidefcon = NSclientSideGet("http://fr.wikipedia.org/wiki/Modèle:WikiDefcon");
  if (nswikidefcon != null) {
    var nswdctable = new RegExp('.*<strong>WikiDefcon</strong> ([1-5]).*')
    var nswdc = nswdctable.exec(nswikidefcon)
    if (nswdc != null && nswdc.length >= 1) {
      return (nswdc[1])
    }
  }
}
 
function getWikiDefConImage() {
  var nswikidefcon = NSclientSideGet("http://fr.wikipedia.org/wiki/Modèle:WikiDefcon")
  if (nswikidefcon != null) {
    var nswdctable = new RegExp('.*"(http://upload.wikimedia.org/.*/Dc_([^ "]*)\\.png)".*')
    var nswdc = nswdctable.exec(nswikidefcon)
    if (nswdc != null && nswdc.length >= 1) {
      return (nswdc[1])
    }
  }
}
 
function NavigationSupp() 
{
  var a = document.getElementById("p-Navigation");
  if (!a)
  {
    a = document.getElementById("p-navigation");
  }
 
  if (a) 
  {
    b = a.getElementsByTagName("ul");
    if(b.length > 0)
    { 
      var startUrl = '/w/index.php?title='
      var endUrl = '&action=purge'
 
      // liste des URLs
      var urls = new Array()
      var labels = new Array()
 
      urls.push("")
      labels.push("")
 
      urls.push("Wikipédia:Bulletin des administrateurs")
      labels.push("WP:BA")
 
      urls.push("Wikipédia:Bot/Requêtes")
      labels.push("Bot Req")
 
      urls.push("Wikipédia:Vandalisme en cours/Alertes en cours")
      labels.push("Vandalisme")
 
      urls.push("")
      labels.push("")
 
      urls.push("Special:Recentchangeslinked/Portail:Transports en Île-de-France/Suivi")
      labels.push("RC Tran IDF")
 
      urls.push("Discussion Projet:Transports en Île-de-France")
      labels.push("(D Tran IDF)")
 
      urls.push("Special:Recentchangeslinked/Modèle:Portail_Stargate/Suivi")
      labels.push("RC Port Stargate")
 
      urls.push("Discussion Portail:Stargate")
      labels.push("(D Port Stargate)")
 
      urls.push("")
      labels.push("")
 
      urls.push("http://en.wikipedia.org/wiki/User:Gonioul")
      labels.push("((en))")
 
      urls.push("http://commons.wikimedia.org/wiki/User:Gonioul")
      labels.push("((commons))")
 
      if ( location.href.indexOf('/Special:Liste_de_suivi') != -1
       ||  location.href.indexOf('/Special:Watchlist') != -1
       ||  location.href.indexOf('/Special:Modifications_r%C3%A9centes') != -1
       || (location.href.indexOf('/Special:Recentchanges') != -1
        && location.href.indexOf('/Special:Recentchangeslinked') == -1)
       ) {
        urls.push("")
        labels.push("")
 
        urls.push("Modèle:WikiDefcon")
        labels.push('<img src="" title="Defcon" id="p-defcon" width="50" height="100" border="1">')
      }
 
      for (var i=0;i<urls.length;i++) {
        if (urls[i] == "") {
          b[0].innerHTML += '<br/>'
        } else {
          if (urls[i].indexOf('http://') == 0 ) {
            tableHTML = '<li><a href="' + urls[i] + '">' + labels[i] + "</a>"
          } else {
            tableHTML = '<li><a href="' + startUrl + urls[i] + endUrl + '">' + labels[i] + "</a>"
          }
          b[0].innerHTML += tableHTML
        }
      }
 
      var defcon = document.getElementById("p-defcon")
 
      if (defcon != null) {
        defcon.src = getWikiDefConImage()
      }
    }
  }
}
 
addLoadEvent(NavigationSupp);
 
// </nowiki></pre>