User:Darkoneko/monobook.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// = = = = = = = start of the code to replace the "user page" link in centralAuth to a contributions page link

function addContribLinkForCentralAuth() {
  if( wgCanonicalSpecialPageName != "CentralAuth" ) return //not on the right page
  var form = document.getElementById("mw-centralauth-merged")
  if(!form) return //no table shown yet 

  var tr = form.getElementsByTagName("table")[0].getElementsByTagName("tr")

  for(var a = 1 ; a < tr.length-1 ; a++) { 
     var link = tr[a].getElementsByTagName("td")[1].getElementsByTagName("a")[0]
     link.href = link.href.replace("User:", "Special:Contributions/")
  }

}
$(addContribLinkForCentralAuth)


// = = = = = = = end of that.


//default summary for centralauth
function addDefaultSummaryForCentralAuth() {
  if ( wgCanonicalSpecialPageName == "CentralAuth" ) {
     var resume = document.getElementById('mw-centralauth-reason')
     if ( resume  ) {
       resume.value += "vandalism account and/or offensive username"
       resume.focus()
     }
   }
}

$(addDefaultSummaryForCentralAuth)




//Ajout de liens internes (bistro, PàS, etc.) dans la boîte de navigation à gauche
function customizeLeftBar() {
  var ul = document.getElementById("p-navigation").getElementsByTagName("ul")[0]
  if( !ul ) return ; //fin
  
  ul.appendChild( createLiAdressNode( 
             new Array('http://meta.wikimedia.org/wiki/Special:CentralAuth', 'http://meta.wikimedia.org/wiki/Special:GlobalBlock'), 
             new Array('CentralAuth', 'IP lock')
  ) )
 
  ul.appendChild( createLiAdressNode( 
             'http://meta.wikimedia.org/wiki/Special:UserRights', 
             'UserRights'
  ) )
  ul.appendChild( createLiAdressNode( 
             'http://meta.wikimedia.org/wiki/Steward_requests/Permissions', 
             'req/local'
  ) )


}
 
 



function customizeTopBar() {
   var logout = document.getElementById("pt-logout")
   if (!logout) return
   var topBarUl = logout.parentNode
   var topBarLiArray = topBarUl.getElementsByTagName("li")


   var userlink = document.getElementById('pt-userpage')

   //ajouter un lien vers la page user:darkoneko lorsque connecté depuis un autre compte
   if( userlink.getElementsByTagName("a")[0].firstChild.nodeValue != 'Darkoneko' ) {
       topBarUl.insertBefore( createLiAdressNode('/wiki/User:Darkoneko', '-Darkoneko-'), userlink )
   }   


   var mytalk = document.getElementById('pt-mytalk');

   //ajouter "js" a gauche de discussion
   topBarUl.insertBefore( createLiAdressNode('/wiki/user:'+wgUserName+'/'+skin+'.js', 'js'), mytalk)

   //ajouter "css" a gauche de discussion, donc il sera entre "js" et "discut'"
   topBarUl.insertBefore( createLiAdressNode('/wiki/user:'+wgUserName+'/'+skin+'.css', 'css'), mytalk)


   //changer l'en tete pour "Page de discussion"
   mytalk.getElementsByTagName("a")[0].firstChild.nodeValue = "discut'"

   //changer l'en tete pour "Préférences"
   document.getElementById('pt-preferences').getElementsByTagName("a")[0].firstChild.nodeValue = "prefs"

   //changer l'en tete pour "Liste de suivi"
   document.getElementById('pt-watchlist').getElementsByTagName("a")[0].firstChild.nodeValue = "watchlist"

   //changer l'en tete pour "Contributions"
   document.getElementById('pt-mycontris').getElementsByTagName("a")[0].firstChild.nodeValue = "contribs"

   //ajouter "log" a gauche de déconnexion
   topBarUl.insertBefore( createLiAdressNode('/w/index.php?title=Special:log&user='+wgUserName, 'log'), logout )

   //changer l'en tete pour "Deconnexion"
   logout.getElementsByTagName("a")[0].firstChild.nodeValue = "X"

 
}



//le 3eme parametre est facultatif
function createLiAdressNode(href, texte, onclick) {
  var li = document.createElement('li')
 
  //un seul élement, ou un tableau de plusieurs élements ?
  if (href.constructor == Array) {
    if (arguments.length == 2) onclick = new Array(); //le 3eme argument n'a pas été passé.
    for (i=0; i<href.length; i++) { 
       //un array retourne undefined sur les clef n'existant pas
       li.appendChild( createAdressNode(href[i], texte[i], ((onclick[i]!='undefined')?onclick[i]:'') ) ) 
       li.appendChild( document.createTextNode( ' - ' ) )
    }
    li.removeChild(li.lastChild)     //retirer le dernier tiret
  } else {
     if (arguments.length == 2) onclick = ''; //le 3eme argument n'a pas été passé
     li.appendChild( createAdressNode(href, texte, onclick ) ) 
  }
  return li
}
 
 
function createAdressNode(href, texte, onclick) {
  var a = document.createElement('a')
  a.href = href
  a.appendChild(document.createTextNode( texte ) )
  if(arguments.length == 3) {   a.setAttribute("onclick", onclick )  }
 
  return a
}


function main() {
   customizeLeftBar()
   customizeTopBar()
}
 
$(main)