User:Jsimlo/shortcuts-dev.js
Appearance
From Wikipedia, the free encyclopedia
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This code will be executed when previewing this page.
This user script seems to have a documentation page at User:Jsimlo/shortcuts-dev.
//<pre><nowiki> /********************************************************************** * * * Changes to this file affect other users. * * Please discuss on the talk page before editing. * * * **********************************************************************/ varshortcutsVersion="1.1.0"; varshortcutsReleaseDate="2007年02月03日"; /*********************************************************** * INTERFACE ***********************************************************/ /** * Starts a new section of links. Function for external use. */ functionshortcutsStartSection(name) { shortcutsLinks[shortcutsLinks.length]={'name':name,'links':newArray()}; } /** * Adds new link into the current section of links. Function for external use. */ functionshortcutsAddLink(name,article) { varlinks=shortcutsLinks[shortcutsLinks.length-1]['links']; links[links.length]={'name':name,'article':article}; } /*********************************************************** * IMPLEMENTATION ***********************************************************/ /** * Link maker. * Creates and returns an li element with the desired link. */ functionshortcutsMakeLink(name,url) { varntxt=document.createTextNode(name); varna=document.createElement('a'); varnli=document.createElement('li'); na.setAttribute('href','/wiki/'+url); nli.setAttribute('class','n-shortcut'); na.appendChild(ntxt); nli.appendChild(na); returnnli; } /** * Portlet maker. * Creates and returns a portlet populated by list of links. */ functionshortcutsMakePortlet(name,links) { varnportlet=document.createElement('div'); varnh5=document.createElement('h5'); varntit=document.createTextNode(name); varnbody=document.createElement('div'); varnul=document.createElement('ul'); nportlet.setAttribute('id','p-'+name); nportlet.setAttribute('class','portlet'); nbody.setAttribute('class','pBody'); nul.setAttribute('id','p-'+name); for(vari=0;i<links.length;i++) nul.appendChild( shortcutsMakeLink(links[i]['name'],links[i]['article']) ); nh5.appendChild(ntit); nportlet.appendChild(nh5); nbody.appendChild(nul); nportlet.appendChild(nbody); returnnportlet; } /** * Main function. * Enumerates all non-empty sections, and adds new portlets beneath the old ones. */ functionshortcutsMain() { varsidecol=document.getElementById('column-one'); for(vari=0;i<shortcutsLinks.length;i++) if(shortcutsLinks[i]['links'].length>0) sidecol.appendChild( shortcutsMakePortlet(shortcutsLinks[i]['name'],shortcutsLinks[i]['links']) ); } /** * Initializes the onload events. */ functionshortcutsInitialize() { shortcutsInit(); shortcutsMain(); } /*********************************************************** * INITIALIZATION ***********************************************************/ varshortcutsLinks=newArray(); shortcutsStartSection(wgUserName?wgUserName:'shortcuts'); addOnloadHook(shortcutsInitialize); //</nowiki></pre>