User:Artoria2e5/gadget-simp-refnote-tags.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/* Modified from MediaWiki:Gadget-SimplifyRefNotesTag.js
* Version 0: Code Cleanup
*/
window.simplifyRefNotesTag = function () {
// 数字转换为 26 进制字母
// "1" => "a"
// "-1" => "-b"
// "0" => "-a"
// "28" => "ab".
function dec2alpha (n) {
var n_int = parseInt(n, 10);
if (isNaN(n_int))
return null;
var neg_n = (n_int <= 0);
n_int = neg_n ? -n_int : n_int - 1;
var a = 'a'.charCodeAt(0);
// 280 = 10 * 26 + 20 => [10, 20]
var digits_26 = [];
if (n_int === 0)
digits_26 = [a];
else
while (n_int > 0) {
digits_26.unshift(n_int % 26 + a);
n_int = (n_int / 26) | 0;
}
var sign = neg_n ? '-' : '';
return sign + String.fromCharCode.apply(String, digits_26);
}
// 簡化各上標
$('sup.reference[id^="cite_ref"] > a:only-child').filter(function (idx, a) {
// 有且仅有一个文字或注释节点
if (a.childNodes.length == 1 && a.childNodes.length == 1)
// 仅取匹配的节点,且必须为文字
if (a.childNodes[0].nodeName == '#text' && !!(a.childNodes[0].nodeValue.match(/^\[[參参註注]/)))
return true;
return false;
}).each(function (idx, a) {
var topSpan = a.parentNode.parentNode; // a -> sup -> span
var txt = a.childNodes[0];
if (topSpan.id == 'refTag-cite_ref-sup') {
// reference
txt.nodeValue = txt.nodeValue.replace(/[參参]\ /g, '');
} else if (topSpan.id == 'noteTag-cite_ref-sup') {
var dec = txt.nodeValue.match(/^\[[註注]\ (\d+)\]/)[1];
if (dec) {
var alpha = dec2alpha(dec);
if (alpha) {
txt.nodeValue = '[' + alpha + ']';
}
}
}
});
// 將備註列表項目用英文字母排序
$('#references-NoteFoot ol').each(function (idx, ol) {
if (ol.className == 'references')
ol.type = 'a';
});
// self-destroy (run-once)
window.simplifyRefNotesTag = function () {};
};
window.load_Merge_Simplify = function () {
if (typeof window.simplifyRefNotesTag == 'function')
window.simplifyRefNotesTag();
if (typeof window.mergeRefBracket == 'function')
window.mergeRefBracket();
// self-destruct (run-once)
window.load_Merge_Simplify = function () {};
};
$(function () {
window.load_Merge_Simplify();
});