User:Iamunknown/image-templates.js

if (wgNamespaceNumber == 6) { /* document.write('<\/script>'); */

var xmlObject; var get_templates = { display: function { // 4 == download complete if(xmlObject.readyState == 4) {    /* var html; var match; var regexp; regexp = /Template:PD-GermanGov/; match = regexp.exec(xmlObject.responseText); */ if( document.getElementById         && document.childNodes          && document.createElement ) {     var parent; var newList; var templateNames; parent       = document.getElementById("filetoc"); newList      = document.createElement("ul"); templateNames = xmlObject.responseXML.getElementsByTagName("tl"); for (var i=0; i < templateNames.length; i++) {      newA            = document.createElement("a"); newLi          = document.createElement("li"); newA.innerHTML = templateNames[i].firstChild.nodeValue; newA.href      = encodeURIComponent(templateNames[i].firstChild.nodeValue); newLi.appendChild(newA); newList.appendChild(newLi); }

}    finalLi        = document.createElement("li"); var myTextNode = document.createTextNode("Templates"); finalLi.appendChild(myTextNode); finalLi.id    = "drop-down-template-menu"; finalLi.appendChild(newList); parent.appendChild(finalLi); var objCSS      = document.createElement("style"); objCSS.type     = "text/css"; objCSS.innerHTML = "#drop-down-template-menu           { display: block ! important; }\n" + "#drop-down-template-menu ul        { display: none  ! important; }\n" + "#drop-down-template-menu li        { display: block; }\n" + "#drop-down-template-menu:hover > ul { display: block ! important; }\n"; document.getElementsByTagName("head")[0].appendChild(objCSS); return true; }

}, // end display: function install: function {

var url; xmlObject = sajax_init_object; if(!xmlObject) { alert('Could not create XML object.'); } url = wgServer + wgScriptPath + '/query.php?what=templates&titles=' + encodeURIComponent(mw.config.get('wgPageName')) + '&format=xml'; xmlObject.open('GET', url, true); xmlObject.onreadystatechange = get_templates.display; xmlObject.send; return true;

} // end install: function

}; // end var get_templates

addOnloadHook(get_templates.install);

} // end if