Jump to content

User:Nemoi/common.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function addClass(node, className) {
    if (hasClass(node, className)) {
        return false;
    }
    var cache = node.className;
    if (cache) {
        node.className = cache + ' ' + className;
    } else {
        node.className = className;
    }
    return true;
}
function removeClass(node, className) {
  if (!hasClass(node, className)) {
    return false;
  }
  node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className);
  return true;
}
function eregReplace(search, replace, subject) {
    return subject.replace(new RegExp(search,'g'), replace);
}

/**
 * Permet d'afficher les catégories cachées pour les contributeurs enregistrés, en ajoutant un (+) à la manière des boîtes déroulantes
 */
function hiddencatN(){
  if(document.URL.indexOf("printable=yes")!=-1) return;
  if( !(hc = document.getElementById('mw-hidden-catlinks')) ) return;
  if( hasClass(hc, 'mw-hidden-cats-user-shown') ) return;
  if( hasClass(hc, 'mw-hidden-cats-ns-shown') )   addClass(hc, 'mw-hidden-cats-hidden');
  var nc = $('#mw-normal-catlinks');
  removeClass(nc, 'catlinks-allhidden' );
  hclink = nc.append('<a id="mw-hidden-cats-link" title="Cet article contient des catégories cachées" style="cursor: pointer; color: black; ">[+]</a>');
  hclink.click(function() {
    if( hasClass(hc, 'mw-hidden-cats-hidden') ) {
      removeClass(hc, 'mw-hidden-cats-hidden');
      addClass(hc, 'mw-hidden-cat-user-shown');
      changeText(hclink, '[–]');
    } else {
      removeClass(hc, 'mw-hidden-cat-user-shown');
      addClass(hc, 'mw-hidden-cats-hidden');
      changeText(hclink, '[+]');
    }
  });
}
$(hiddencatN);