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.
$(function($){setTimeout(function(){$.when(mw.loader.using(['mediawiki.util']),$.ready).then(function(){varportletlink=mw.util.addPortletLink('p-tv','#','Update episodes');$(portletlink).click(function(e){e.preventDefault();// Textbox contentsvarNumEpisodesM;varwpTextbox1=document.getElementById('wpTextbox1');varwpTextbox1_V=wpTextbox1.value.split("\n");// Declare variablesvarNumEpisodes=false;varRTitle=false;varline;varOriginalAirDate=false;varEpisodeNumber=false;varRmvRefs=false;// Go though contents one line at a timefor(vari=0;i<wpTextbox1_V.length;i++){// Retreive particular lineline=wpTextbox1_V[i];// Remove references param set, and on to the next episode rowif(RmvRefs&&(line.toLowerCase().indexOf('episode list')>=0||line.trim()=='}}'))RmvRefs=false;// Update num_episodes in Template:Infobox_television, if it existsif(!NumEpisodesM){NumEpisodesM=line.match(/(\s*\|\s*num_episodes\s*=\s*(<onlyinclude>)?)(\d+)(.*)/);if(NumEpisodesM)NumEpisodes=parseInt(NumEpisodesM[3])+1;}// Check if first appearance of RTitle is foundif(!RTitle){// If line contains RTitle, set to <<RTitle>> if only a ref (will be removed later), else set to contents of RTitle is more than a ref (e.g. raw episode title).varRTitleM=line.match(/(\s*\|\s*RTitle\s*=\s*)([^<]*)<ref(.*)/);if(RTitleM){if(RTitleM[2]==="")line='<<RTitle>>';elseline=RTitleM[1]+RTitleM[2];RTitle=true;RmvRefs=true;}// Catch episode number to add to summaryvarEpisodeNumberM=line.match(/(\s*\|\s*EpisodeNumber\s*=\s*)(.*)/);if(EpisodeNumberM)EpisodeNumber=EpisodeNumberM[2];}elseif(!OriginalAirDate){// If RTitle is found but OriginalAirDate not set, find the next occurrence// of OriginalAirDate to update Template:Aired_episodes, if it existsvarOriginalAirDateM=line.match(/(\s*\|\s*OriginalAirDate\s*=\s*)\{\{[s|S]tart date\|([^\}]*)\}\}/);if(OriginalAirDateM)OriginalAirDate=OriginalAirDateM[2].replace("|df=y","");}// Remove director/writer/etc. referencesif(RmvRefs)line=line.replace(/<ref(.*)\/(ref)?\>/g,"");// Update linewpTextbox1_V[i]=line;}EpisodeNumber=(EpisodeNumber?EpisodeNumber:NumEpisodes);// Save values or get saved valuesif(OriginalAirDate){// If EpisodeNumber/OriginalAirDate was found, saved it from transcluded season page for LoE page updatelocalStorage.setItem('EpisodeNumber',EpisodeNumber);localStorage.setItem('OriginalAirDate',OriginalAirDate);}elseif(localStorage.getItem('OriginalAirDate')||localStorage.getItem('EpisodeNumber')){// If EpisodeNumber/OriginalAirDate was not found, obtain it from transcluded season page save for LoE page updateOriginalAirDate=localStorage.getItem('OriginalAirDate');localStorage.removeItem('OriginalAirDate');EpisodeNumber=localStorage.getItem('EpisodeNumber');localStorage.removeItem('EpisodeNumber');}// Alert of no existance of OriginalAirDate/EpisodeNumbervarupdate=true;if(!OriginalAirDate&&!EpisodeNumber){alert('Be sure to update the individual transcluded season page first, then the List of Episode page, to save the episode number and air date.');update=false;}// Update summaryvarsummary=document.getElementById('wpSummary');if(summary.value.indexOf('Update]]; aired')>=0)summary.value+=" ["+EpisodeNumber+"]";elseif(update)summary.value+="[[User:Alex 21/script-updateepisodes|Update]]; aired ["+EpisodeNumber+"]";// Concatenate textbox values again, but without <<RTitle>>varwpTextbox1NewValue='';for(i=0;i<wpTextbox1_V.length;i++)if(wpTextbox1_V[i]!='<<RTitle>>')wpTextbox1NewValue+=wpTextbox1_V[i]+"\n";// Update |num_episodes=if(NumEpisodesM){if(RTitle)wpTextbox1NewValue=wpTextbox1NewValue.replace(NumEpisodesM[1]+NumEpisodesM[3],NumEpisodesM[1]+NumEpisodes);// Season pageelsewpTextbox1NewValue=wpTextbox1NewValue.replace(NumEpisodesM[1]+NumEpisodesM[3],NumEpisodesM[1]+EpisodeNumber);// Main page}// Update Template:Aired_episodes if it existsif(OriginalAirDate)wpTextbox1NewValue=wpTextbox1NewValue.replace(/(\{\{Aired episodes\|)((\d*)\|(\d*)\|(\d*))/,"$1"+OriginalAirDate);if(EpisodeNumber)wpTextbox1NewValue=wpTextbox1NewValue.replace(/((\{\{Aired episodes\|)(.*)(\|\s*num\s*=))(\d+)/,"$1"+EpisodeNumber);wpTextbox1NewValue=wpTextbox1NewValue.replace(/((\{\{Aired episodes\|)(.*)(\|\s*finished\s*=))([\d\.]+)/,"$2$3");// Reset textbox with new versionwpTextbox1.value=wpTextbox1NewValue;});});},900);});