User:Crestfalling/ScriptTitle.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.
This user script seems to have a documentation page at User:Crestfalling/ScriptTitle.
function autoEdScriptTitle(str) {
//Check for Japanese text using kana
str = str.replace(/(\|\s*)title(\s*)=(\s*)([^|]*?[\u3041-\u3096\u30A1-\u30FA]+[^|]*?([|]|[^!=]\}))/g, '$1script-title$2=$3ja:$4');
//Check for Korean text using hangul
str = str.replace(/(\|\s*)title(\s*)=(\s*)([^|]*?[\uAC00-\uD7A3]+[^|]*?([|]|[^!=]\}))/g, '$1script-title$2=$3ko:$4');
//Check for likely Chinese text using at least six hanzi in a row
str = str.replace(/(\|\s*)title(\s*)=(\s*)([^|]*?[\u4E00-\u9FFF]{6}[^|]*?([|]|[^!=]\}))/g, '$1script-title$2=$3zh:$4');
//Check for provisionally Chinese text using any Han characters, use placeholder lang code
str = str.replace(/(\|\s*)title(\s*)=(\s*)([^|]*?[\u4E00-\u9FFF]+[^|]*?([|]|[^!=]\}))/g, '$1script-title$2=$3PH:$4');
//Correct any text wrongly labeled
str = str.replace(/script-title(\s*)=(\s*)(ja|ko|zh|PH)(([^}]|\{\{=\}\}|\{\{!\}\}|\{\{ill[^}]*?\}\})*lang(uage)?=)(ja|ko|zh|Ja|Ko|Ch)/g, 'script-title$1=$2$7$4$7');
str = str.replace(/(lang(uage)?=(ja|ko|zh|Ja|Ko|Ch)([^{]|\{\{=\}\}|\{\{!\}\}|\{\{ill[^}]*?\}\})*)script-title(\s*)=(\s*)(ja|ko|zh|PH)/g, '$1script-title$5=$6$3');
//Normalize any placeholder lang codes
str = str.replace(/(script-title\s*=\s*)Ja/g, '$1ja');
str = str.replace(/(script-title\s*=\s*)Ko/g, '$1ko');
str = str.replace(/(script-title\s*=\s*)Ch/g, '$1zh');
//If hanzi/kanji/hanja-only text can't be determined, default back to title= to prevent incorrect labeling
str = str.replace(/script-title(\s*)=(\s*)PH:/g, 'title$1=$2');
return str;
}