修复小镇提示的错误,添加脚本的功能配置
This commit is contained in:
parent
b1f09a502a
commit
e79f094fce
@ -1,8 +1,8 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @lastmodified 202112272108
|
// @lastmodified 202112290010
|
||||||
// @name Torn翻译
|
// @name Torn翻译
|
||||||
// @namespace WOOH
|
// @namespace WOOH
|
||||||
// @version 0.1.1227a
|
// @version 0.1.1229a
|
||||||
// @description Torn UI翻译
|
// @description Torn UI翻译
|
||||||
// @author Woohoo-[2687093] sabrina_devil[2696209]
|
// @author Woohoo-[2687093] sabrina_devil[2696209]
|
||||||
// @match https://www.torn.com/*
|
// @match https://www.torn.com/*
|
||||||
@ -23,6 +23,11 @@
|
|||||||
todo: true,
|
todo: true,
|
||||||
cont: `baza npc商店 imarket及imarket搜索结果`,
|
cont: `baza npc商店 imarket及imarket搜索结果`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ver: '0.1.1229a',
|
||||||
|
date: '20211229',
|
||||||
|
cont: `修复小镇提示的错误,添加脚本的功能配置`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ver: '0.1.1227a',
|
ver: '0.1.1227a',
|
||||||
date: '20211227',
|
date: '20211227',
|
||||||
@ -2864,6 +2869,7 @@
|
|||||||
// transDict.calDict = calDict;
|
// transDict.calDict = calDict;
|
||||||
// if (!localStorage.getItem('wh_trans_transDict')) localStorage.setItem('wh_trans_transDict', JSON.stringify(transDict))
|
// if (!localStorage.getItem('wh_trans_transDict')) localStorage.setItem('wh_trans_transDict', JSON.stringify(transDict))
|
||||||
|
|
||||||
|
const mobile = window.innerWidth <= 600;
|
||||||
// 左侧标签
|
// 左侧标签
|
||||||
const zhongIconIntervalID = window.setInterval(() => {
|
const zhongIconIntervalID = window.setInterval(() => {
|
||||||
if (!document.querySelector('#wh-trans-icon')) initIcon();
|
if (!document.querySelector('#wh-trans-icon')) initIcon();
|
||||||
@ -2871,24 +2877,32 @@
|
|||||||
const wh_trans_settings = localStorage.getItem('wh_trans_settings')
|
const wh_trans_settings = localStorage.getItem('wh_trans_settings')
|
||||||
? JSON.parse(localStorage.getItem('wh_trans_settings'))
|
? JSON.parse(localStorage.getItem('wh_trans_settings'))
|
||||||
: {
|
: {
|
||||||
transEnable: true,
|
transEnable: false,
|
||||||
attBtnPos: 2,
|
quickCrime: true,
|
||||||
|
missionHint: true,
|
||||||
|
xmasTownWT: true,
|
||||||
|
xmasTownNotify: true,
|
||||||
|
energyAlert: true,
|
||||||
|
quickAtt: false,
|
||||||
|
quichAttIndex: 2,
|
||||||
isDev: false,
|
isDev: false,
|
||||||
};
|
};
|
||||||
|
// const quickAttArr = ['pri', 'sec', 'wea', 'gre', 'fis', 'kic'];
|
||||||
initIcon();
|
initIcon();
|
||||||
addStyle(
|
addStyle(`#wh-trans-icon{
|
||||||
`#wh-trans-icon{
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 50%;
|
top: calc(50% - 100px);
|
||||||
left: 0;
|
left: 0;
|
||||||
z-index: 10;
|
z-index: 20000;
|
||||||
background-color: white;
|
|
||||||
border: solid 1px #b5b5b5;
|
border: solid 1px #b5b5b5;
|
||||||
border-left: none;
|
border-left: none;
|
||||||
border-radius: 0 4px 4px 0;
|
border-radius: 0 4px 4px 0;
|
||||||
max-width: 200px;
|
max-width: 200px;
|
||||||
}
|
}
|
||||||
|
#wh-trans-icon input{
|
||||||
|
margin:0 4px 0 0;
|
||||||
|
}
|
||||||
#wh-trans-icon button{
|
#wh-trans-icon button{
|
||||||
margin:0;
|
margin:0;
|
||||||
padding:0;
|
padding:0;
|
||||||
@ -2907,11 +2921,6 @@ padding:16px !important;
|
|||||||
}
|
}
|
||||||
.wh-hide{display:none;}`);
|
.wh-hide{display:none;}`);
|
||||||
|
|
||||||
// 默认开启通知翻译
|
|
||||||
if (!localStorage.getItem('wh_trans_event')) {
|
|
||||||
localStorage.setItem('wh_trans_event', 'true');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时分秒转换
|
* 时分秒转换
|
||||||
*/
|
*/
|
||||||
@ -2953,6 +2962,7 @@ padding:16px !important;
|
|||||||
* 边栏
|
* 边栏
|
||||||
* 目前默认所有页面调用边栏翻译
|
* 目前默认所有页面调用边栏翻译
|
||||||
*/
|
*/
|
||||||
|
if (wh_trans_settings.transEnable) {
|
||||||
let sidebarTimeOut = 60;
|
let sidebarTimeOut = 60;
|
||||||
const sidebarInterval = setInterval(() => {
|
const sidebarInterval = setInterval(() => {
|
||||||
// 60秒后取消定时
|
// 60秒后取消定时
|
||||||
@ -3017,6 +3027,7 @@ padding:16px !important;
|
|||||||
|
|
||||||
clearInterval(sidebarInterval);
|
clearInterval(sidebarInterval);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 迷你资料卡 全局 todo
|
* 迷你资料卡 全局 todo
|
||||||
@ -3069,12 +3080,12 @@ padding:16px !important;
|
|||||||
// }
|
// }
|
||||||
// }, 1000);
|
// }, 1000);
|
||||||
};
|
};
|
||||||
miniProfile();
|
if (wh_trans_settings.transEnable) miniProfile();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* header
|
* header
|
||||||
*/
|
*/
|
||||||
if ($('div#header-root').length > 0) {
|
if (wh_trans_settings.transEnable && document.querySelector('div#header-root')) {
|
||||||
const headerOB = new MutationObserver(_ => {
|
const headerOB = new MutationObserver(_ => {
|
||||||
headerOB.disconnect();
|
headerOB.disconnect();
|
||||||
headerTrans();
|
headerTrans();
|
||||||
@ -3157,7 +3168,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* chatbox
|
* chatbox
|
||||||
*/
|
*/
|
||||||
if ($('div#chatRoot').length > 0) {
|
if (wh_trans_settings.transEnable && document.querySelector('div#chatRoot')) {
|
||||||
const chatOB = new MutationObserver(_ => {
|
const chatOB = new MutationObserver(_ => {
|
||||||
chatOB.disconnect();
|
chatOB.disconnect();
|
||||||
chatTrans();
|
chatTrans();
|
||||||
@ -3239,13 +3250,14 @@ padding:16px !important;
|
|||||||
});
|
});
|
||||||
psbtOB.observe(document.body, opt);
|
psbtOB.observe(document.body, opt);
|
||||||
}
|
}
|
||||||
playerSearchBoxTrans();
|
if (wh_trans_settings.transEnable) playerSearchBoxTrans();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 飞行页面
|
* 飞行页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('index.php') >= 0 &&
|
if (window.location.href.indexOf('index.php') >= 0 &&
|
||||||
$('div.travelling h4').length !== 0) {
|
$('div.travelling h4').length !== 0 &&
|
||||||
|
wh_trans_settings.transEnable) {
|
||||||
const travelOB = new MutationObserver(travelOBInit);
|
const travelOB = new MutationObserver(travelOBInit);
|
||||||
|
|
||||||
function travelOBInit() {
|
function travelOBInit() {
|
||||||
@ -3283,8 +3295,9 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* 主页 todo
|
* 主页 todo
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('index.php') >= 0 &&
|
if (wh_trans_settings.transEnable &&
|
||||||
$('h4#skip-to-content').text().indexOf('Home') >= 0) {
|
window.location.href.contains(/index\.php/) &&
|
||||||
|
document.querySelector('h4#skip-to-content').innerText.contains(/Home/)) {
|
||||||
titleTrans();
|
titleTrans();
|
||||||
contentTitleLinksTrans();
|
contentTitleLinksTrans();
|
||||||
|
|
||||||
@ -3340,6 +3353,7 @@ padding:16px !important;
|
|||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/travelagency\.php/)) {
|
if (window.location.href.contains(/travelagency\.php/)) {
|
||||||
const $$ = $('.content-wrapper');
|
const $$ = $('.content-wrapper');
|
||||||
|
if (wh_trans_settings.energyAlert) {
|
||||||
const OB = new MutationObserver(() => {
|
const OB = new MutationObserver(() => {
|
||||||
OB.disconnect();
|
OB.disconnect();
|
||||||
titleTrans();
|
titleTrans();
|
||||||
@ -3384,13 +3398,100 @@ padding:16px !important;
|
|||||||
subtree: true,
|
subtree: true,
|
||||||
childList: true
|
childList: true
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 攻击页面
|
||||||
|
*/
|
||||||
|
if (window.location.href.contains(/sid=attack/)) {
|
||||||
|
if (wh_trans_settings.quickAtt && !mobile) {
|
||||||
|
const getAbsTop = (e) => {
|
||||||
|
let actualTop = e.offsetTop;
|
||||||
|
let current = e.offsetParent;
|
||||||
|
while (current !== null) {
|
||||||
|
actualTop += (current.offsetTop + current.clientTop);
|
||||||
|
current = current.offsetParent;
|
||||||
|
}
|
||||||
|
return actualTop;
|
||||||
|
};
|
||||||
|
const getAbsLeft = (e) => {
|
||||||
|
let actualLeft = e.offsetLeft;
|
||||||
|
let current = e.offsetParent;
|
||||||
|
while (current !== null) {
|
||||||
|
actualLeft += (current.offsetLeft + current.clientLeft);
|
||||||
|
current = current.offsetParent;
|
||||||
|
}
|
||||||
|
return actualLeft;
|
||||||
|
};
|
||||||
|
const IDMap = ['weapon_main', 'weapon_second', 'weapon_melee', 'weapon_temp', 'weapon_fists', 'weapon_boots'];
|
||||||
|
let dialog_container;
|
||||||
|
let btnParentElem;
|
||||||
|
let startBtn;
|
||||||
|
// const get_btn_ob = new MutationObserver(() => {
|
||||||
|
// dialog_container = document.querySelector('div[class^="dialog___"]');
|
||||||
|
// if (dialog_container) {
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// get_btn_ob.observe(document, {subtree: true, childList: true,});
|
||||||
|
elementReady('div[class^="dialog___"]').then(e => {
|
||||||
|
dialog_container = e;
|
||||||
|
// get_btn_ob.disconnect();
|
||||||
|
const targetNode = document.querySelector(`#${IDMap[wh_trans_settings.quichAttIndex]} figure`);
|
||||||
|
if (targetNode) {
|
||||||
|
const targetT = getAbsTop(targetNode);
|
||||||
|
const targetL = getAbsLeft(targetNode);
|
||||||
|
const targetWidth = targetNode.offsetWidth;
|
||||||
|
const targetHeight = targetNode.offsetHeight;
|
||||||
|
// dialog_container.classList.toggle('wh-hide');
|
||||||
|
const newBtn = dialog_container.querySelector('button');
|
||||||
|
startBtn = newBtn;
|
||||||
|
btnParentElem = newBtn.parentElement;
|
||||||
|
// const newBtn = dialog_container.querySelector('button').cloneNode(true);
|
||||||
|
// dialog_container.querySelector('button').remove();
|
||||||
|
// const newBtn=dialog_container;
|
||||||
|
document.body.appendChild(newBtn);
|
||||||
|
newBtn.style.position = 'absolute';
|
||||||
|
newBtn.style.top = `${targetT}px`;
|
||||||
|
newBtn.style.left = `${targetL}px`;
|
||||||
|
newBtn.style.margin = '0';
|
||||||
|
newBtn.style.zIndex = '999';
|
||||||
|
newBtn.style.width = `${targetWidth}px`;
|
||||||
|
newBtn.style.height = `${targetHeight}px`;
|
||||||
|
} else if (wh_trans_settings.isDev) {
|
||||||
|
console.warn('找不到武器格子,是不是选错了?');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// let isBtnMoved = false;
|
||||||
|
let original_fetch = window.fetch;
|
||||||
|
window.fetch = async (url, init) => {
|
||||||
|
if (isDev()) console.log('[before]', url, init)
|
||||||
|
const attPrs = false;
|
||||||
|
if (url.contains(/loader\.php.+sid=attack/) && attPrs) {
|
||||||
|
//还原
|
||||||
|
btnParentElem.appendChild(startBtn);
|
||||||
|
startBtn.style = null;
|
||||||
|
}
|
||||||
|
let response = await original_fetch(url, init)
|
||||||
|
// let res = response.clone();
|
||||||
|
// res.json().then((data) => {
|
||||||
|
// if(isDev()) console.log('[response json data]', data)
|
||||||
|
// if (data.viewStyle && data.viewStyle === 'nonAttack') {
|
||||||
|
// const btn = document.querySelector('div[class^="dialog___"] button');
|
||||||
|
// console.log(btn)
|
||||||
|
// isBtnMoved=true;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* city
|
* city
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('city.php') >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf('city.php') >= 0) {
|
||||||
//todo 1.西部地区的健身房是否翻译? 2.bit's n bobs是否翻译?
|
//todo 1.西部地区的健身房是否翻译? 2.bit's n bobs是否翻译?
|
||||||
const cityOB = new MutationObserver(cityOBInit);
|
const cityOB = new MutationObserver(cityOBInit);
|
||||||
|
|
||||||
@ -3474,7 +3575,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* gym健身房页面
|
* gym健身房页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('gym.php') >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf('gym.php') >= 0) {
|
||||||
const gymOB = new MutationObserver(gymOBInit);
|
const gymOB = new MutationObserver(gymOBInit);
|
||||||
|
|
||||||
function gymOBInit() {
|
function gymOBInit() {
|
||||||
@ -3627,7 +3728,7 @@ padding:16px !important;
|
|||||||
const is_captcha = $$.querySelector('div#tab-menu.captcha') !== null;
|
const is_captcha = $$.querySelector('div#tab-menu.captcha') !== null;
|
||||||
const $title = $('div.content-title');
|
const $title = $('div.content-title');
|
||||||
const $info = $('.info-msg-cont');
|
const $info = $('.info-msg-cont');
|
||||||
if (!is_wh_translate && !is_captcha) {
|
if (!is_wh_translate && !is_captcha && wh_trans_settings.quickCrime) {
|
||||||
if ($title.length > 0) $title.before(dom);
|
if ($title.length > 0) $title.before(dom);
|
||||||
else if ($info.length > 0) $info.before(dom);
|
else if ($info.length > 0) $info.before(dom);
|
||||||
}
|
}
|
||||||
@ -3645,7 +3746,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* 物品页面
|
* 物品页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/item\.php/)) {
|
if (wh_trans_settings.transEnable && window.location.href.contains(/item\.php/)) {
|
||||||
// 标题和右边的链接
|
// 标题和右边的链接
|
||||||
initOB(document.querySelector('.content-title'), {childList: true},
|
initOB(document.querySelector('.content-title'), {childList: true},
|
||||||
() => {
|
() => {
|
||||||
@ -3756,7 +3857,7 @@ padding:16px !important;
|
|||||||
/*
|
/*
|
||||||
npc商店
|
npc商店
|
||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/(shops|bigalgunshop)\.php/)) {
|
if (wh_trans_settings.transEnable && window.location.href.contains(/(shops|bigalgunshop)\.php/)) {
|
||||||
// 标题和右边的链接
|
// 标题和右边的链接
|
||||||
const $cont_title = document.querySelector('.content-title');
|
const $cont_title = document.querySelector('.content-title');
|
||||||
initOB($cont_title, {childList: true, subtree: true},
|
initOB($cont_title, {childList: true, subtree: true},
|
||||||
@ -3892,6 +3993,7 @@ padding:16px !important;
|
|||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/loader\.php\?sid=missions/)) {
|
if (window.location.href.contains(/loader\.php\?sid=missions/)) {
|
||||||
const $$ = $('.content-wrapper');
|
const $$ = $('.content-wrapper');
|
||||||
|
if (wh_trans_settings.missionHint) {
|
||||||
const OB = new MutationObserver(() => {
|
const OB = new MutationObserver(() => {
|
||||||
OB.disconnect();
|
OB.disconnect();
|
||||||
titleTrans();
|
titleTrans();
|
||||||
@ -3904,11 +4006,8 @@ padding:16px !important;
|
|||||||
childList: true
|
childList: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// const taskList = [];
|
|
||||||
const taskList = {};
|
const taskList = {};
|
||||||
// let isCapTaskList = false;
|
|
||||||
const trans = () => {
|
const trans = () => {
|
||||||
// if (!isCapTaskList) {
|
|
||||||
$('ul#giver-tabs a.ui-tabs-anchor').each((i, e) => {
|
$('ul#giver-tabs a.ui-tabs-anchor').each((i, e) => {
|
||||||
if ($(e).children().hasClass('mission-complete-icon')) {
|
if ($(e).children().hasClass('mission-complete-icon')) {
|
||||||
taskList[i] = e.innerText.trim();
|
taskList[i] = e.innerText.trim();
|
||||||
@ -3916,8 +4015,6 @@ padding:16px !important;
|
|||||||
taskList[i] = $(e).clone().children().remove().end().text().trim();
|
taskList[i] = $(e).clone().children().remove().end().text().trim();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// isCapTaskList = true;
|
|
||||||
// }
|
|
||||||
// 助手注入
|
// 助手注入
|
||||||
$('div.max-height-fix.info').each((i, e) => {
|
$('div.max-height-fix.info').each((i, e) => {
|
||||||
if ($(e).find('.wh-translated').length !== 0) return;
|
if ($(e).find('.wh-translated').length !== 0) return;
|
||||||
@ -3939,13 +4036,14 @@ padding:16px !important;
|
|||||||
subtree: true,
|
subtree: true,
|
||||||
childList: true
|
childList: true
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 股票
|
* 股票
|
||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/page\.php\?sid=stocks/)) {
|
if (wh_trans_settings.transEnable && window.location.href.contains(/page\.php\?sid=stocks/)) {
|
||||||
const stockOB = new MutationObserver(() => {
|
const stockOB = new MutationObserver(() => {
|
||||||
stockOB.disconnect();
|
stockOB.disconnect();
|
||||||
titleTrans();
|
titleTrans();
|
||||||
@ -4064,7 +4162,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* 教育页面
|
* 教育页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('education.php') >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf('education.php') >= 0) {
|
||||||
const eduOB = new MutationObserver(eduOBInit);
|
const eduOB = new MutationObserver(eduOBInit);
|
||||||
|
|
||||||
function eduOBInit() {
|
function eduOBInit() {
|
||||||
@ -4162,7 +4260,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* profile 玩家资料页面
|
* profile 玩家资料页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/profiles\.php\?XID=[0-9]+/)) {
|
if (wh_trans_settings.transEnable && window.location.href.contains(/profiles\.php\?XID=[0-9]+/)) {
|
||||||
const $wrapper = document.querySelector('.content-wrapper');
|
const $wrapper = document.querySelector('.content-wrapper');
|
||||||
const profileOB = new MutationObserver(() => {
|
const profileOB = new MutationObserver(() => {
|
||||||
profileOB.disconnect();
|
profileOB.disconnect();
|
||||||
@ -4391,6 +4489,7 @@ padding:16px !important;
|
|||||||
* 报纸
|
* 报纸
|
||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/(newspaper|joblist|freebies|newspaper_class|personals|bounties|comics)\.php/)) {
|
if (window.location.href.contains(/(newspaper|joblist|freebies|newspaper_class|personals|bounties|comics)\.php/)) {
|
||||||
|
if (wh_trans_settings.transEnable) {
|
||||||
const newspaperOB = new MutationObserver(() => {
|
const newspaperOB = new MutationObserver(() => {
|
||||||
newspaperOB.disconnect();
|
newspaperOB.disconnect();
|
||||||
newspaperTrans();
|
newspaperTrans();
|
||||||
@ -4576,11 +4675,12 @@ padding:16px !important;
|
|||||||
newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true});
|
newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* npc买房 estateagents
|
* npc买房 estateagents
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('estateagents.php') >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf('estateagents.php') >= 0) {
|
||||||
titleTrans();
|
titleTrans();
|
||||||
contentTitleLinksTrans();
|
contentTitleLinksTrans();
|
||||||
$('div.estate-info div.title').each((i, e) => {
|
$('div.estate-info div.title').each((i, e) => {
|
||||||
@ -4594,7 +4694,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* properties房屋页面 todo
|
* properties房屋页面 todo
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('properties.php') >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf('properties.php') >= 0) {
|
||||||
const isRent = window.location.href.indexOf('rent') >= 0;
|
const isRent = window.location.href.indexOf('rent') >= 0;
|
||||||
// const isRentOrSell = isRent || window.location.href.indexOf('sell') >= 0;
|
// const isRentOrSell = isRent || window.location.href.indexOf('sell') >= 0;
|
||||||
// const isOption = window.location.href.indexOf('p=options') >= 0;
|
// const isOption = window.location.href.indexOf('p=options') >= 0;
|
||||||
@ -4737,7 +4837,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* 通知页面
|
* 通知页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('events.php') >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf('events.php') >= 0) {
|
||||||
const ob = new MutationObserver(() => {
|
const ob = new MutationObserver(() => {
|
||||||
ob.disconnect();
|
ob.disconnect();
|
||||||
titleTrans();
|
titleTrans();
|
||||||
@ -4772,7 +4872,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* awards.php
|
* awards.php
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('awards.php') >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf('awards.php') >= 0) {
|
||||||
const awOB = new MutationObserver(() => {
|
const awOB = new MutationObserver(() => {
|
||||||
awOB.disconnect();
|
awOB.disconnect();
|
||||||
awTrans();
|
awTrans();
|
||||||
@ -4912,7 +5012,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* preferences设置
|
* preferences设置
|
||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/preferences\.php/)) {
|
if (wh_trans_settings.transEnable && window.location.href.contains(/preferences\.php/)) {
|
||||||
const $$ = $('.content-wrapper');
|
const $$ = $('.content-wrapper');
|
||||||
const OB = new MutationObserver(() => {
|
const OB = new MutationObserver(() => {
|
||||||
OB.disconnect();
|
OB.disconnect();
|
||||||
@ -4983,7 +5083,7 @@ padding:16px !important;
|
|||||||
/*
|
/*
|
||||||
展柜
|
展柜
|
||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/displaycase\.php/)) {
|
if (wh_trans_settings.transEnable && window.location.href.contains(/displaycase\.php/)) {
|
||||||
const $page_wrapper = document.querySelector('#display-page-wrap');
|
const $page_wrapper = document.querySelector('#display-page-wrap');
|
||||||
initOB($page_wrapper, {
|
initOB($page_wrapper, {
|
||||||
subtree: true,
|
subtree: true,
|
||||||
@ -5021,13 +5121,13 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* 升级页面
|
* 升级页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf('level2.php') >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf('level2.php') >= 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 医院页面
|
* 医院页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf("hospitalview.php") >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf("hospitalview.php") >= 0) {
|
||||||
const hospitalOB = new MutationObserver(hosOBInit);
|
const hospitalOB = new MutationObserver(hosOBInit);
|
||||||
|
|
||||||
function hosOBInit() {
|
function hosOBInit() {
|
||||||
@ -5090,7 +5190,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* 帮派页面
|
* 帮派页面
|
||||||
*/
|
*/
|
||||||
if (window.location.href.indexOf("actions.php") >= 0) {
|
if (wh_trans_settings.transEnable && window.location.href.indexOf("actions.php") >= 0) {
|
||||||
const factionOB = new MutationObserver(factionOBInit);
|
const factionOB = new MutationObserver(factionOBInit);
|
||||||
|
|
||||||
function factionOBInit() {
|
function factionOBInit() {
|
||||||
@ -5213,7 +5313,7 @@ padding:16px !important;
|
|||||||
/**
|
/**
|
||||||
* pc电脑
|
* pc电脑
|
||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/pc\.php/)) {
|
if (wh_trans_settings.transEnable && window.location.href.contains(/pc\.php/)) {
|
||||||
const $$ = $('.content-wrapper');
|
const $$ = $('.content-wrapper');
|
||||||
const OB = new MutationObserver(() => {
|
const OB = new MutationObserver(() => {
|
||||||
OB.disconnect();
|
OB.disconnect();
|
||||||
@ -5249,7 +5349,7 @@ padding:16px !important;
|
|||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/calendar\.php/)) {
|
if (window.location.href.contains(/calendar\.php/)) {
|
||||||
const $root = document.querySelectorAll('#calendar-root');
|
const $root = document.querySelectorAll('#calendar-root');
|
||||||
$root.forEach(el => {
|
if (wh_trans_settings.transEnable) $root.forEach(el => {
|
||||||
initOB(el, {childList: true, subtree: true}, () => {
|
initOB(el, {childList: true, subtree: true}, () => {
|
||||||
// 页标题
|
// 页标题
|
||||||
const $h4_title = el.querySelectorAll('h4[class^="title___"]');
|
const $h4_title = el.querySelectorAll('h4[class^="title___"]');
|
||||||
@ -5272,15 +5372,17 @@ padding:16px !important;
|
|||||||
*/
|
*/
|
||||||
if (window.location.href.contains(/christmas_town\.php/)) {
|
if (window.location.href.contains(/christmas_town\.php/)) {
|
||||||
const $root = document.querySelector('#christmastownroot');
|
const $root = document.querySelector('#christmastownroot');
|
||||||
// 标题和右边的链接
|
if (wh_trans_settings.transEnable) {
|
||||||
const $title_wrapper = $root.querySelector('div[class^="appHeaderWrapper___"]');
|
const $title_wrapper = $root.querySelector('div[class^="appHeaderWrapper___"]');
|
||||||
|
// 标题和右边的链接
|
||||||
initOB($title_wrapper, {childList: true, subtree: true},
|
initOB($title_wrapper, {childList: true, subtree: true},
|
||||||
() => {
|
() => {
|
||||||
titleTransReact();
|
titleTransReact();
|
||||||
contentTitleLinksTransReact();
|
contentTitleLinksTransReact();
|
||||||
});
|
});
|
||||||
const $city_wrapper = $root.querySelectorAll('div[class^="core-layout__"]');
|
}
|
||||||
// 解密攻略
|
// 解密攻略
|
||||||
|
if (wh_trans_settings.xmasTownWT) {
|
||||||
const insert_html = `<div id="wh-xmas-cont">
|
const insert_html = `<div id="wh-xmas-cont">
|
||||||
<div class="title-black"><span>水晶球解密地图攻略</span><span><button style="color: white">[隐藏]</button></span></div>
|
<div class="title-black"><span>水晶球解密地图攻略</span><span><button style="color: white">[隐藏]</button></span></div>
|
||||||
<div class="cont-gray select-wrap dropdown-new dropdown-default">
|
<div class="cont-gray select-wrap dropdown-new dropdown-default">
|
||||||
@ -5555,6 +5657,7 @@ margin: 0 0 3px;
|
|||||||
</ul>`,
|
</ul>`,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const $city_wrapper = $root.querySelectorAll('div[class^="core-layout__"]');
|
||||||
$city_wrapper.forEach(el => {
|
$city_wrapper.forEach(el => {
|
||||||
let $wh_container = $root.querySelector('#wh-xmas-cont');
|
let $wh_container = $root.querySelector('#wh-xmas-cont');
|
||||||
if (!$wh_container) {
|
if (!$wh_container) {
|
||||||
@ -5580,7 +5683,9 @@ margin: 0 0 3px;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// 宝箱检测
|
// 宝箱检测
|
||||||
|
if (wh_trans_settings.xmasTownNotify) {
|
||||||
const chestTypeDict = {'1': '金', '2': '银', '3': '铜',};
|
const chestTypeDict = {'1': '金', '2': '银', '3': '铜',};
|
||||||
const chestTypeColorDict = {'1': 'gold', '2': 'silver', '3': 'sandybrown',};
|
const chestTypeColorDict = {'1': 'gold', '2': 'silver', '3': 'sandybrown',};
|
||||||
const lootTypeDict = {'chests': '钥匙箱', 'gifts': '礼物', 'combinationChest': '密码箱', 'keys': '钥匙',};
|
const lootTypeDict = {'chests': '钥匙箱', 'gifts': '礼物', 'combinationChest': '密码箱', 'keys': '钥匙',};
|
||||||
@ -5610,7 +5715,7 @@ margin: 0 0 3px;
|
|||||||
<div><input type="checkbox" id="wh-loot-setting-blink" ${alertSettings.blink === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-blink">闪烁提示</label></div>
|
<div><input type="checkbox" id="wh-loot-setting-blink" ${alertSettings.blink === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-blink">闪烁提示</label></div>
|
||||||
<div><input type="checkbox" id="wh-loot-setting-sound" ${alertSettings.sound === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-sound">声音提示(不支持iOS)</label></div>
|
<div><input type="checkbox" id="wh-loot-setting-sound" ${alertSettings.sound === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-sound">声音提示(不支持iOS)</label></div>
|
||||||
<div><input type="checkbox" id="wh-loot-setting-chest" ${alertSettings.chest === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-chest">不记录需要钥匙的宝箱</label></div>
|
<div><input type="checkbox" id="wh-loot-setting-chest" ${alertSettings.chest === 'y' ? 'checked' : ''} /><label for="wh-loot-setting-chest">不记录需要钥匙的宝箱</label></div>
|
||||||
<div>
|
<div id="wh-hist">
|
||||||
<div id="wh-hist-clear">
|
<div id="wh-hist-clear">
|
||||||
<p><button>清空数据</button>- 如果长时间不清空数据会有奇怪的bug</p>
|
<p><button>清空数据</button>- 如果长时间不清空数据会有奇怪的bug</p>
|
||||||
</div>
|
</div>
|
||||||
@ -5626,7 +5731,9 @@ margin: 0 0 3px;
|
|||||||
#wh-loot-container-main div span img{height: 1em; width: 1em;}
|
#wh-loot-container-main div span img{height: 1em; width: 1em;}
|
||||||
#wh-loot-container-ex{padding: 0.5em;}
|
#wh-loot-container-ex{padding: 0.5em;}
|
||||||
#wh-loot-container-ex.wh-hide{display: none;}
|
#wh-loot-container-ex.wh-hide{display: none;}
|
||||||
|
#wh-loot-container-ex #wh-hist{overflow-x: auto;}
|
||||||
#wh-loot-container-ex table {margin-top: 0.5em;}
|
#wh-loot-container-ex table {margin-top: 0.5em;}
|
||||||
|
#wh-loot-container-ex tbody {background-color: antiquewhite;}
|
||||||
#wh-loot-container-ex table, #wh-loot-container-ex th, #wh-loot-container-ex td {
|
#wh-loot-container-ex table, #wh-loot-container-ex th, #wh-loot-container-ex td {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
@ -5706,7 +5813,10 @@ margin: 0 0 3px;
|
|||||||
ob.disconnect();
|
ob.disconnect();
|
||||||
const $ct_title = $ct_wrap.querySelector('.status-title');
|
const $ct_title = $ct_wrap.querySelector('.status-title');
|
||||||
const $pos = $ct_wrap.querySelector('.map-title span[class^="position___"]') || $ct_wrap.querySelector('.status-title span[class^="position___"]');
|
const $pos = $ct_wrap.querySelector('.map-title span[class^="position___"]') || $ct_wrap.querySelector('.status-title span[class^="position___"]');
|
||||||
if (!$pos) return;
|
if (!$pos) {
|
||||||
|
ob.observe($ct_wrap, {childList: true, subtree: true});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const $pos_spl = $pos.innerText.trim().split(',');
|
const $pos_spl = $pos.innerText.trim().split(',');
|
||||||
const player_position = {};
|
const player_position = {};
|
||||||
player_position.x = parseInt($pos_spl[0]);
|
player_position.x = parseInt($pos_spl[0]);
|
||||||
@ -5714,6 +5824,7 @@ margin: 0 0 3px;
|
|||||||
const $wh_loot_container = $root.querySelector('#wh-loot-container');
|
const $wh_loot_container = $root.querySelector('#wh-loot-container');
|
||||||
if (!$wh_loot_container) {
|
if (!$wh_loot_container) {
|
||||||
console.error('掉落助手未找到DOM容器');
|
console.error('掉落助手未找到DOM容器');
|
||||||
|
ob.observe($ct_wrap, {childList: true, subtree: true});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
|
const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink');
|
||||||
@ -5801,6 +5912,7 @@ margin: 0 0 3px;
|
|||||||
ob.observe($ct_wrap, {childList: true, subtree: true});
|
ob.observe($ct_wrap, {childList: true, subtree: true});
|
||||||
});
|
});
|
||||||
getDOMOb.observe($root, {childList: true, subtree: true});
|
getDOMOb.observe($root, {childList: true, subtree: true});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5813,6 +5925,7 @@ margin: 0 0 3px;
|
|||||||
* @param events
|
* @param events
|
||||||
*/
|
*/
|
||||||
function eventsTrans(events = $('span.mail-link')) {
|
function eventsTrans(events = $('span.mail-link')) {
|
||||||
|
// if (!wh_trans_settings.transEnable) return;
|
||||||
const index = window.location.href.indexOf('events.php#/step=received') >= 0 ? 1 : 0;
|
const index = window.location.href.indexOf('events.php#/step=received') >= 0 ? 1 : 0;
|
||||||
const isReceived = index === 1;
|
const isReceived = index === 1;
|
||||||
// 通知的类型选择栏
|
// 通知的类型选择栏
|
||||||
@ -5861,9 +5974,9 @@ margin: 0 0 3px;
|
|||||||
|
|
||||||
// 通知翻译的开关
|
// 通知翻译的开关
|
||||||
if (!$('div#event-trans-msg').get(0) && !window.location.href.contains(/index\.php/)) {
|
if (!$('div#event-trans-msg').get(0) && !window.location.href.contains(/index\.php/)) {
|
||||||
msgBox(`<div id="event-trans-msg">插件暂时不能翻译全部通知。<br>
|
// msgBox(`<div id="event-trans-msg">插件暂时不能翻译全部通知。<br>
|
||||||
如发现问题请发送通知并联系 <a href="profiles.php?XID=2687093">Woohoo[2687093]</a><br>
|
// 如发现问题请发送通知并联系 <a href="profiles.php?XID=2687093">Woohoo[2687093]</a><br>
|
||||||
<input type="checkbox" id="eventTransCheck" name="eventTransCheck" /><label for="eventTransCheck">开启通知翻译</label> 可能会出现卡顿,默认开启</div>`);
|
// <input type="checkbox" id="eventTransCheck" name="eventTransCheck" /><label for="eventTransCheck">开启通知翻译</label> 可能会出现卡顿,默认开启</div>`);
|
||||||
$('input#eventTransCheck').attr('checked', localStorage.getItem('wh_trans_event') === 'true');
|
$('input#eventTransCheck').attr('checked', localStorage.getItem('wh_trans_event') === 'true');
|
||||||
$('input#eventTransCheck').change(function () {
|
$('input#eventTransCheck').change(function () {
|
||||||
if ($(this).attr('checked') === undefined) {
|
if ($(this).attr('checked') === undefined) {
|
||||||
@ -6839,19 +6952,55 @@ ${htmlCont}</div></div></div></div><hr class="delimiter-999 m-top10 m-bottom10">
|
|||||||
function initIcon() {
|
function initIcon() {
|
||||||
const zhongNode = document.createElement('div');
|
const zhongNode = document.createElement('div');
|
||||||
zhongNode.id = 'wh-trans-icon';
|
zhongNode.id = 'wh-trans-icon';
|
||||||
|
zhongNode.classList.add('cont-gray');
|
||||||
zhongNode.innerHTML =
|
zhongNode.innerHTML =
|
||||||
`<div><button id="wh-trans-icon-btn"></button></div>
|
`<div><button id="wh-trans-icon-btn"></button></div>
|
||||||
<div class="wh-container wh-hide">
|
<div class="wh-container wh-hide">
|
||||||
<div class="wh-main">
|
<div class="wh-main">
|
||||||
<div><b>翻译助手</b></div>
|
<div><b>芜湖的翻译助手</b></div>
|
||||||
|
<div>
|
||||||
|
<div><input type="checkbox" id="wh-trans-enable" ${wh_trans_settings.transEnable ? 'checked' : ''} />
|
||||||
|
<label for="wh-trans-enable">开启翻译</label><span> (施工中)</span>
|
||||||
<div><button id="wh-trans-data-update">更新翻译词库数据</button></div>
|
<div><button id="wh-trans-data-update">更新翻译词库数据</button></div>
|
||||||
<div><p>选项</p></div>
|
</div>
|
||||||
|
<div><input type="checkbox" id="wh-quick-crime" ${wh_trans_settings.quickCrime ? 'checked' : ''} />
|
||||||
|
<label for="wh-quick-crime">快速犯罪</label>
|
||||||
|
</div>
|
||||||
|
<div><input type="checkbox" id="wh-mission-lint" ${wh_trans_settings.missionHint ? 'checked' : ''} />
|
||||||
|
<label for="wh-mission-lint">任务助手</label>
|
||||||
|
</div>
|
||||||
|
<div><input type="checkbox" id="wh-xmastown-wt" ${wh_trans_settings.xmasTownWT ? 'checked' : ''} />
|
||||||
|
<label for="wh-xmastown-wt">圣诞小镇攻略</label>
|
||||||
|
</div>
|
||||||
|
<div><input type="checkbox" id="wh-xmastown-notify" ${wh_trans_settings.xmasTownNotify ? 'checked' : ''} />
|
||||||
|
<label for="wh-xmastown-notify">圣诞小镇物品提示</label>
|
||||||
|
</div>
|
||||||
|
<div><input type="checkbox" id="wh-energy-alert" ${wh_trans_settings.energyAlert ? 'checked' : ''} />
|
||||||
|
<label for="wh-energy-alert">起飞爆E提示</label>
|
||||||
|
</div>
|
||||||
|
<div><input type="checkbox" id="wh-quick-attack" ${wh_trans_settings.quickAtt ? 'checked' : ''} disabled/>
|
||||||
|
<label for="wh-quick-attack">攻击按钮重新定位</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>攻击按钮位置:<select id="wh-quick-attack-index">
|
||||||
|
<option value="pri" ${wh_trans_settings.quichAttIndex === 0 ? 'selected' : ''}>主手</option>
|
||||||
|
<option value="sec" ${wh_trans_settings.quichAttIndex === 1 ? 'selected' : ''}>副手</option>
|
||||||
|
<option value="wea" ${wh_trans_settings.quichAttIndex === 2 ? 'selected' : ''}>近战</option>
|
||||||
|
<option value="gre" ${wh_trans_settings.quichAttIndex === 3 ? 'selected' : ''}>手雷</option>
|
||||||
|
<option value="fis" ${wh_trans_settings.quichAttIndex === 4 ? 'selected' : ''}>拳头</option>
|
||||||
|
<option value="kic" ${wh_trans_settings.quichAttIndex === 5 ? 'selected' : ''}>脚踢</option>
|
||||||
|
</select></label>
|
||||||
|
</div>
|
||||||
|
<div><input type="checkbox" id="wh-dev" ${wh_trans_settings.isDev ? 'checked' : ''} />
|
||||||
|
<label for="wh-dev">开发模式</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
$('body').prepend(zhongNode);
|
$('body').prepend(zhongNode);
|
||||||
zhongNode.querySelector('#wh-trans-icon-btn').onclick = (e) => {
|
zhongNode.querySelector('#wh-trans-icon-btn').onclick = (e) => {
|
||||||
e.target.blur();
|
e.target.blur();
|
||||||
$(e.path[1].nextElementSibling).toggleClass('wh-hide');
|
e.target.parentElement.nextElementSibling.classList.toggle('wh-hide');
|
||||||
};
|
};
|
||||||
let intervalID;
|
let intervalID;
|
||||||
let connected = false;
|
let connected = false;
|
||||||
@ -6877,5 +7026,82 @@ ${htmlCont}</div></div></div></div><hr class="delimiter-999 m-top10 m-bottom10">
|
|||||||
if (e.data === '测试') alert(e.data);
|
if (e.data === '测试') alert(e.data);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
zhongNode.querySelector('#wh-trans-enable').onchange = (e) => {
|
||||||
|
wh_trans_settings.transEnable = e.target.checked;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
zhongNode.querySelector('#wh-quick-crime').onchange = (e) => {
|
||||||
|
wh_trans_settings.quickCrime = e.target.checked;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
zhongNode.querySelector('#wh-mission-lint').onchange = (e) => {
|
||||||
|
wh_trans_settings.missionHint = e.target.checked;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
zhongNode.querySelector('#wh-xmastown-wt').onchange = (e) => {
|
||||||
|
wh_trans_settings.xmasTownWT = e.target.checked;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
zhongNode.querySelector('#wh-xmastown-notify').onchange = (e) => {
|
||||||
|
wh_trans_settings.xmasTownNotify = e.target.checked;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
zhongNode.querySelector('#wh-energy-alert').onchange = (e) => {
|
||||||
|
wh_trans_settings.energyAlert = e.target.checked;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
zhongNode.querySelector('#wh-quick-attack').onchange = (e) => {
|
||||||
|
wh_trans_settings.quickAtt = e.target.checked;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
zhongNode.querySelector('#wh-quick-attack-index').onchange = (e) => {
|
||||||
|
wh_trans_settings.quichAttIndex = e.target.selectedIndex;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
zhongNode.querySelector('#wh-dev').onchange = (e) => {
|
||||||
|
wh_trans_settings.isDev = e.target.checked;
|
||||||
|
saveSettings();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
保存脚本的配置
|
||||||
|
*/
|
||||||
|
function saveSettings() {
|
||||||
|
localStorage.setItem('wh_trans_settings', JSON.stringify(wh_trans_settings))
|
||||||
|
}
|
||||||
|
|
||||||
|
// bool 返回当前是否dev状态
|
||||||
|
function isDev() {
|
||||||
|
return wh_trans_settings.isDev;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waits for an element satisfying selector to exist, then resolves promise with the element.
|
||||||
|
* Useful for resolving race conditions.
|
||||||
|
*
|
||||||
|
* @param selector
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
function elementReady(selector) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let el = document.querySelector(selector);
|
||||||
|
if (el) {
|
||||||
|
resolve(el);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
new MutationObserver((mutationRecords, observer) => {
|
||||||
|
// Query for elements matching the specified selector
|
||||||
|
Array.from(document.querySelectorAll(selector)).forEach((element) => {
|
||||||
|
resolve(element);
|
||||||
|
//Once we have resolved we don't need the observer anymore.
|
||||||
|
observer.disconnect();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.observe(document.documentElement, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user