Utilisateur:Dr Brains/Divers.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.
/////////////////////////////////////////// Fonctions diverses ///////////////////////////////////////////////




// Bistro du jour

if(typeof(TodayDate)=="undefined"){
  TodayDate = function() {
    var
      m = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
      today = new Date(),
      day = today.getDate(),
      year = today.getYear();
    if (year < 2000) {
      year = year + 1900;
    }
    return (day + " " + m[today.getMonth()] + " " + year);
  }
}

window.BistroDuJour = function(){
  var Target = document.getElementById("p-navigation");
  if(!Target) return;
  var Ul = Target.getElementsByTagName('ul')[0];
  if(!Ul) return;
  var Li = document.createElement("li");
  Li.id = 'n-bistro';
  var Link = document.createElement('a');
  Link.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace(/\$1/, 'Wikipédia:Le_Bistro/' + TodayDate().replace(/ /g, "_"))
  Link.innerHTML = 'Bistro du jour';
  Li.appendChild(Link);
  Ul.appendChild(Li);
} 
$(BistroDuJour);

// Réglages polices d'écriture 
//importStylesheet('User:Dr_Brains/polices.css');

// Ouverture liens externes dans un nouvel onglet
$(function() {
    var alinks = document.getElementsByTagName('a');
    var tablink, sitename;
    for (var i = 0, leng = alinks.length; i < leng; i++) {
        tablink = alinks[i];
        if( (tablink.className.indexOf("external")!= -1) && (tablink.href.indexOf(mw.config.get('wgServer')) == -1))
            tablink.target = "_blank";
    }
});

// Ajout liens discussion et contributions dans la catégorie "Wikipédien désirant être parrainé"
 
window.ChercheFilleul = function(){ 
        if((mw.config.get('wgPageName')=="Catégorie:Wikipédien_désirant_être_parrainé")&&(mw.config.get('wgAction')=="view")){
                var CategoryArea = document.getElementById("mw-pages");
                var Ul = CategoryArea.getElementsByTagName("li");
                for(b=0;b<Ul.length;b++){
                        var Lien = Ul[b].getElementsByTagName("a");
                        for(c=0;c<Lien.length;c++){
                              Cible = Lien[c].innerHTML.split(mw.config.get('wgFormattedNamespaces')[2]+":").join('');
                              var Ajout = ' (<a target="_blank" title="Discussion" href="' + mw.config.get('wgServer') + mw.config.get('wgArticlePath').split('$1').join(mw.config.get('wgFormattedNamespaces')[3]+":"+encodeURIComponent(Cible)) + '" >d</a>'
                              Ajout += ' - <a target="_blank" title="Contributions" href="' + mw.config.get('wgServer') + mw.config.get('wgArticlePath').split('$1').join('Special:Contributions/' + encodeURIComponent(Cible)) + '" >c</a>)';
                        }
                        Ul[b].innerHTML += Ajout; 
                }
        }
}
$(ChercheFilleul);

// Interwikis dans les pages perso .js et .css
$(function(){
      var AllSkins = new Array();
      AllSkins.push('common');
      AllSkins.push('monobook');
      AllSkins.push('modern');
      AllSkins.push('vector');
      AllSkins.push('chick');
      AllSkins.push('myskin');
      AllSkins.push('simple');

      var MatchSkin = false;
      for(var b=0;b<AllSkins.length;b++){
            if(mw.config.get('wgTitle') == mw.config.get('wgUserName')+'/'+AllSkins[b]+'.js') MatchSkin = true;
            if(mw.config.get('wgTitle') == mw.config.get('wgUserName')+'/'+AllSkins[b]+'.css') MatchSkin = true;
      }
      if(!MatchSkin) return;

      var Column = document.getElementById('column-one');
      if(!Column) Column = document.getElementById('mw-portlets');
      if(Column){
            var PortletClass = 'portlet';
            var PBodyClass = 'pBody';
      }
      if(!Column){
            Column = document.getElementById('mw-panel');
            var PortletClass = 'portal';
            var PBodyClass = 'body';
      }
      if(!Column) return;
      var PLang = document.getElementById('p-lang');
      if(!PLang){
            PLang = document.createElement('div');
            PLang.id = 'p-lang';
            PLang.className = PortletClass;
            PLang.innerHTML = '<h5>Autres langues</h5><div class="'+PBodyClass+'"><ul></ul></div>';
            Column.appendChild(PLang);
      }
      if(!PLang) return;
      var LangUl = PLang.getElementsByTagName('ul')[0];
      if(!LangUl){
            var DivBody = PLang.appendChild(document.createElement('div'));
            DivBody.className = PBodyClass;
            LangUl = DivBody.appendChild(document.createElement('ul'));
      }
      var OtherLangagesWikipedia = new Array();
      OtherLangagesWikipedia.push('en');
      OtherLangagesWikipedia.push('es');
      OtherLangagesWikipedia.push('de');
      OtherLangagesWikipedia.push('it');
      
      for(var a=0;a<OtherLangagesWikipedia.length;a++){
            LangUl.innerHTML += '<li><a href="//'+OtherLangagesWikipedia[a]+'.wikipedia.org/wiki/User:'+mw.config.get('wgTitle')+'">'+OtherLangagesWikipedia[a]+'</a></li>'
      }
});

