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.
/*importScript('User:M/jquery.js');importScript('User:M/dereference.js');*//*! selectText jQuery plugin by Steve Clay http://code.google.com/p/mrclay/source/browse/trunk *//* * Simple plugin to select a range of text within a text box/textarea */(function(){functionselectText(el,begin,end){varlen=el.value.length;end=end||len;if(begin==null)el.select();elseif(el.setSelectionRange)el.setSelectionRange(begin,end);elseif(el.createTextRange){vartr=el.createTextRange(),c="character";tr.moveStart(c,begin);tr.moveEnd(c,end-len);tr.select();}elseel.select();el.focus();}jQuery.fn.selectText=function(begin,end){this.length&&selectText(this.get(0),begin,end);returnthis;};})();// Adds a link below the page heading which replaces references of the following form:// <ref name=aa/><ref>678</ref>// <ref name="bb">// </ref>// with this form:// [1][2]// [3]// The refs are re-inserted upon submit (unless these numbers are deleted).// // TODO: // * Dump the refs into a list, where clicking each opens a textarea with its removed ref data.// * Timer to check for new number-refs, add them to list, allow creation. Check duplicates [12][12], highlight removed for re-insertion.// * Handle slashes in: ref name="aa/bb".// * Entry form for template refs instead of textarea, make ref list look nicer.// * More efficient, if problems arise.//// "...that removes all refs into an a div below the edit textarea, replacing them with numbers[439]. // If you mess with the number, the ref-down-there turns red. Click the button to inject another ref // below using reftools, and a number inline. Parsing/replacing the refs wouldn't be very difficult, // and then add a timer that makes sure the numbers are all still there in the text. Offer little 'add // this ref' for any new numbers (so right now I'd see '439: [click to add ref]' somewhere below)."//$(window).load(addRefTab);functionaddRefTab(){if(window.___location.href.indexOf("action=")==-1)return;$("<div id='refbox' style='display:none;margin-bottom:.4em; border:1px solid #bbb;background:#fafafa;border-top:none;padding:1px;margin-bottom:.3em;'></div></div>").insertAfter($("#wpTextbox1"));$("<div id='refbutton' style='padding-top:.3em;text-align:center;cursor:pointer; border:1px solid #bbb;background:#fafafa;border-top:none;padding:1px;margin-bottom:.3em;'>References</div>").insertAfter($("#wpTextbox1"));$("#refbutton").click(function(){$("#refbox").slideDown(500);$(this).fadeTo(100,.01).slideUp(100);hideRefs();}).mouseenter(function(){$(this).css("color","#900").css("background","#fafafa");}).mouseleave(function(){$(this).css("color","black").css("background","#fafafa");});$("#wpTextbox1").width($("#refbutton").width());}varrefMap=newArray();functionhideRefs(){vart1=newDate().getTime()if(window.___location.href.indexOf("action=")==-1)return;vartext=$("#wpTextbox1").val();//var regex = /<ref\b[^(/>)>]*(\/>|>(?:(?! y4bo4gche5h)[\s\S])*?<\/ref>)/;// also absorbs comments to the sides of the refvarregex=/(<!--(?:(?!-->)[\s\S])*?-->[ ]*)*<ref\b[^(/>)>]*(\/>|>(?:(?! y4bo4gche5h)[\s\S])*?<\/ref>)([ ]*<!--(?:(?!-->)[\s\S])*?-->)*/varcurRefNum=0;varnum=0;$("#refbox").append("<div id='reflist' style='font-size:90%'><b>References:</b> </div>");$("#refbox").append($("<div style='border:0px solid red;'><textarea style='margin-top:.5em;width:98.5%;margin-left:.5em;height:7em;' id='refcontent'></textarea></div>"));vart2=newDate().getTime()for(;;){curRefNum++;varmatch=text.match(regex);if(match==null)break;varstartR=match.index;varendR=match[0].length+startR;varrText=text.substring(startR,endR);while(text.indexOf("["+curRefNum+"]")>=0){curRefNum++;}text=text.substring(0,startR)+"["+curRefNum+"]"+text.substring(endR,text.length);refMap[""+curRefNum]=rText;$("#reflist").append($("<span style='cursor:pointer;' id='ref-"+curRefNum+"'/>").text(curRefNum+", ").mouseenter(function(){$(this).css("background","red");varrefnum=$(this).attr("id").substr(4);$("#refcontent").val(refMap[refnum]);varloc=$("#wpTextbox1").val().indexOf("["+refnum+"]");$("#wpTextbox1").selectText(loc,loc+2+refnum.length);}).mouseleave(function(){$(this).css("background","none");$("#refcontent").val("");}));num++;}vart3=newDate().getTime()alert(t3-t2);$("#wpTextbox1").text(text);$("#refclean").text("DeReferenced "+num+" references. They will be added back upon save/preview/changes, unless [2][56] etc. are removed.");$("#editform").submit(function(){$("#refclean").text("Rereferencing...");vartext2=$("#wpTextbox1").val();for(varkeyinrefMap){//TODO: notify missing refs.text2=text2.split("["+key+"]").join(refMap[key]);}$("#wpTextbox1").text(text2);$("#refclean").text("Rereferenced");returntrue;});}// Adds a link below the page heading which replaces references of the following form:// <ref name=aa/><ref>678</ref>// <ref name="bb">// </ref>// with this form:// [1][2]// [3]// The refs are re-inserted upon submit (unless these numbers are deleted).// //<ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref>//<ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref>//<ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref><ref>678</ref>