User:Alex 21/script-updateepisodes.js
Appearance
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. |
![]() | This user script seems to have a documentation page at User:Alex 21/script-updateepisodes. |
$(function($) {
var portletlink = mw.util.addPortletLink('p-tb', '#', 'Remove redlinks');
$(portletlink).click( function(e) {
e.preventDefault();
// Textbox contents
var wpTextbox1 = document.getElementById('wpTextbox1');
var s = wpTextbox1.value.split("\n");
// Declare variables
var NumEpisodes = false; var RTitle = false;
var OriginalAirDate = false; var EpisodeNumber = false;
// Go though contents one line at a time
for (var i = 0; i < s.length; i++) {
// Update num_episodes in {{Infobox television}}, if it exists
var NumEpisodesM = s[i].match(/(\s*\|\s*num_episodes\s*=\s*(<onlyinclude>)?)(\d*)(.*)/);
if (NumEpisodesM) {
NumEpisodes = parseInt(NumEpisodesM[3])+1;
s[i] = s[i].replace(NumEpisodesM[1]+NumEpisodesM[3], NumEpisodesM[1]+NumEpisodes);
}
// Check if first appearance of RTitle is found
if (!RTitle) {
// If line contains RTitle, set to <<RTitle>> (will be remove later).
var RTitleM = s[i].match(/(\s*\|\s*RTitle\s*=\s*)(.*)/);
if (RTitleM) {
s[i] = '<<RTitle>>';
RTitle = true;
}
// Catch episode number to add to summary
var EpisodeNumberM = s[i].match(/(\s*\|\s*EpisodeNumber\s*=\s*)(.*)/);
if (EpisodeNumberM) EpisodeNumber = EpisodeNumberM[2];
} else if (!OriginalAirDate) {
// If RTitle is found but OriginalAirDate not set, find the next occurrence of OriginalAirDate to update {{Aired episodes}}, if it exists
var OriginalAirDateM = s[i].match(/(\s*\|\s*OriginalAirDate\s*=\s*)\{\{[s|S]tart date\|([^\}]*)\}\}/);
if (OriginalAirDateM) OriginalAirDate = OriginalAirDateM[2];
}
}
// Update summary
document.getElementById('wpSummary').value += "Update; aired ["+(EpisodeNumber?EpisodeNumber:NumEpisodes)+"]";
// Concatenate textbox values again, but without <<RTitle>>
var wpTextbox1NewValue = '';
for (i = 0; i < s.length; i++) if (s[i] != '<<RTitle>>') wpTextbox1NewValue += s[i]+"\n";
// Update {{Aired episodes}}, if it exists
wpTextbox1NewValue = wpTextbox1NewValue.replace(/(\{\{Aired episodes\|)((\d*)\|(\d*)\|(\d*))/, "$1"+OriginalAirDate);
// Reset textbox with new version
wpTextbox1.value = wpTextbox1NewValue;
});
});