LLWiki正在建设中,欢迎加入我们!
MediaWiki:Gadget-translation.js
跳转到导航
跳转到搜索
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
"use strict"; const dict = [{reg:'南小[鸟鳥]', hans:'南琴梨'}, {reg:'妮可妮可妮', hans:'微笑小香香'}, {reg:'妮可', hans:'日香'}], reg = new RegExp( dict.map(function(ele) { return ele.reg; }).join('|') ), replace = function(string) { dict.forEach(function(ele) { string = string.replace(new RegExp(dict.reg, 'g'), wgUCS(dict.hans, dict.hant || dict.hans)); }); return string; }, searchReplace = function(ele) { const text = ele.innerHTML || ele.textContent; if (ele.title && reg.test(ele.title)) { ele.title = replace(ele.title); } if (!reg.test(text)) { return; } if (ele.nodeType == 3) { ele.textContent = replace(text); } else { $(ele).contents().each(function() { searchReplace(this); }); } }; mw.hook( 'wikipage.content' ).add(function($content) { $content.find( '.mw-parser-output' ).filter(function() { return reg.test(this.innerHTML); }) .each(function() { console.log('Hook: wikipage.content,开始替换译名'); searchReplace(this); }); }); $(function() { const heading = $('h1'); if (reg.test( heading.text() )) { searchReplace(heading[0]); } });