User:23W/DecadesInTelevision.js

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.
if (wgTitle.search(/\d+s in .*? television/i) != -1) {
    function fixCategories() {
        var textBox = document.getElementById('wpTextbox1').value;
        
        var regExp = /\[\[Category:Years in (.*?) television/i;
        var country = textBox.match(regExp)[1];
        
        replaceTextBox = textBox.replace(/\[\[Category:Years in (.*?) television(\|.*?)?\]\]/gi,"\x5B\x5BCategory:Decades in $1 television\x5D\x5D")
                                .replace(/\[\[Category:(\d+s) in television(\|.*?)?\]\]/gi,"\x5B\x5BCategory:$1 in television\|" + country + "\x5D\x5D")
                                .replace(/\[\[Category:(\d+s) in (?!television)(.*?)(\|.*?)?\]\]/gi,"\x5B\x5BCategory:$1 in $2|Television\x5D\x5D")
                                .replace(/\[\[Category:Television in .*?\]\]\n/gi,"")
                                .replace(/\{\{CatRel/gi,"\x7B\x7BCategory see also")
                                .replace(/\{\{Cat(egory see also|Pair)\|(.*?\|.*?\}\})/gi,"\x7B\x7BCategory pair|$2");
        document.getElementById('wpTextbox1').value = replaceTextBox;
        
        document.getElementById('wpSummary').value = "\x5B\x5BCategory:Years in " + country + " television\x5D\x5D to \x5B\x5BCategory:Decades in " + country + " television\x5D\x5D, fixing keys (\x5B\x5Ben:User:23W/DecadesInTelevision.js|script-assisted\x5D\x5D)"
    }
    window.onload = fixCategories;
}