Iōng-chiá:A-lú-mih/lomajiToHanji.js
Chù-ì: Pó-chûn liáu-āu, tio̍h ē-kì leh kā liû-lám-khì ê cache piàⁿ tiāu chiah khoàⁿ-ē-tio̍h kái-piàn: Mozilla: chhi̍h reload/têng-sin chài-ji̍p (a̍h-sī Ctrl-R), IE kap Opera: Ctrl-F5, Safari: Cmd-R, Konqueror Ctrl-R.
//https://www.mediawiki.org/wiki/Manual:Interface/JavaScript
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
};
var wordDictionary = {
"bu̍t-lí-ha̍k": "物理學",
"tāi-chū-jiân": "大自然",
"kho-ha̍k-ka": "科學家",
"bu̍t-lí": "物理",
"chū-jiân": "自然",
"gí-giân": "語言",
"gián-kiù": "研究",
"hoan-gêng": "歡迎",
"hōng-tê": "奉茶",
"kho-ha̍k": "科學",
"pán-pún": "版本",
"thâu-ia̍h": "頭頁",
"ú-tiū": "宇宙"
};
var originalContent = $("#content").html();
var wordReplace = function(LHSwitch){
for (var word in wordDictionary) {
var replacedBy;
if (LHSwitch == "switchToHanji") {
replacedBy = wordDictionary[word];
$("#content").html( $("#content").html().replace(new RegExp(word, "ig"), replacedBy) );
$('#loHanSwitch').children().children().attr("data-switch", "switchToLomaji").text("Chóan tńg POJ");
}
if (LHSwitch == "switchToLomaji") {
$("#content").html(originalContent);
$('#loHanSwitch').children().children().attr("data-switch", "switchToHanji").text("顯示漢字");
}
}
};
$("#p-namespaces ul").append("<li id='loHanSwitch'><span><a data-switch='switchToHanji'>顯示漢字</a></span></li>");
$('#loHanSwitch').children().children().click(function(){
var loHanSelect = $(this).attr("data-switch");
wordReplace(loHanSelect);
}).change();