User:Juno719/script/MOSHEADERS omitting.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 code will be executed when previewing this page.
Documentation for this user script can be added at User:Juno719/script/MOSHEADERS omitting.
mw.loader.using('mediawiki.util', function () {
const action = mw.config.get('wgAction');
const ns = mw.config.get('wgNamespaceNumber');
if (!['edit', 'submit'].includes(action)) return;
if (![0, 118].includes(ns)) return;
function runHeaderFix() {
const textarea = document.getElementById('wpTextbox1');
if (!textarea) return;
let text = textarea.value;
// Chart performance captions
text = text.replace(/^\s*\|\+.*weekly chart performance.*$/gim,'|+ {{Screen reader-only|Weekly chart performance}}\n');
text = text.replace(/^\s*\|\+.*weekly charts for.*$/gim,'|+ {{Screen reader-only|Weekly chart performance}}\n');
text = text.replace(/^\s*\|\+.*monthly chart performance.*$/gim,'|+ {{Screen reader-only|Monthly chart performance}}\n');
text = text.replace(/^\s*\|\+.*year-end chart performance.*$/gim,'|+ {{Screen reader-only|Year-end chart performance}}\n');
text = text.replace(/^\s*\|\+.*decade-end chart performance.*$/gim,'|+ {{Screen reader-only|Decade-end chart performance}}\n');
text = text.replace(/^\s*\|\+.*all-time chart performance.*$/gim,'|+ {{Screen reader-only|All-time chart performance}}\n');
// Release captions
text = text.replace(/\|\+\s*Release history for\s+"[^"]+"\s*/gi, '|+ {{Screen reader-only|Release history}}\n');
text = text.replace(/\|\+\s*Release dates and formats for\s+"[^"]+"\s*/gi, '|+ {{Screen reader-only|Release dates and formats}}\n');
text = text.replace(/\|\+\s*Release history for\s+''[^'']+''\s*/gi, '|+ {{Screen reader-only|Release history}}\n');
text = text.replace(/\|\+\s*Release dates and formats for\s+''[^'']+''\s*/gi, '|+ {{Screen reader-only|Release dates and formats}}\n');
// Track listing headers
text = text.replace(/\|\+\s*''[^']+''\s*track listing\s*/gi, '| headline = {{Screen reader-only|Track listing}}\n');
// Certification Table Top captions
text = text.replace(/(\{\{Certification Table Top\|caption=)Certifications for\s+"[^"]+"(\}\})/gi, '$1{{Screen reader-only|Certifications}}$2');
text = text.replace(/(\{\{Certification Table Top\|caption=)Certifications and sales for\s+"[^"]+"(\}\})/gi, '$1{{Screen reader-only|Certifications and sales}}$2');
text = text.replace(/(\{\{Certification Table Top\|caption=)Certifications for\s+''[^'']+''(\}\})/gi, '$1{{Screen reader-only|Certifications}}$2');
text = text.replace(/(\{\{Certification Table Top\|caption=)Certifications and sales for\s+''[^'']+''(\}\})/gi, '$1{{Screen reader-only|Certifications and sales}}$2');
// Discography captions
text = text.replace(/\|\+\s*List of studio albums,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of studio albums}}\n');
text = text.replace(/\|\+\s*List of extended plays,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of extended plays}}\n');
text = text.replace(/\|\+\s*List of single albums,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of single albums}}\n');
text = text.replace(/^\s*\|\+\s*List of reissue[^\n]*/gim,'|+ {{Screen reader-only|List of reissues}}\n');
text = text.replace(/\|\+\s*List of compilation albums,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of compilation albums}}\n');
text = text.replace(/\|\+\s*List of live albums,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of live albums}}\n');
text = text.replace(/^\s*\|\+\s*List of singles[^\n]*/gim,'|+ {{Screen reader-only|List of singles}}\n');
text = text.replace(/^\s*\|\+\s*List of collaboration[^\n]*/gim,'|+ {{Screen reader-only|List of collaborations}}\n');
text = text.replace(/^\s*\|\+\s*List of songs[^\n]*/gim,'|+ {{Screen reader-only|List of songs}}\n');
text = text.replace(/^\s*\|\+\s*List of music videos[^\n]*/gim,'|+ {{Screen reader-only|List of music videos}}\n');
text = text.replace(/\|\+\s*List of Korean singles,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of Korean singles}}\n');
text = text.replace(/\|\+\s*List of Japanese singles,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of Japanese singles}}\n');
text = text.replace(/\|\+\s*List of English singles,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of English singles}}\n');
text = text.replace(/\|\+\s*List of Korean extended plays,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of Korean extended plays}}\n');
text = text.replace(/\|\+\s*List of Japanese extended plays,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of Japanese extended plays}}\n');
text = text.replace(/\|\+\s*List of promotional singles,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of promotional singles}}\n');
text = text.replace(/\|\+\s*List of soundtrack appearances,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of soundtrack appearances}}\n');
text = text.replace(/\|\+\s*List of other charted songs,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of other charted songs}}\n');
text = text.replace(/\|\+\s*List of other appearances,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of other appearances}}\n');
// Awards
text = text.replace(/\|\+\s*Name of the award ceremony,\s*[^\n]*/gi,'|+ {{Screen reader-only|List of awards and nominations}}\n');
text = text.replace(/\|\+\s*Name of publisher,\s*[^\n]*/gi,'|+ {{Screen reader-only|Listicles}}\n');
textarea.value = text;
// Auto-fill edit summary if empty
const summary = document.getElementById('wpSummary');
if (summary && summary.value.trim() === '') {
summary.value = 'Omit redundant table captions per [[MOS:HEADERS]] using [[User:Juno719/script/MOSHEADERS omitting.js|script]]';
}
// Mark the edit as minor
const minorEditCheckbox = document.getElementById('wpMinoredit');
if (minorEditCheckbox) {
minorEditCheckbox.checked = true;
}
}
// Add "Omit headers" button to the right-side Tools section
function addOmitHeadersButton() {
const toolbox = document.getElementById('p-tb');
if (!toolbox) return;
if (document.getElementById('p-omitheaders')) return;
mw.util.addPortletLink(
'p-tb',
'#',
'Omit headers',
'p-omitheaders',
'Run header cleanup script'
);
document.getElementById('p-omitheaders').addEventListener('click', function (e) {
e.preventDefault();
runHeaderFix();
});
}
mw.hook('wikipage.editform').add(addOmitHeadersButton);
});