User:Alex 21/script-formatdates.js
$(function($) {
setTimeout(function() {
$.when( mw.loader.using( ['mediawiki.util']), $.ready ).then(function() {
var portletlink = mw.util.addPortletLink('p-tv', '#', 'Format airdates');
$(portletlink).click( function(e) {
e.preventDefault();
// Textbox value
var wpTextbox1 = document.getElementById('wpTextbox1');
var wpTextbox1_V = wpTextbox1.value.split("\n");
// Df parameter, update parameters, months and regex used throughout
var df = false;
var AltDate_U = false;
var OriginalAirDate_U = false;
var MDY = /(\|\s*(OriginalAirDate)_?\d?\s*=\s*)(([A-Z][a-z]*)\s*)?((\d{1,2}),\s*)?(\d{4})/;
var DMY = /(\|\s*(OriginalAirDate)_?\d?\s*=\s*)((\d{1,2})\s*)?(([A-Z][a-z]*)\s*)?(\d{4})/;
var ad_reg = /(\|\s*(AltDate|FirstEngAirDate)_?\d?\s*=\s*)\{\{[Ss]tart\sdate\|(\d+)\|0?(\d+)\|0?(\d+)([^\}]*)\}\}/;
var months = ['','January','February','March','April','May','June','July','August','September','October','November','December'];
var months_short = ['','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
// Iterate through each line of the textbox
for (var i = 0; i < wpTextbox1_V.length; i++) {
var line = wpTextbox1_V[i];
// Check for df and to see if the line actually needs changing at all
if (line.match(/\|\s*df\s*\=\s*([^\s]+)/)) df = true;
if (line.toLowerCase().indexOf('start date') > -1 && line.indexOf('OriginalAirDate') > -1) continue;
if (line.toLowerCase().indexOf('start date') == -1 && (line.indexOf('AltDate') > -1 || line.indexOf('FirstEngAirDate') > -1)) continue;
if ((line.indexOf('OriginalAirDate') == -1 && line.indexOf('AltDate') == -1 && line.indexOf('FirstEngAirDate') == -1) || line.indexOf('TableTBA') > -1) continue;
// Replace OriginalAirDate
var line_old = line;
if (line.match(MDY)) {
line = line.replace(MDY, "$1{{Start date|$7|$4|$6"+(df?"|df=y":"")+"}}");
} else {
line = line.replace(DMY, "$1{{Start date|$7|$6|$4|df=y}}");
}
if (line_old == line && line.indexOf("{{Start date") == -1) {
line = line.replace(/(\|\s*(OriginalAirDate)\s*=\s*)(.*)/, "$1{{Start date|$3}}");
} else {
OriginalAirDate_U = true;
}
// Months to numbers
for (var j = 1; j < months.length; j++) {
var re = new RegExp("\\|"+months[j]+"\\|","g");
line = line.replace(re, "|"+j+"|");
re = new RegExp("\\|"+months_short[j]+"\\|","g");
line = line.replace(re, "|"+j+"|");
}
// Replace AltDate and FirstEngAirDate
line_old = line;
if (df) {
line = line.replace(ad_reg, "$1$5 <<$4>> $3");
} else {
line = line.replace(ad_reg, "$1<<$4>> $5, $3");
}
if (line_old != line) {
AltDate_U = true;
}
// Numbers to months
for (j = 1; j < months.length; j++) {
line = line.replace("<<"+j+">>", months[j]);
}
// Replace any occurences of {{Start date|}} and similar
line = line.replace(/\|\|+/g,'|').replace("|}}","}}").replace("{{Start date}}","");
wpTextbox1_V[i] = line;
}
// Save content
var wpTextbox1NewValue = '';
for (i = 0; i < wpTextbox1_V.length; i++) wpTextbox1NewValue += wpTextbox1_V[i]+"\n";
wpTextbox1.value = wpTextbox1NewValue;
document.getElementById('wpSummary').value += "Update OriginalAirDate and/or AltDate to use correct formats per template documentation via [[User:Alex 21/script-formatdates|script]].";
});
});
},200);
});
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.