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.
/*Moves refs and citation needed tags after punctuation.*/varnamespaceNumber=mw.config.values.wgNamespaceNumber;// Add a link just above the edit box, if you're in the main namespace.if(namespaceNumber===0){$("#editform").prepend('<div id="footnote-cleanup"><a href="javascript:cleanupFootnotes()">clean up footnotes</a></div>');}functioncleanupFootnotes(){vartextbox=$("#wpTextbox1");if(textbox){varoldContents=textbox.val();varcontents=oldContents;varescaped=[];vari=0;varescape=function(text,regexString){varregex=newRegExp(regexString,"g");text=text.replace(regex,function(match){escaped[i]=match;replacement="%%"+i+"%%";i+=1;returnreplacement;});returntext;};/* Escape various things: ref tags */contents=escape(contents,"<ref[^>]*>[^<]+<\/ref>");// footnote templatescontents=escape(contents,"\{\{(?:sfn|efn|rfn)[^\}]+\}\}");// citation neededcontents=escape(contents,"\{\{(?:[Cc]itation needed|[Cc]n|[Ff]act|[Cc]b|[Cc]tn|[Rr]ef\?)[^\}]+\}\}");if(i>0){mw.notify(i+" refs found.");}varpunctuation="[\.\,\;\:\)]{1,3}";varcount=0;varreplacements=[];contents=contents.replace(/((?:%%\d+%%)+)([\.\,\;\:\)]{1,3})/g,function(match,capture1,capture2){count+=1;varreplacement=capture2+capture1;replacements.push(replacement);returnreplacement;});mw.notify(count+" correction"+((count>1&&"s")||"")+" made: "+replacements.join());// Unescape the various things escaped above.contents=contents.replace(/%%(\d+)%%/g,function(wholematch,number){number=Number(number);returnescaped[number];});varisUnchanged=(oldContents===contents);if(isUnchanged){mw.notify("No misplaced footnotes were found.");}textbox.val(contents);$("#wpSummary").val(function(index,summary){mw.notify(summary);varaddition="made sure refs are after punctuation with [[User:Erutuon/footnoteCleanup.js|JavaScript]]";afterSectionName=summary.match(/^\/\*[^\*]+\*\/\s+(.+)/);if(afterSectionName&&afterSectionName[1].length>1){addition="; "+addition;}if(!isUnchanged&&(!afterSectionName||!afterSectionName.includes(addition))){returnsummary+addition;}});}}