// Réouverture des boîtes déroulantes entourées d'un <div class="BoiteOuverte"></div>
$(function(){
      var AllDivs = document.getElementsByTagName('div');
      for(var a=0;a<AllDivs.length;a++){
            if($(AllDivs[a]).hasClass("BoiteOuverte")){
                  var AllDivsBis = AllDivs[a].getElementsByTagName('div');
                  for(var b=0;b<AllDivsBis.length;b++){
                        if($(AllDivsBis[b]).hasClass("NavFrame")){
                              var index = AllDivsBis[b].id.split('NavFrame').join('');
                              toggleNavigationBar(index);
                        }
                  }
            }
      }
});

// Ouverture recherche dans un nouvel onglet
$(function(){
     var FormeRecherche = document.getElementById('searchform');
     if(FormeRecherche) FormeRecherche.setAttribute("target", "_blank");
});

// Retour automatique après connexion et ajout/retrait d'une page dans la liste de suivi

window.AutoReturnTo_Target;
window.AutoReturnTo_Tempo = 5
window.AutoReturnTo_Enabled = true;
window.AutoReturnTo = function(){
    var ReturnP = document.getElementById("mw-returnto");
    if(!ReturnP) return;
    var ReturnLink = ReturnP.getElementsByTagName('a')[0];
    if(ReturnLink){
        AutoReturnTo_Target = ReturnLink.href;
        var CountDown = document.createElement('sup');
        var CountDownLink = document.createElement('a');
        CountDownLink.id = 'AutoReturnTo_CountDown';
        CountDownLink.innerHTML = AutoReturnTo_Tempo;
        CountDownLink.href = "javascript:AutoReturnTo_Disable();";
        CountDown.appendChild(CountDownLink);

        ReturnP.appendChild(CountDown);
        setTimeout("AutoReturnTo_CountDown();", 1000);
    }
}

window.AutoReturnTo_CountDown = function(){
    var CountDown = document.getElementById('AutoReturnTo_CountDown');
    if( !CountDown || !AutoReturnTo_Enabled ) return;
    var Count = parseInt(CountDown.innerHTML);
    Count = (Count-1);
    CountDown.innerHTML = Count;
    if(Count == 0){
        document.location=AutoReturnTo_Target;
        return;
    }else{
        setTimeout("AutoReturnTo_CountDown()", 1000);
    }
}

window.AutoReturnTo_Disable = function(){
    var CountDown = document.getElementById('AutoReturnTo_CountDown');
    if(CountDown) CountDown.parentNode.removeChild(CountDown);
    AutoReturnTo_Enabled=false;
}
if( (document.URL.indexOf("&action=watch")!=-1) || (document.URL.indexOf("&action=unwatch")!=-1) || mw.config.get('wgCanonicalSpecialPageName') == "Userlogin" ) $(AutoReturnTo);


// insertion de balises personnalisées
window.BalisePerso_defaultbalise = "s";
 
window.BalisePerso_onclickBalise = function() {
  var balise = window.prompt("Nom de la balise ?", BalisePerso_defaultbalise);
  if(balise != null)
    insertTags('<' + balise + '>','</' + balise + '>', '');
}
 
window.BalisePerso_insertBalise = function() {
  var specialcharsets = document.getElementById("specialcharsets");
  if (specialcharsets == null) return;
  var insertBalisesP = specialcharsets.getElementsByTagName("p")[0];
  if(!insertBalisesP) return;
  var insertBalises = insertBalisesP.getElementsByTagName("a");
  for(var a=0,l=insertBalises.length;a<l;a++){  
    var ThisBalise = insertBalises[a];
    if(ThisBalise.innerHTML == "&lt;&gt;&lt;/&gt;" || ThisBalise.innerHTML == "<></>") ThisBalise.href = "javascript:BalisePerso_onclickBalise();";
    else continue;   
  }
}
$(BalisePerso_insertBalise);


/////////////////////////////////////////////////////// Nombre au hasard

window.rand = function(top, down){
   if(!down) down = 0;
   if(!top) top = 1;
   return Math.floor(Math.random()*((top-down)+1)+down);
}

// Pop-up avant déconnexion

$(function(){
  var LogoutLi = document.getElementById("pt-logout");
  if(!LogoutLi) return;
  var LogoutLink = LogoutLi.getElementsByTagName('a')[0];
  if(!LogoutLink) return;
  LogoutLink.onclick = function(){
    var Confirm = confirm("Êtes-vous sûr de vouloir vous déconnecter ?");
    return (!!Confirm);
  }
});