User:JackSchmidt/JS ShowHiddenCats.js

function JS_ShowHiddenCats { JS_API(   {action:"query",prop:"categories",titles:wgPageName,format:"json"},    "cat",    function(id,txt) {      var p = eval("(" + txt + ")");      var cats = [];      for ( var pageid in p["query"]["pages"] ) {        pagecats = p["query"]["pages"][pageid]["categories"];        for ( var catkey in pagecats ) {          var cat = pagecats[catkey]["title"];          cat = cat.substring(9);          cats.push(cat);        }      }      var catlinks = document.getElementById("catlinks");      if(catlinks == null) {        catlinks = document.createElement("div");        document.getElementById("bodyContent").appendChild(catlinks);      }      catlinks.appendChild( document.createTextNode('Hidden categories: ') );      var viscats = catlinks.getElementsByTagName("a");      for ( var a in viscats ) {        a = viscats[a].title;        viscats[a] = a;      }      for ( var cat in cats ) { cat = cats[cat]; var title = 'Category:' + cat; if( viscats[title] == title ) continue; var a = document.createElement("a"); a.href = '/wiki/' + title; a.title = title; a.appendChild( document.createTextNode(cat) ); catlinks.appendChild( document.createTextNode(' | ') ); catlinks.appendChild( a ); if(addTooltip) addTooltip(a); }   }  ); };

$( JS_ShowHiddenCats );