MediaWiki:Gadget-SimplifyRefNotesTag.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
$(function() {
// 本功能將數字按順序轉為英文字母
var num2alp = function(n) {
var chk = parseInt(n);
if (isNaN(chk)) return null;
var digit = [];
var result = '';
while (chk > 0) {
digit.unshift(chk % 26);
chk = Math.floor(chk / 26);
}
var j = digit.length;
while (j --> 0) {
if (digit[j] <= 0) {
if (j > 0) {
digit[j] += 26;
digit[j - 1] -= 1;
} else {
break;
}
}
result = String.fromCharCode('a'.charCodeAt(0) + (digit[j] - 1)) + result;
}
return result;
}
// 功能結束
// 將各上標簡化開始
var sups = document.getElementsByTagName('sup');
var i = sups.length, sup_textnode, temp, num, j;
while (i --> 0) {
if (sups[i].className == 'reference' && ('' + sups[i].id).indexOf('cite_ref') == 0)
if (sups[i].childNodes.length == 1)
if (('' + sups[i].childNodes[0].tagName).toLowerCase() == 'a')
if (sups[i].childNodes[0].childNodes.length == 3)
if (('' + sups[i].childNodes[0].childNodes[0].childNodes[0].nodeName + sups[i].childNodes[0].childNodes[1].nodeName) == '#text#text')
if (sups[i].childNodes[0].childNodes[0].childNodes[0].nodeValue.indexOf('[') == 0 || !isNaN(sups[i].childNodes[0].childNodes[0].childNodes[0].nodeValue.charAt(0)))
if ((sups[i].childNodes[0].childNodes[1].nodeValue+sups[i].group_name).match(/[參参註注]/)) {
sup_textnode = sups[i].childNodes[0].childNodes[1];
if (sups[i].parentNode.classList.contains('refTag-cite_ref-sup')) {
sup_textnode.nodeValue = sup_textnode.nodeValue.replace(/[參参] /, '');
} else if (sups[i].parentNode.classList.contains('noteTag-cite_ref-sup')) {
temp = sup_textnode.nodeValue.split(/[註注] /);
j = temp[temp.length - 1].length;
while (j --> 0) {
if (!isNaN(temp[temp.length - 1].charAt(j))) break;
}
num = parseInt(temp[temp.length - 1].substring(0, j + 1));
temp[temp.length - 1] = num2alp(num) + temp[temp.length - 1].substring(j + 1);
sup_textnode.nodeValue=temp.join('');
}
}
}
// 將各上標簡化結束
// 將備註列表項目用英文字母排序
if (document.getElementById('references-NoteFoot')) {
var ol = document.getElementById('references-NoteFoot').getElementsByTagName('ol');
for (i = ol.length; i --> 0;) {
if (ol[i].className == 'references') ol[i].type = 'a';
}
}
});