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.
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.
/* * Grabs text from a Template documentation page that is wrapped in * <pre id="autoload_template"></pre> tags and inserts it into the document * * The aim of this is to allow users to easily insert blank templates into * pages and save thm looking up the parameters names and/or orders * * There is two way to use it, for both add * importScript('User:Inductiveload/Autoload template.js'); * to your javascript. * * then add a link in the left regex menu, add [[m:TemplateScript]] to your * .js with this template: * { name: 'Autoload template', script:autoloadTemplate } */functionget_autoload_data(data){try{//the textbox to insert the text intovartextbox=document.getElementsByName('wpTextbox1')[0];if(textbox&&!data.query.pages["-1"]){for(varidindata.query.pages){varcontent=data.query.pages[id].revisions[0]['*'];varr=newRegExp('<pre id="[Aa]utoload">([\\s\\S]*?)</pre>');varmatch=r.exec(content);if(match){vartemplate_text=match[1];// prepend the autoloaded text to the editbox content// TODO: insert at cursor (possible?)textbox.value=template_text+"\n"+textbox.value;}else{alert("No preloadable text found");}break;}}}catch(err){}}functioncreate_script_obj(url){varscriptObj=document.createElement("script");scriptObj.setAttribute("type","text/javascript");scriptObj.setAttribute("src",url);document.body.appendChild(scriptObj);}functiongetTemplateName(){vartemplate_name=window.prompt("Template to autoload","");returntemplate_name;}functionautoloadTemplate(){varname=getTemplateName();vartemplate_pagename="Template:"+name+"/doc";varurl=wgServer+wgScriptPath+"/api.php"+"?action=query"+"&prop=revisions"+"&callback=get_autoload_data"+"&rvprop=content"+"&format=json"+"&titles="+encodeURIComponent(template_pagename);create_script_obj(url);}