跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
社群首页
帮助
希顶相关网站
希顶社区官网
希服维基
Nyoeghau翻译器
〇改希顶转写器
语圈山海经
搜索
搜索
外观
创建账号
登录
个人工具
创建账号
登录
查看“︁MediaWiki:Gadget-Xdi8CharInsert.js”︁的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
特殊页面
页面信息
外观
移至侧栏
隐藏
←
MediaWiki:Gadget-Xdi8CharInsert.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于这些用户组的用户执行:
用户
、storagereadable
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
/*************编辑器注入*************/ var xdi8Letters = [ //希顶字母表数据 //注意字母表数据暂使用未经调整的编码系统 [ ["!`", "b", "p", "m", "w", "j", "q", "x", "y", "n", "z", "D", "s", "r", "H", "N", "l", "d", "t", "g", "k", "h", "4", "5", "v", "F", "7", "B", "c", "f", "u", "a", "o", "e", "E", "A", "Y", "L", "6", "2", "T", "8", "3", "V", "1", "i"], ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""] ], [ ["⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧", "⇧"], ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""] ], [ ["⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩", "⇩"], ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""] ] ]; function translatePua(str) { //将使用聊天字母的文本转换成PUA代码 for(var i_ in xdi8Letters) { var i = xdi8Letters[i_]; for(var j_ in i[0]) { var j = i[0][j_]; while(str != str.replace(j, i[1][i[0].indexOf(j)])) { str = str.replace(j, i[1][i[0].indexOf(j)]) } } } return str; } function injectBotton() { //注入希顶输入按钮于特殊字符输入区 function findBotton() { if(document.getElementsByTagName("div")) { for(var childs_ in document.getElementsByTagName("div")) { var childs = document.getElementsByTagName("div")[childs_]; var attrs = childs.attributes; if(attrs && (attrs["rel"] && attrs["rel"].value == "latin") && (attrs["class"] && attrs["class"].value != "toolbar section section-main") && (attrs["class"] && attrs["class"].value != "page page-latin page-characters")) { return childs; } } } return null; } if(findBotton()) { findBotton() .setAttribute('class', ''); var xdi8Bottom = document.createElement('div'); xdi8Bottom.setAttribute('rel', 'xdi8'); xdi8Bottom.setAttribute('id', 'xdi8in'); xdi8Bottom.onclick = function() { //取自mediawiki内部脚本 var section; $(this) .parent() .parent() .find('.page') .hide(); $(this) .parent() .parent() .find('.page-' + $(this) .attr('rel')) .show() .trigger('loadPage'); $(this) .siblings() .removeClass('current'); $(this) .addClass('current'); section = $(this) .parent() .parent() .attr('rel'); $.cookie('wikiEditor-0-booklet-' + section + '-page', $(this) .attr('rel'), { expires: 30, path: '/' }); event.preventDefault(); } xdi8Bottom.innerText = "希顶字母"; findBotton() .parentNode.insertBefore(xdi8Bottom, findBotton()); return true; } else { return false; } } function insertText(obj, str) { //向texteara插入文本在当前光标处 if(document.selection) { var sel = document.selection.createRange(); sel.text = str; } else if(typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') { var startPos = obj.selectionStart, endPos = obj.selectionEnd, cursorPos = startPos, tmpStr = obj.value; obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length); cursorPos += str.length; obj.selectionStart = obj.selectionEnd = cursorPos; } else { obj.value += str; } } function injectList() { //注入希顶字母输入列表 function findList() { if(document.getElementsByTagName("div")) { for(var childs_ in document.getElementsByTagName("div")) { var childs = document.getElementsByTagName("div")[childs_]; var attrs = childs.attributes; if(attrs && (attrs["rel"] && attrs["rel"].value == "latin") && (attrs["class"] && attrs["class"].value == "page page-latin page-characters")) { return childs; } } } return null; }; if(findList()) { findList() .style = "display: none"; var xdi8List = document.createElement('div'); xdi8List.setAttribute('rel', 'xdi8'); xdi8List.setAttribute('class', 'page page-xdi8 page-characters'); var divin = document.createElement('div'); divin.setAttribute('dir', 'ltr'); var innerLetter = (xdi8Letters[0][1].concat(xdi8Letters[1][1])) .concat(xdi8Letters[2][1]); //内含物字母列表 for(var letter_ in innerLetter) { letter = innerLetter[letter_]; var spanin = document.createElement("span") spanin.setAttribute('rel', letter); spanin.innerText = letter; spanin.style.fontFamily = "'XEGOEPUAall',-apple-system,'Helvetica Neue','Segoe UI',Helvetica,'Nimbus Sans L',Arial,'Liberation Sans','PingFang SC','Hiragino Sans GB','Noto Sans CJK SC','Source Han Sans SC','Microsoft YaHei','Wenquanyi Micro Hei','WenQuanYi Zen Hei','ST Heiti',SimHei,'WenQuanYi Zen Hei Sharp',sans-serif"; divin.appendChild(spanin); spanin.onclick = function() { insertText(wpTextbox1, $(this) .attr('rel')); }; } xdi8List.appendChild(divin); findList() .parentNode.insertBefore(xdi8List, findList()); return true; } else { return false; } } function insertTransPuaNew(obj) { //向texteara文段翻译 var sel=obj.textSelection( 'getSelection') var trans = translatePua(sel); obj.textSelection( 'replaceSelection',trans) } function insertTransPua(obj) { //向texteara文段翻译 if(document.selection) { var sel = document.selection.createRange(); sel.text = translatePua(sel.text); } else if(typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') { var startPos = obj.selectionStart, endPos = obj.selectionEnd, cursorPos = startPos, tmpStr = obj.value; obj.value = tmpStr.substring(0, startPos) + translatePua(tmpStr.substring(startPos, endPos)) + tmpStr.substring(endPos, tmpStr.length); cursorPos += translatePua(tmpStr.substring(startPos, endPos)) .length - tmpStr.substring(startPos, endPos) .length; obj.selectionStart = obj.selectionEnd = cursorPos; } else { obj.value = translatePua(obj.value); } } function findTransPua(obj) { //在texteara里寻找{{x}}翻译 function findX(str) { for(var indx = str.indexOf("{{x|"); indx >= 0; indx = str.indexOf("{{x|")) { var floor = 1; var nowin = indx + 4; while(floor > 0) { var floora = str.indexOf("{{", nowin); var floorb = str.indexOf("}}", nowin); if(floora >= 0 || floorb >= 0) { //判断模板层数 if((floora < floorb && floora >= 0) || floorb < 0) { floor++; nowin = floora + 2; } else if((floorb < floora && floorb >= 0) || floora < 0) { floor--; nowin = floorb + 2; } } else { floor = 0; } } str = str.substring(0, indx) + translatePua(str.substring(indx + 4, nowin - 2)) + str.substring(nowin, str.length); } return str; } var txt = obj.textSelection( 'getContents') obj.textSelection( 'setContents',findX(txt) ); } function injectBelow() { //注入下面的按钮 $('div .editOptions').prepend('<div id="xdi8-tools"></div>'); var xdi8Tools=$('#xdi8-tools'); var mwtextbox = $('#wpTextbox1'); var bottom1=new OO.ui.ButtonWidget( { icon: 'edit', label: '输入希顶字母' } ); bottom1.on('click',function() { document.getElementById("wikiEditor-section-xdi8") .setAttribute('class', 'booklet section section-xdi8 section-visible'); }); var bottom2 = new OO.ui.ButtonWidget( { icon: 'reload', label: '转换选中区域希顶为PUA' } ); bottom2.on('click',function() { insertTransPuaNew(mwtextbox); }); var bottom3 = new OO.ui.ButtonWidget( { icon: 'reload', label: '转换全文{{x|}}内希顶为PUA' } ); bottom3.on('click',function() { findTransPua(mwtextbox); }); xdi8Tools.append(bottom1.$element); xdi8Tools.append(bottom2.$element); xdi8Tools.append(bottom3.$element); return true; } function injectDivOutsideTable() { //注入表格外父级div var allTable = document.getElementsByTagName("table"); if(allTable) { for(var child_ in allTable) { var child = allTable[child_]; var divOutside = document.createElement('div'); divOutside.setAttribute("class", "divOutsideTable"); if(child.parentNode){ child.parentNode.insertBefore(divOutside, child); divOutside.appendChild(child); } } return true; } else { return false; } } /*************定时执行块*************/ //定时控制变量,用于处理部分延迟元素的后加载 var isjectBotton = false; var isjectList = false; var isjectBelow = false; var isjectDivOutsideTable = false; var XwInterval = setInterval(function() { //isjectBotton = (!isjectBotton) ? injectBotton() : true; //isjectList = (!isjectList) ? injectList() : true; isjectBelow = (!isjectBelow) ? injectBelow() : true; isjectDivOutsideTable = (!isjectDivOutsideTable) ? injectDivOutsideTable() : true;//注入表格外div }, 300); var XwRefreshInterval = setInterval(function () {//固定时间刷新页面 var myEvent = new Event('resize'); window.dispatchEvent(myEvent); }, 30); //销毁定时 setTimeout(function() { clearInterval(XwInterval); }, 15000); $(function() { //全文转希顶文字 document.getElementById('ca-varlang-3') .firstChild.innerHTML = '全文转希顶<small>不建议</small>'; }); mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) { $textarea.wikiEditor( 'addToToolbar', { // 特殊字母输入 sections: { xdi8: { type: 'booklet', label: '希顶字母' } } } ); $('#wpTextbox1').wikiEditor( 'addToToolbar', { section: 'xdi8', pages: { xdi: { layout: 'characters', label: '希顶字母', characters:(xdi8Letters[0][1].concat(xdi8Letters[1][1])).concat(xdi8Letters[2][1]) } } } ); } );
该页面使用的模板:
Template:X
(
查看源代码
)(受保护)
Module:Arguments
(
查看源代码
)
Module:Xd
(
查看源代码
)(受保护)
返回
MediaWiki:Gadget-Xdi8CharInsert.js
。