User:Sl/wiki/tradsim.js

出自維基百科,自由嘅百科全書
注意:儲存之後,你可能要兜過你嘅瀏覽器快取至睇到更改。Internet Explorer: 撳住Ctrl掣再撳重新整理掣。 Firefox: 撳住Shift掣再撳重新載入(又或者撳Ctrl-Shift-R)。 Google Chrome同埋Safari用戶就噉撳個重載掣。
 document.write('<script type="text/javascript" src="'
 + 'http://zh-yue.wikipedia.org/w/index.php?title=User:Sl/wiki/sim2trad.js'
 + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 document.write('<script type="text/javascript" src="'
 + 'http://zh-yue.wikipedia.org/w/index.php?title=User:Sl/wiki/trad2sim.js'
 + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 
 origStr = "";
 function supplane(num) {
 	if(num >= 65536) num -= 65536;
 	var num1 = Math.floor(num / 1024) + 55296;
 	var num2 = num % 1024 + 56320;
 	return String.fromCharCode(num1) + String.fromCharCode(num2);
 }
 function converts2t() {
 	var content = document.getElementById("bodyContent").innerHTML;
 	var newStr = "";
 	if(origStr.length > 0)
 		content = origStr;
 	if(content.length == 0) {
 		newStr = default_text;
 	}
 	else for(var i = 0; i < content.length; i++) {
 		var unicode = content.charCodeAt(i);
 		if(unicode >= 55296 && unicode <= 56319) {
 			var unicode1 = content.charCodeAt(++i);
 			if(unicode1 >= 56320 && unicode1 <= 57343) {
 				unicode = 1024 * unicode - 56557568 + unicode1 - 56320;
 			}
 		}
 		var unicode2 = table2t[unicode];
 		if(unicode2 > 65535) {
 			newStr += supplane(unicode2);
 		}
 		else if(unicode > 65535 && !unicode2) {
 			newStr += supplane(unicode);
 		}
 		else {
 			newStr += ( unicode2 ) ? String.fromCharCode(unicode2) : String.fromCharCode(unicode);
 		}
 	}
 	origStr = content;
 	document.getElementById("bodyContent").innerHTML = newStr;
 }
 function convertt2s() {
 	var content = document.getElementById("bodyContent").innerHTML;
 	var newStr = "";
 	if(origStr.length > 0)
 		content = origStr;
 	if(content.length == 0) {
 		newStr = default_text;
 	}
 	else for(var i = 0; i < content.length; i++) {
 		var unicode = content.charCodeAt(i);
 		if(unicode >= 55296 && unicode <= 56319) {
 			var unicode1 = content.charCodeAt(++i);
 			if(unicode1 >= 56320 && unicode1 <= 57343) {
 				unicode = 1024 * unicode - 56557568 + unicode1 - 56320;
 			}
 		}
 		var unicode2 = table2s[unicode];
 		if(unicode2 > 65535) {
 			newStr += supplane(unicode2);
 		}
 		else if(unicode > 65535 && !unicode2) {
 			newStr += supplane(unicode);
 		}
 		else {
 			newStr += ( unicode2 ) ? String.fromCharCode(unicode2) : String.fromCharCode(unicode);
 		}
 	}
 	origStr = content;
 	document.getElementById("bodyContent").innerHTML = newStr;
 }
 function convertorig() {
 	if(origStr.length > 0)
 		document.getElementById("bodyContent").innerHTML = origStr;
 }
 if(location.href.indexOf("action=edit") == -1 && location.href.indexOf("action=submit") == -1)
 	document.write('<div style=\"position:relative;top:2em;text-align:right;margin-right:1em;white-space:nowrap;\"><a href=\"javascript:convertorig();\" style=\"font-size:133%;\">不轉換<\/a> <a href=\"javascript:converts2t();\" style=\"font-size:133%;\">轉繁體<\/a> <a href=\"javascript:convertt2s();\" style=\"font-size:133%;\">转简体<\/a><\/div>');