User:DodoMan/adminmenu.js

From Test 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.
/**
 *
 * Fonction get
 *
**/
function getHTTPObject() {
  var xmlhttp = false;
  /* on essaie de créer l'objet si ce n'est pas déjà fait */
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp = false;
      }
    }
  return xmlhttp;
}

/**

 *
 * Affiche un nouveau Menu à gauche avec quelques liens pratiques
 * Toutes modifications devraient se faire sur la page du menu
 *
**/
function AddMenuAdmin() {
  var contenu = 'Erreur d\'affichage';
  var HTTPMenu = new getHTTPObject();
  if (HTTPMenu) {// requête au serveur
    HTTPMenu.open('GET', mw.config.get('wgServer')+'/wiki/MediaWiki:Gadget-MenuAdmin/Menu?action=render', true);
    HTTPMenu.onreadystatechange = function () {
      if (HTTPMenu.readyState == 4) {
        var reponse = HTTPMenu.responseText;
        var deb = '<div id="OuvreMenu"></div>';
        var ideb =  reponse.indexOf(deb)+deb.length;
        var fin = '<div id="FermeMenu"></div>';
        var ifin = reponse.indexOf(fin);
        contenu = reponse.substring(ideb,ifin);
        if (mw.config.get('skin') == "monobook"){
          var l = document.getElementById("column-one");
          if (l) {
            l.innerHTML = '<div class="portlet" id="p-MenuAdmin">'
            + '<h3>Menu Admin</h3><div class="pBody">'
            + contenu
            + '</div></div>' 
            + l.innerHTML;
          }
          var menu_class = "";
        } else if (mw.config.get('skin') == "vector"){
          var l= document.getElementById("p-Navigation");
          if (l) {
            l.insertAdjacentHTML('afterend', '<nav id="p-MenuAdmin" class="vector-menu mw-portlet mw-portlet-Aide vector-menu-portal portal" aria-labelledby="p-MenuAdmin-label" role="navigation">'
            + '<h3 id="p-MenuAdmin-label" class="vector-menu-heading"><span class="vector-menu-heading-label">Menu Admin</span></h3>'
            + '<div class="vector-menu-content">'
            + contenu
            + '</div></nav>');
          }
        } else if (mw.config.get('skin') == "vector-2022"){
          var l= document.getElementById("p-Navigation");
          if (l) {
            l.insertAdjacentHTML('afterend', '<nav id="p-MenuAdmin" class="vector-menu mw-portlet mw-portlet-Aide vector-menu-portal portal" aria-labelledby="p-MenuAdmin-label" role="navigation">'
            + '<h3 id="p-MenuAdmin-label" class="vector-menu-heading"><span class="vector-menu-heading-label">Menu Admin</span></h3>'
            + '<div class="vector-menu-content">'
            + contenu
            + '</div></nav>');
          }
        } else if (mw.config.get('skin') == "timeless"){
          var l= document.getElementById("p-userpagetools");
          if (l) {
            l.insertAdjacentHTML('afterend', '<div class="mw-portlet" role="navigation" id="p-MenuAdmin" aria-labelledby="p-MenuAdmin-label">'
            + '<h3 id="p-MenuAdmin-label" dir="ltr" lang="fr">Menu Admin</h3>'
            + '<div class="mw-portlet-body">'
            + contenu
            + '</div></div>');
          }
        }
      }
    }// fin gestion onreadystatechange
  HTTPMenu.send(null); 
  }
}
$(AddMenuAdmin);