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.
/*<nowiki>Copyright (c) 2023 theleekycauldronPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.*/importScript('User:Theleekycauldron/Scripts/PSHAW/dependencies/Hook.js');importScript('User:Theleekycauldron/Scripts/PSHAW/dependencies/Credit.js');importScript('User:Theleekycauldron/Scripts/PSHAW/dependencies/File.js');classPrep{constructor(title){this.title=title;//MediaWiki stuff}asyncinitialize(){awaitget_pages(this.title,"user|content",null,"older").then((res)=>{this.page=resthis.content=this.page[0].revisions[0].slots.main.content;this.loadHooks();this.loadFiles();})}loadHooks(){letsplittext=this.content.split("\n");letip=[splittext.indexOf("<!--Hooks-->")+2,splittext.indexOf("<!--HooksEnd-->"),splittext.indexOf("-->")+1,splittext.indexOf("</div>")];//important split pointslethooktext=splittext.slice(ip[0],ip[1]);letcreditstext=splittext.slice(ip[2],ip[3]);this.hooks=[]for(varh=0;h<hooktext.length;h++){lethook=newHook(h,hooktext[h].slice(2),[])this.hooks.push(hook)if(hook.articles.length>0){for(cincreditstext){letcredit=newCredit(creditstext[c]);if(credit.articleinhook.articles){hook.credits.push(credit)}}}else{hook.credits.push(newCredit("* {{DYKmake|Example|Editor|subpage=}}"))if(h==hooktext.length-1){hook.credits.push(newCredit("* {{DYKnom|Example|Nominator}}"))}}}}loadFiles(){letfiletext=this.content.match(/\{\{main page image\/DYK.*?}}/g);this.file=newFile(filetext[0])}morebits(){letres=[]for(lethookofthis.hooks){res.push({type:'option',label:hook.morebits(),value:i})}if(this.isEmpty()){res.push()}returnres}isEmpty(){returnthis.hooks.every(hook=>hook.articles.length==0)}addHook(hook,slot,file){if(slot==0){this.file=file}this.hooks[slot]=hook}assemble(){letres=[]res.push(`<noinclude>{{Did you know/Clear/header}}==Hooks==</noinclude>{{DYK bottom prep notice}}<!--Hooks-->`)res.push(this.file.mpi()+"<!--See [[Template:Main page image/DYK]] for other parameters-->")for(lethookofthis.hooks){res.push("* "+hook.content)}res.push(`<!--HooksEnd-->{{flatlist|class=dyk-footer noprint|style=margin-top: 0.5em; text-align: right;}}* '''[[Wikipedia:Recent additions|Archive]]'''* '''[[Help:Your first article|Start a new article]]'''* '''[[Template talk:Did you know|Nominate an article]]'''{{endflatlist}}<noinclude>{{Did you know/Clear/torso}}==Credits==<div id="credits">This space is to credit the creators/nominators of the items in this template that in fact appear on the Main Page. If you replace or remove an item before it appears on the Main Page, please revert the promotion of the hook so its template appears again at [[Template talk:Did you know]] and add a note to the nomination's template explaining why you removed it.<!--******************** Example format ********************** (Follow this or you WILL break something)**** Normal credit: * {{DYKmake|ArticleName|Editor|subpage=}}** Nomination credit: * {{DYKnom|ArticleName|Nominator}}**** Each credit MUST go on a new line*********************************************************-->`)for(lethookofthis.hooks){for(letcreditofhook.credits){res.push(credit.content)}}res.push(`</div>{{Did you know/Clear/footer}}</noinclude>`)this.content=res.join("\n")returnthis.content}save(summary){varparams={action:'edit',title:this.title,summary:summary,text:this.content,format:'json'}api.postWithToken('csrf',params).done(function(data){console.log(data);});}}// </nowiki>