MediaWiki:Gadget-AutoOldStyleVi.js
Cache: Sau khi lưu biểu mẫu này, phải xóa bộ nhớ đệm (cache) của trình duyệt để những thay đổi hiện ra:
Firefox, Chrome, Safari, Opera — Shift Internet Explorer — Ctrl Konqueror —
Nếu bạn viết mã JavaScript, chú ý đọc hướng dẫn để tránh mâu thuẫn với mã mặc định của mạng.
// **********************************************************************
// ** ***WARNING GLOBAL GADGET FILE*** **
// ** changes to this file affect many users. **
// ** please discuss on the talk page before editing **
// ** **
// **********************************************************************
// Automatically convert Vietnamese new-styled typing (oà, uý) to old-styled typing (òa, úy)
// Authors: Kimkha, Vinhtantran, Magnus Manske
$(function () {
if (mw.config.get("wgAction") !== "edit" && mw.config.get("wgAction") !== "submit") {
return;
}
var ns = mw.config.get("wgNamespaceNumber");
var check = mw.html.element("input", {
id: "wsAutoOldStyle",
type: "checkbox",
checked: (ns === 0 || ns === 100 || ns === 102 || ns === 104 ||
ns === 106)
});
var label = mw.html.element("label", {
id: "ws-editpage-auto-old-style",
"for": "wsAutoOldStyle",
title: "Tự động đổi từ cách bỏ dấu tiếng Việt kiểu mới sang kiểu cũ khi lưu trang này"
}, "Sửa dấu theo kiểu cũ");
$("#editform .editCheckboxes").append($(check)).append($(label));
$("#editform").submit(function (evt) {
if (!$("#wsAutoOldStyle").prop("checked")) return;
$("#wpTextbox1").val(function (i, ot) {
return get_linkfixr_text(ot);
});
});
});
function get_linkfixr_text ( ot ) {
var t = ot ;
var ct ;
do {
ct = t ;
t = t.replace(/oà(?=\W|$)/g, "òa");
t = t.replace(/oá(?=\W|$)/g, "óa");
t = t.replace(/oả(?=\W|$)/g, "ỏa");
t = t.replace(/oã(?=\W|$)/g, "õa");
t = t.replace(/oạ(?=\W|$)/g, "ọa");
t = t.replace(/oè(?=\W|$)/g, "òe");
t = t.replace(/oé(?=\W|$)/g, "óe");
t = t.replace(/oẻ(?=\W|$)/g, "ỏe");
t = t.replace(/oẽ(?=\W|$)/g, "õe");
t = t.replace(/oẹ(?=\W|$)/g, "ọe");
t = t.replace(/(^|[^Qq])uỳ(?=\W|$)/g, "$1ùy");
t = t.replace(/(^|[^Qq])uý(?=\W|$)/g, "$1úy");
t = t.replace(/(^|[^Qq])uỷ(?=\W|$)/g, "$1ủy");
t = t.replace(/(^|[^Qq])uỹ(?=\W|$)/g, "$1ũy");
t = t.replace(/(^|[^Qq])uỵ(?=\W|$)/g, "$1ụy");
} while ( ct != t ) ;
return t ;
}