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.
varRefreshingAlready=false;varalreadyScanned=false;varMainLoop=function(index){setInterval(function(){// Setup againendDate=newDate(index.getAttribute("data-end")).getTime();now=newDate().getTime();distance=endDate-now;if(!alreadyScanned){alreadyScanned=true;varsanitizedCode=encodeURIComponent(index.getAttribute("data-event"));$.post("https:"+mw.config.get("wgServer")+"/w/api.php?action=parse&format=json&title="+mw.config.get('wgPageName')+"&text="+sanitizedCode+"&pst=1",function(res){if(!res||!res.parse||!res.parse.text)returnconsole.log("Preview failed");varStrippedText=res.parse.text['*'];//Trim off div/p tagsvarendTrim=StrippedText.search(/<\/p>/g)-1;StrippedText=StrippedText.substring(33,endTrim);index.setAttribute("data-event",StrippedText);});}if(isNaN(distance)){// Something went terribly wrong with parsing the dates.// Display errorindex.innerHTML='<strong class="error">[LiveCountdown] Parsing date from "'+index.getAttribute("data-end")+'" returned NaN, check parameters "month/day/year/customdate"</strong>';}else{// Time calculations for days, hours, minutes and seconds (copied from W3Schools)vardays=Math.floor(distance/(1000*60*60*24));varhours=Math.floor((distance%(1000*60*60*24))/(1000*60*60));varminutes=Math.floor((distance%(1000*60*60))/(1000*60));varseconds=Math.floor((distance%(1000*60))/1000);// Display the resultindex.innerHTML="There are <b>"+days+"</b> days, <b>"+hours+"</b> hours, <b>"+minutes+"</b> minutes, and <b>"+seconds+"</b> seconds until "+index.getAttribute("data-event")+".";}// If the count down is finished, refreshif(distance<0){index.innerHTML="Countdown expired, refreshing...";if(!RefreshingAlready){document.location.reload();RefreshingAlready=true;}}},1000);};varcounts=document.getElementsByClassName("toxicountdown");if(counts.length>0){for(vari=0;i<counts.length;i++){counts[i].innerHTML="Loading countdown...";varendDate=newDate(counts[i].getAttribute("data-end")).getTime();varnow=newDate().getTime();vardistance=endDate-now;if(distance<0){counts[i].innerHTML="The countdown finished.";}else{if(counts[i].getAttribute("data-event").search(/<(\/|)script>/g)!=-1){//script tag, do not runcounts[i].innerHTML='<strong class="error">[LiveCountdown] Possible XSS detected in event parameter. As a safety precaution, this countdown is cancelled. Please revert the recent edits immediately.</strong>';}else{MainLoop(counts[i]);}}}}else{console.log("[LiveCountdown] No countdown widgets detected.");}