跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
分类索引
最近更改
随便看看
灵兰秘典
捐助本站
帮助
帮助
联系我们
关于本站
MediaWiki帮助
中医百科
搜索
搜索
外观
登录
个人工具
登录
查看“︁MediaWiki:Gadget-SimplifyRefNotesTag.js”︁的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
清除缓存
常规
链入页面
相关更改
特殊页面
页面信息
Cargo数据
短URL
外观
移至侧栏
隐藏
←
MediaWiki:Gadget-SimplifyRefNotesTag.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
window.simplifyRefNotesTag = function() { var i, j; /** * 本功能将数字按顺序转为英文字母(如 1->a,26->z,27->aa) * @param {number} n - 需转换的数字(非负整数) * @returns {string|null} 转换后的英文字母组合,输入非数字则返回null */ function num2alp(n) { var chk = parseInt(n); if (isNaN(chk)) return null; var digit = new Array(); var result = ""; while (chk > 0) { digit.unshift(chk % 26); chk = Math.floor(chk / 26); } for (var j = digit.length; 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 sup_textnode; var temp, num, alp; // 从后往前遍历所有sup标签(避免DOM操作影响遍历顺序) for (i = sups.length; i-- > 0;) { // 筛选符合条件的引用上标:class为reference、id以cite_ref开头、结构为sup>a>文本 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 == 1) if (("" + sups[i].childNodes[0].childNodes[0].nodeName) == "#text") // 文本以[开头或首个字符为数字,且包含“参”或“注”字样(匹配简繁体) if (sups[i].childNodes[0].childNodes[0].nodeValue.indexOf("[") == 0 || !isNaN(sups[i].childNodes[0].childNodes[0].nodeValue.charAt(0))) if ((sups[i].childNodes[0].childNodes[0].nodeValue + sups[i].group_name).match(/[參参註注]/g)) { sup_textnode = sups[i].childNodes[0].childNodes[0]; // 处理“参”类型引用(父容器id为refTag-cite_ref-sup) if (sups[i].parentNode.id == "refTag-cite_ref-sup") { // 分割并移除“参 ”字样(匹配简繁体) temp = sup_textnode.nodeValue.split(/[參参] /g); sup_textnode.nodeValue = temp.join(""); } // 处理“注”类型引用(父容器id为noteTag-cite_ref-sup) else if (sups[i].parentNode.id == "noteTag-cite_ref-sup") { // 分割“注 ”字样(匹配简繁体) temp = sup_textnode.nodeValue.split(/[註注] /g); // 提取最后一段文本中的数字部分 for (j = temp[temp.length - 1].length; 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(""); } } } // 上标简化处理结束 // 将备注列表项目用英文字母排序(type="a") 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"; } } // 函数自销毁,避免重复执行 window.simplifyRefNotesTag = function() {}; }; window.load_Merge_Simplify = function() { // 若存在mergeRefBracket函数则执行(外部依赖函数) if (("" + (typeof window.mergeRefBracket)).toLowerCase() == "function") window.mergeRefBracket(); // 执行上标简化函数 if (("" + (typeof window.simplifyRefNotesTag)).toLowerCase() == "function") window.simplifyRefNotesTag(); // 函数自销毁,避免重复执行 window.load_Merge_Simplify = function() {}; }; // 页面DOM加载完成后执行初始化函数(jQuery语法) $(function() { window.load_Merge_Simplify(); });
返回
MediaWiki:Gadget-SimplifyRefNotesTag.js
。