MediaWiki:Common.js:修订间差异

此后如竟没有炬火,我便是唯一的光。
跳转到导航 跳转到搜索
无编辑摘要
无编辑摘要
第4行: 第4行:
/*************多语言选择*************/
/*************多语言选择*************/
function cleartext() {
function cleartext() {
for (var i = 0; i < t1.length; i++) {
for(var i = 0; i < t1.length; i++) {
t1[i].style.display = 'none';
t1[i].style.display = 'none';
t2[i].style.display = 'none';
t2[i].style.display = 'none';
第15行: 第15行:


/*************编辑器注入*************/
/*************编辑器注入*************/
var xdi8Letters = [ //希顶字母表
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"],
["!`", "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"],
第29行: 第29行:
]
]
];
];

function translatePua(str) {//翻译作pua
function translatePua(str) { //翻译作pua
for (var i_ in xdi8Letters) {
for(var i_ in xdi8Letters) {
var i = xdi8Letters[i_];
var i = xdi8Letters[i_];
for (var j_ in i[0]) {
for(var j_ in i[0]) {
var j = i[0][j_];
var j = i[0][j_];
while (str != str.replace(j, i[1][i[0].indexOf(j)])) {
while(str != str.replace(j, i[1][i[0].indexOf(j)])) {
str = str.replace(j, i[1][i[0].indexOf(j)])
str = str.replace(j, i[1][i[0].indexOf(j)])
}
}
第42行: 第43行:
}
}


function injectBotton() {//注入希顶按钮
function injectBotton() { //注入希顶按钮
function findBotton() {
function findBotton() {
if (document.getElementsByTagName("div")) {
if(document.getElementsByTagName("div")) {
for (var childs_ in document.getElementsByTagName("div")) {
for(var childs_ in document.getElementsByTagName("div")) {
var childs = document.getElementsByTagName("div")[childs_];
var childs = document.getElementsByTagName("div")[childs_];
var attrs = childs.attributes;
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")) {
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 childs;
}
}
第55行: 第56行:
return null;
return null;
}
}
if (findBotton()) {
if(findBotton()) {
findBotton().setAttribute('class', '');
findBotton()
.setAttribute('class', '');
var xdi8Bottom = document.createElement('div');
var xdi8Bottom = document.createElement('div');
xdi8Bottom.setAttribute('rel', 'xdi8');
xdi8Bottom.setAttribute('rel', 'xdi8');
xdi8Bottom.setAttribute('id', 'xdi8in');
xdi8Bottom.setAttribute('id', 'xdi8in');
xdi8Bottom.onclick = function () { //取自mediawiki内部脚本
xdi8Bottom.onclick = function() { //取自mediawiki内部脚本
var section;
var section;
$(this).parent().parent().find('.page').hide();
$(this)
.parent()
$(this).parent().parent().find('.page-' + $(this).attr('rel')).show().trigger('loadPage');
$(this).siblings().removeClass('current');
.parent()
$(this).addClass('current');
.find('.page')
section = $(this).parent().parent().attr('rel');
.hide();
$(this)
$.cookie('wikiEditor-' + $(this).data('context').instance + '-booklet-' + section + '-page', $(this).attr('rel'), {
expires: 30,
.parent()
path: '/'
.parent()
});
.find('.page-' + $(this)
.attr('rel'))
.show()
.trigger('loadPage');
$(this)
.siblings()
.removeClass('current');
$(this)
.addClass('current');
section = $(this)
.parent()
.parent()
.attr('rel');
$.cookie('wikiEditor-' + $(this)
.data('context')
.instance + '-booklet-' + section + '-page', $(this)
.attr('rel'), {
expires: 30,
path: '/'
});
event.preventDefault();
event.preventDefault();
}
}
xdi8Bottom.innerText = "希顶字母";
xdi8Bottom.innerText = "希顶字母";
findBotton().parentNode.insertBefore(xdi8Bottom, findBotton());
findBotton()
.parentNode.insertBefore(xdi8Bottom, findBotton());
return true;
return true;
} else {
return false;
}
}
else { return false; }
}
}


function insertText(obj, str) {//向texteara插入文本在当前光标处
function insertText(obj, str) { //向texteara插入文本在当前光标处
if (document.selection) {
if(document.selection) {
var sel = document.selection.createRange();
var sel = document.selection.createRange();
sel.text = str;
sel.text = str;
} else if(typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
}
else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
var startPos = obj.selectionStart,
var startPos = obj.selectionStart,
endPos = obj.selectionEnd,
endPos = obj.selectionEnd,
第93行: 第115行:
cursorPos += str.length;
cursorPos += str.length;
obj.selectionStart = obj.selectionEnd = cursorPos;
obj.selectionStart = obj.selectionEnd = cursorPos;
}
} else {
else {
obj.value += str;
obj.value += str;
}
}
}
}

function injectList() {//注入希顶输入列表
function injectList() { //注入希顶输入列表
function findList() {
function findList() {
if (document.getElementsByTagName("div")) {
if(document.getElementsByTagName("div")) {
for (var childs_ in document.getElementsByTagName("div")) {
for(var childs_ in document.getElementsByTagName("div")) {
var childs = document.getElementsByTagName("div")[childs_];
var childs = document.getElementsByTagName("div")[childs_];
var attrs = childs.attributes;
var attrs = childs.attributes;
if (attrs && (attrs["rel"] && attrs["rel"].value == "latin") && (attrs["class"] && attrs["class"].value == "page page-latin page-characters")) {
if(attrs && (attrs["rel"] && attrs["rel"].value == "latin") && (attrs["class"] && attrs["class"].value == "page page-latin page-characters")) {
return childs;
return childs;
}
}
第111行: 第133行:
return null;
return null;
};
};
if (findList()) {
if(findList()) {
findList().style = "display: none";
findList()
.style = "display: none";
var xdi8List = document.createElement('div');
var xdi8List = document.createElement('div');
xdi8List.setAttribute('rel', 'xdi8');
xdi8List.setAttribute('rel', 'xdi8');
第120行: 第143行:
divin.setAttribute('dir', 'ltr');
divin.setAttribute('dir', 'ltr');


var innerLetter = (xdi8Letters[0][1].concat(xdi8Letters[1][1])).concat(xdi8Letters[2][1]);//内含物字母列表
var innerLetter = (xdi8Letters[0][1].concat(xdi8Letters[1][1]))
.concat(xdi8Letters[2][1]); //内含物字母列表
for (var letter_ in innerLetter) {
for(var letter_ in innerLetter) {
letter = innerLetter[letter_];
letter = innerLetter[letter_];
var spanin = document.createElement("span")
var spanin = document.createElement("span")
第128行: 第152行:
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";
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);
divin.appendChild(spanin);
spanin.onclick = function () { insertText(wpTextbox1, $(this).attr('rel')); };
spanin.onclick = function() {
insertText(wpTextbox1, $(this)
.attr('rel'));
};
}
}
xdi8List.appendChild(divin);
xdi8List.appendChild(divin);
findList().parentNode.insertBefore(xdi8List, findList());
findList()
.parentNode.insertBefore(xdi8List, findList());
return true;
return true;
} else {
return false;
}
}
else { return false; }
}
}


function insertTextBothSide(obj, str1, str2) {//向texteara插入文本在当前光标两侧
function insertTextBothSide(obj, str1, str2) { //向texteara插入文本在当前光标两侧
if (document.selection) {
if(document.selection) {
var sel = document.selection.createRange();
var sel = document.selection.createRange();
sel.text = str1 + sel.text + str2;
sel.text = str1 + sel.text + str2;
} else if(typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
}
else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
var startPos = obj.selectionStart,
var startPos = obj.selectionStart,
endPos = obj.selectionEnd,
endPos = obj.selectionEnd,
第150行: 第178行:
cursorPos += str1.length;
cursorPos += str1.length;
obj.selectionStart = obj.selectionEnd = cursorPos;
obj.selectionStart = obj.selectionEnd = cursorPos;
}
} else {
else {
obj.value = str1 + obj.value + str2;
obj.value = str1 + obj.value + str2;
}
}
}
}

function insertTransPua(obj) {//向texteara文段翻译
function insertTransPua(obj) { //向texteara文段翻译
if (document.selection) {
if(document.selection) {
var sel = document.selection.createRange();
var sel = document.selection.createRange();
sel.text = translatePua(sel.text);
sel.text = translatePua(sel.text);
} else if(typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
}
else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
var startPos = obj.selectionStart,
var startPos = obj.selectionStart,
endPos = obj.selectionEnd,
endPos = obj.selectionEnd,
第166行: 第193行:
tmpStr = obj.value;
tmpStr = obj.value;
obj.value = tmpStr.substring(0, startPos) + translatePua(tmpStr.substring(startPos, endPos)) + tmpStr.substring(endPos, tmpStr.length);
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;
cursorPos += translatePua(tmpStr.substring(startPos, endPos))
.length - tmpStr.substring(startPos, endPos)
.length;
obj.selectionStart = obj.selectionEnd = cursorPos;
obj.selectionStart = obj.selectionEnd = cursorPos;
}
} else {
else {
obj.value = translatePua(obj.value);
obj.value = translatePua(obj.value);
}
}
}
}

function findTransPua(obj) {//在texteara里寻找{{x}}翻译
function findTransPua(obj) { //在texteara里寻找{{x}}翻译
function findX(str) {
function findX(str) {
for (var indx = str.indexOf("{{x|"); indx >= 0; indx = str.indexOf("{{x|")) {
for(var indx = str.indexOf("{{x|"); indx >= 0; indx = str.indexOf("{{x|")) {
var floor = 1;
var floor = 1;
var nowin = indx + 4;
var nowin = indx + 4;
while (floor > 0) {
while(floor > 0) {
var floora = str.indexOf("{{", nowin);
var floora = str.indexOf("{{", nowin);
var floorb = str.indexOf("}}", nowin);
var floorb = str.indexOf("}}", nowin);
if (floora >= 0 || floorb >= 0) {
if(floora >= 0 || floorb >= 0) {
if ((floora < floorb && floora >= 0) || floorb < 0) {
if((floora < floorb && floora >= 0) || floorb < 0) {
floor++;
floor++;
nowin = floora + 2;
nowin = floora + 2;
}
} else if((floorb < floora && floorb >= 0) || floora < 0) {
else if ((floorb < floora && floorb >= 0) || floora < 0) {
floor--;
floor--;
nowin = floorb + 2;
nowin = floorb + 2;
第200行: 第228行:
obj.value = findX(obj.value);
obj.value = findX(obj.value);
}
}

function injectBelow() {//注入下面的按钮
function findBelow() {//寻找位置
function injectBelow() { //注入下面的按钮
function findBelow() { //寻找位置
if (document.getElementsByTagName("div")) {
for (var childs_ in document.getElementsByTagName("div")) {
if(document.getElementsByTagName("div")) {
for(var childs_ in document.getElementsByTagName("div")) {
var childs = document.getElementsByTagName("div")[childs_];
var childs = document.getElementsByTagName("div")[childs_];
var attrs = childs.attributes;
var attrs = childs.attributes;
if (attrs && attrs["class"] && attrs["class"].value == "editOptions") {
if(attrs && attrs["class"] && attrs["class"].value == "editOptions") {
return childs;
return childs;
}
}
第213行: 第242行:
return null;
return null;
};
};
if (findBelow()) {
if(findBelow()) {
//希顶翻译块
//希顶翻译块
var belowBottom3 = document.createElement('a');
var belowBottom3 = document.createElement('a');
belowBottom3.onclick = function () { insertTransPua(wpTextbox1); };
belowBottom3.onclick = function() {
insertTransPua(wpTextbox1);
};
belowBottom3.innerText = "转换选中区域希顶为PUA";
belowBottom3.innerText = "转换选中区域希顶为PUA";
belowBottom3.style.marginLeft = "1.4em";
belowBottom3.style.marginLeft = "1.4em";
findBelow().insertBefore(belowBottom3, findBelow().childNodes[0]);
findBelow()
.insertBefore(belowBottom3, findBelow()
.childNodes[0]);
//希顶翻译全文
//希顶翻译全文
var belowBottom4 = document.createElement('a');
var belowBottom4 = document.createElement('a');
belowBottom4.onclick = function () { findTransPua(wpTextbox1); };
belowBottom4.onclick = function() {
findTransPua(wpTextbox1);
};
belowBottom4.innerText = "转换全文{{x|}}内希顶为PUA";
belowBottom4.innerText = "转换全文{{x|}}内希顶为PUA";
belowBottom4.style.marginLeft = "1.4em";
belowBottom4.style.marginLeft = "1.4em";
findBelow().insertBefore(belowBottom4, findBelow().childNodes[0]);
findBelow()
.insertBefore(belowBottom4, findBelow()
.childNodes[0]);
//插入功能表
//插入功能表
var funcLists = [
var funcLists = [
第238行: 第275行:
["{{x|", "}}"]
["{{x|", "}}"]
]
]
for (var funcList_ in funcLists) {
for(var funcList_ in funcLists) {
var funcList = funcLists[funcList_];
var funcList = funcLists[funcList_];
var belowBottom2 = document.createElement('a');
var belowBottom2 = document.createElement('a');
belowBottom2.setAttribute('onclick', "insertTextBothSide(wpTextbox1,'" + funcList[0] + "','" + funcList[1] + "');");//需要固定量
belowBottom2.setAttribute('onclick', "insertTextBothSide(wpTextbox1,'" + funcList[0] + "','" + funcList[1] + "');"); //需要固定量
belowBottom2.innerText = funcList[0] + (funcList[1] != "" ? "..." : "") + funcList[1];
belowBottom2.innerText = funcList[0] + (funcList[1] != "" ? "..." : "") + funcList[1];
belowBottom2.style.marginLeft = "1.4em";
belowBottom2.style.marginLeft = "1.4em";
findBelow().insertBefore(belowBottom2, findBelow().childNodes[0]);
findBelow()
.insertBefore(belowBottom2, findBelow()
.childNodes[0]);
}
}


var belowBottom = document.createElement('a');
var belowBottom = document.createElement('a');
belowBottom.href = "#xdi8in";
belowBottom.href = "#xdi8in";
belowBottom.onclick = function () {
belowBottom.onclick = function() {
document.getElementById("wikiEditor-section-characters").setAttribute('class', 'booklet section section-characters section-visible');
document.getElementById("wikiEditor-section-characters")
.setAttribute('class', 'booklet section section-characters section-visible');
}
}
belowBottom.innerText = "输入希顶字母";
belowBottom.innerText = "输入希顶字母";
findBelow().insertBefore(belowBottom, findBelow().childNodes[0]);
findBelow()
.insertBefore(belowBottom, findBelow()
.childNodes[0]);
return true;
return true;
} else {
return false;
}
}
else { return false; }
}
}


function setMobileBody(){ //移动端处理
function setMobileBody() { //移动端处理
//标题栏处理,已废弃
//标题栏处理,已废弃
/*if(window.screen.width <= 500 || ('ontouchstart' in document.documentElement)){
/*if(window.screen.width <= 500 || ('ontouchstart' in document.documentElement)){
第268行: 第311行:
document.querySelector("#mw-head").style.right = "0px";
document.querySelector("#mw-head").style.right = "0px";
}*/
}*/
if(window.screen.width <= 500){//如果在手机上
if(window.screen.width <= 500) { //如果在手机上
//缩放处理
//缩放处理
document.querySelector("body").style.position="absolute";
document.querySelector("body")
.style.position = "absolute";
document.querySelector("body").style.transform="scale("+(window.screen.width/500)+")";
//document.querySelector("body").style.left= (-(500-window.screen.width)/2)+"px";
document.querySelector("body")
//document.querySelector("body").style.top= (-(document.querySelector("body").clientHeight-document.querySelector("body").clientHeight*(window.screen.width/500))/2)+"px";
.style.transform = "scale(" + (window.screen.width / 500) + ")";
//document.querySelector("body").style.left= (-(500-window.screen.width)/2)+"px";
}
//document.querySelector("body").style.top= (-(document.querySelector("body").clientHeight-document.querySelector("body").clientHeight*(window.screen.width/500))/2)+"px";
}
}
}


function injectPageBase(){ //处理大页面边距的一部分,其余用css实现
function injectPageBase() { //处理大页面边距的一部分,其余用css实现
var mwPageBase = document.querySelector("#mw-page-base")
var mwPageBase = document.querySelector("#mw-page-base")
if(mwPageBase){
if(mwPageBase) {
var clonedPageBase = mwPageBase.cloneNode(true);
var clonedPageBase = mwPageBase.cloneNode(true);
//clonedPageBase.setAttribute("id", "cloned-page-base");
//clonedPageBase.setAttribute("id", "cloned-page-base");
clonedPageBase.setAttribute("style", "position: absolute; top: 0; width: 100%; left: 0;");//css属性,浮动在背后提供背景
clonedPageBase.setAttribute("style", "position: absolute; top: 0; width: 100%; left: 0;"); //css属性,浮动在背后提供背景
mwPageBase.parentNode.insertBefore(clonedPageBase, mwPageBase);
mwPageBase.parentNode.insertBefore(clonedPageBase, mwPageBase);
return true;
return true;
} else return false;
}
else return false;
}
}


var isShowPanel=false;//信息栏标志
var isShowPanel = false; //信息栏标志
function infoMethod(){//信息栏响应函数
function infoMethod() { //信息栏响应函数
if(!isShowPanel){
if(!isShowPanel) {
isShowPanel=true;
isShowPanel = true;
document.querySelector("#mw-panel").style.display="block";
document.querySelector("#mw-panel")
.style.display = "block";
document.querySelector("#ca-nstab-project").style.backgroundImage="linear-gradient(to top,#77c1f6 0,#e8f2f8 1px,#ffffff 100%)";
document.querySelector("#ca-nstab-project")
.style.backgroundImage = "linear-gradient(to top,#77c1f6 0,#e8f2f8 1px,#ffffff 100%)";
} else {
isShowPanel = false;
document.querySelector("#mw-panel")
.style.display = "none";
document.querySelector("#ca-nstab-project")
.style.backgroundImage = "linear-gradient(to top,#ffffff 0,#ffffff 100%)";
}
}
else{
isShowPanel=false;
document.querySelector("#mw-panel").style.display="none";
document.querySelector("#ca-nstab-project").style.backgroundImage="linear-gradient(to top,#ffffff 0,#ffffff 100%)";
}
}
}

function injectInfos(){ //注入信息栏
function injectInfos() { //注入信息栏
if(window.screen.width <= 500&&document.querySelector("#p-namespaces > div > ul")){//如果在手机上并且加载完毕
if(window.screen.width <= 500 && document.querySelector("#p-namespaces > div > ul")) { //如果在手机上并且加载完毕
var myInfos = document.createElement('li');
var myInfos = document.createElement('li');
myInfos.setAttribute("id","infos");
myInfos.setAttribute("class","selected");
myInfos.setAttribute("id", "infos");
myInfos.setAttribute("class", "selected");
myInfos.innerHTML="<a id='ininfos' href='javascript:void(0);' onclick='infoMethod()'>☰</a>";
myInfos.innerHTML = "<a id='ininfos' href='javascript:void(0);' onclick='infoMethod()'>☰</a>";
document.querySelector("#p-namespaces > div > ul").insertBefore(myInfos, document.querySelector("#p-namespaces > div > ul").firstElementChild);
document.querySelector("#p-namespaces > div > ul")
return true;
.insertBefore(myInfos, document.querySelector("#p-namespaces > div > ul")
}
.firstElementChild);
else return false;
return true;
} else return false;
}

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");
child.parentNode.insertBefore(divOutside, child);
divOutside.appendChild(child);
}
}
}
}


第321行: 第383行:
var isjectPageBase = false;
var isjectPageBase = false;
var isjectInfos = false;
var isjectInfos = false;
var XwInterval = setInterval(function () {
var XwInterval = setInterval(function() {
isjectBotton = (!isjectBotton) ? injectBotton() : true;
isjectBotton = (!isjectBotton) ? injectBotton() : true;
isjectList = (!isjectList) ? injectList() : true;
isjectList = (!isjectList) ? injectList() : true;
第327行: 第389行:
isjectPageBase = (!isjectPageBase) ? injectPageBase() : true;
isjectPageBase = (!isjectPageBase) ? injectPageBase() : true;
isjectInfos = (!isjectInfos) ? injectInfos() : true;
isjectInfos = (!isjectInfos) ? injectInfos() : true;

if(document.querySelector("#p-variants-label > span").innerText == '新加坡简体')
if(document.querySelector("#p-variants-label > span")
document.querySelector("#p-variants-label > span").innerText = '全文转希顶';
.innerText == '新加坡简体')
document.querySelector("#p-variants-label > span")
}
.innerText = '全文转希顶';
, 300);
}, 300);
var XwInterval2 = setInterval(setMobileBody , 3);
var XwInterval3 = setInterval(function(){
var XwInterval2 = setInterval(setMobileBody, 3);
var XwInterval3 = setInterval(function() {
var myEvent = new Event('resize');
var myEvent = new Event('resize');
window.dispatchEvent(myEvent);
window.dispatchEvent(myEvent);
} , 30);
}, 30);
//销毁定时
//销毁定时
setTimeout(function () {
setTimeout(function() {
clearInterval(XwInterval);
clearInterval(XwInterval);
clearInterval(XwInterval2);
clearInterval(XwInterval2);
},
},
15000);
15000);


第347行: 第410行:
/*************函数执行块*************/
/*************函数执行块*************/
//载入js时加载
//载入js时加载
injectMobieDemand();//移动端需求注入
injectMobieDemand(); //移动端需求注入


//dom执行完成后加载
//dom执行完成后加载
$(function () {
$(function() {
//全文转希顶文字
//全文转希顶文字
document.getElementById('ca-varlang-3').firstChild.innerHTML = '全文转希顶<small>不建议</small>';
document.getElementById('ca-varlang-3')
.firstChild.innerHTML = '全文转希顶<small>不建议</small>';
//document.getElementById('p-variants-label').firstChild.innerText = '全文转希顶';
//document.getElementById('p-variants-label').firstChild.innerText = '全文转希顶';

//移动端需求注入
//移动端需求注入
injectMobieDemand();
injectMobieDemand();
//移动端处理
//移动端处理
setMobileBody();
setMobileBody();

//处理大页面边距
//处理大页面边距
injectPageBase();
injectPageBase();

//移动端信息栏
//注入表格外div
//injectInfos();
injectDivOutsideTable();
//移动端信息栏
//injectInfos();
});
});
/*************内部包含反响*************/
/*************内部包含反响*************/
//需要mw参数时用,回调函数外部无法取值
//需要mw参数时用,回调函数外部无法取值
(function (mw) {
(function(mw) {


})(mediaWiki);
})(mediaWiki);

2022年12月21日 (三) 21:41的版本

/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
/* 这些源码执行和希顶WIKI相同的 “知识共享署名-相同方式共享 4.0” 协议 */

/*************多语言选择*************/
function cleartext() {
    for(var i = 0; i < t1.length; i++) {
        t1[i].style.display = 'none';
        t2[i].style.display = 'none';
        t3[i].style.display = 'none';
        t4[i].style.display = 'none';
        t5[i].style.display = 'none';
        t6[i].style.display = 'none';
    }
}

/*************编辑器注入*************/
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-' + $(this)
                .data('context')
                .instance + '-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 insertTextBothSide(obj, str1, str2) { //向texteara插入文本在当前光标两侧
    if(document.selection) {
        var sel = document.selection.createRange();
        sel.text = str1 + sel.text + str2;
    } 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) + str1 + tmpStr.substring(startPos, endPos) + str2 + tmpStr.substring(endPos, tmpStr.length);
        cursorPos += str1.length;
        obj.selectionStart = obj.selectionEnd = cursorPos;
    } else {
        obj.value = str1 + obj.value + str2;
    }
}

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;
    }
    obj.value = findX(obj.value);
}

function injectBelow() { //注入下面的按钮
    function findBelow() { //寻找位置
        if(document.getElementsByTagName("div")) {
            for(var childs_ in document.getElementsByTagName("div")) {
                var childs = document.getElementsByTagName("div")[childs_];
                var attrs = childs.attributes;
                if(attrs && attrs["class"] && attrs["class"].value == "editOptions") {
                    return childs;
                }
            }
        }
        return null;
    };
    if(findBelow()) {
        //希顶翻译块
        var belowBottom3 = document.createElement('a');
        belowBottom3.onclick = function() {
            insertTransPua(wpTextbox1);
        };
        belowBottom3.innerText = "转换选中区域希顶为PUA";
        belowBottom3.style.marginLeft = "1.4em";
        findBelow()
            .insertBefore(belowBottom3, findBelow()
                .childNodes[0]);
        //希顶翻译全文
        var belowBottom4 = document.createElement('a');
        belowBottom4.onclick = function() {
            findTransPua(wpTextbox1);
        };
        belowBottom4.innerText = "转换全文{{x|}}内希顶为PUA";
        belowBottom4.style.marginLeft = "1.4em";
        findBelow()
            .insertBefore(belowBottom4, findBelow()
                .childNodes[0]);
        //插入功能表
        var funcLists = [
            ["[[", "]]"],
            ["{{拼|", "}}"],
            ["{{|", "}}"],
            ["{{ruby|", "|}}"],
            ["{{color|red|", "}}"],
            ["{{国家声明}}", ""],
            ["{{人物声明}}", ""],
            ["{{Info|", "}}"],
            ["{{x|", "}}"]
        ]
        for(var funcList_ in funcLists) {
            var funcList = funcLists[funcList_];
            var belowBottom2 = document.createElement('a');
            belowBottom2.setAttribute('onclick', "insertTextBothSide(wpTextbox1,'" + funcList[0] + "','" + funcList[1] + "');"); //需要固定量
            belowBottom2.innerText = funcList[0] + (funcList[1] != "" ? "..." : "") + funcList[1];
            belowBottom2.style.marginLeft = "1.4em";
            findBelow()
                .insertBefore(belowBottom2, findBelow()
                    .childNodes[0]);
        }

        var belowBottom = document.createElement('a');
        belowBottom.href = "#xdi8in";
        belowBottom.onclick = function() {
            document.getElementById("wikiEditor-section-characters")
                .setAttribute('class', 'booklet section section-characters section-visible');
        }
        belowBottom.innerText = "输入希顶字母";
        findBelow()
            .insertBefore(belowBottom, findBelow()
                .childNodes[0]);
        return true;
    } else {
        return false;
    }
}

function setMobileBody() { //移动端处理
    //标题栏处理,已废弃
    /*if(window.screen.width <= 500 || ('ontouchstart' in document.documentElement)){
		document.querySelector("#mw-head").style.width = document.querySelector("#mw-head").parentNode.clientWidth + 23 + "px";
		document.querySelector("#mw-head").style.right = (-720 + window.screen.width) + "px";
	}
	else{
		document.querySelector("#mw-head").style.right = "0px";
	}*/
    if(window.screen.width <= 500) { //如果在手机上
        //缩放处理
        document.querySelector("body")
            .style.position = "absolute";
        document.querySelector("body")
            .style.transform = "scale(" + (window.screen.width / 500) + ")";
        //document.querySelector("body").style.left= (-(500-window.screen.width)/2)+"px";
        //document.querySelector("body").style.top= (-(document.querySelector("body").clientHeight-document.querySelector("body").clientHeight*(window.screen.width/500))/2)+"px";
    }
}

function injectPageBase() { //处理大页面边距的一部分,其余用css实现
    var mwPageBase = document.querySelector("#mw-page-base")
    if(mwPageBase) {
        var clonedPageBase = mwPageBase.cloneNode(true);
        //clonedPageBase.setAttribute("id", "cloned-page-base");
        clonedPageBase.setAttribute("style", "position: absolute; top: 0; width: 100%; left: 0;"); //css属性,浮动在背后提供背景
        mwPageBase.parentNode.insertBefore(clonedPageBase, mwPageBase);
        return true;
    } else return false;
}

var isShowPanel = false; //信息栏标志
function infoMethod() { //信息栏响应函数
    if(!isShowPanel) {
        isShowPanel = true;
        document.querySelector("#mw-panel")
            .style.display = "block";
        document.querySelector("#ca-nstab-project")
            .style.backgroundImage = "linear-gradient(to top,#77c1f6 0,#e8f2f8 1px,#ffffff 100%)";
    } else {
        isShowPanel = false;
        document.querySelector("#mw-panel")
            .style.display = "none";
        document.querySelector("#ca-nstab-project")
            .style.backgroundImage = "linear-gradient(to top,#ffffff 0,#ffffff 100%)";
    }
}

function injectInfos() { //注入信息栏
    if(window.screen.width <= 500 && document.querySelector("#p-namespaces > div > ul")) { //如果在手机上并且加载完毕
        var myInfos = document.createElement('li');
        myInfos.setAttribute("id", "infos");
        myInfos.setAttribute("class", "selected");
        myInfos.innerHTML = "<a id='ininfos' href='javascript:void(0);' onclick='infoMethod()'>☰</a>";
        document.querySelector("#p-namespaces > div > ul")
            .insertBefore(myInfos, document.querySelector("#p-namespaces > div > ul")
                .firstElementChild);
        return true;
    } else return false;
}

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");
            child.parentNode.insertBefore(divOutside, child);
            divOutside.appendChild(child);
        }
    }
}

/*************定时执行块*************/
//定时控制变量,用于处理部分延迟元素的后加载
var isjectBotton = false;
var isjectList = false;
var isjectBelow = false;
var isjectPageBase = false;
var isjectInfos = false;
var XwInterval = setInterval(function() {
    isjectBotton = (!isjectBotton) ? injectBotton() : true;
    isjectList = (!isjectList) ? injectList() : true;
    isjectBelow = (!isjectBelow) ? injectBelow() : true;
    isjectPageBase = (!isjectPageBase) ? injectPageBase() : true;
    isjectInfos = (!isjectInfos) ? injectInfos() : true;

    if(document.querySelector("#p-variants-label > span")
        .innerText == '新加坡简体')
        document.querySelector("#p-variants-label > span")
        .innerText = '全文转希顶';
}, 300);
var XwInterval2 = setInterval(setMobileBody, 3);
var XwInterval3 = setInterval(function() {
    var myEvent = new Event('resize');
    window.dispatchEvent(myEvent);
}, 30);
//销毁定时
setTimeout(function() {
        clearInterval(XwInterval);
        clearInterval(XwInterval2);
    },
    15000);


/*************函数执行块*************/
//载入js时加载
injectMobieDemand(); //移动端需求注入

//dom执行完成后加载
$(function() {
    //全文转希顶文字
    document.getElementById('ca-varlang-3')
        .firstChild.innerHTML = '全文转希顶<small>不建议</small>';
    //document.getElementById('p-variants-label').firstChild.innerText = '全文转希顶';

    //移动端需求注入
    injectMobieDemand();
    //移动端处理
    setMobileBody();

    //处理大页面边距
    injectPageBase();

    //注入表格外div
    injectDivOutsideTable();
    //移动端信息栏
    //injectInfos();
});
/*************内部包含反响*************/
//需要mw参数时用,回调函数外部无法取值
(function(mw) {

})(mediaWiki);