修复小镇提示的错误,添加脚本的功能配置

This commit is contained in:
woohoo 2021-12-29 00:11:04 +08:00
parent b1f09a502a
commit e79f094fce

View File

@ -1,8 +1,8 @@
// ==UserScript==
// @lastmodified 202112272108
// @lastmodified 202112290010
// @name Torn翻译
// @namespace WOOH
// @version 0.1.1227a
// @version 0.1.1229a
// @description Torn UI翻译
// @author Woohoo-[2687093] sabrina_devil[2696209]
// @match https://www.torn.com/*
@ -23,6 +23,11 @@
todo: true,
cont: `baza npc商店 imarket及imarket搜索结果`,
},
{
ver: '0.1.1229a',
date: '20211229',
cont: `修复小镇提示的错误,添加脚本的功能配置`,
},
{
ver: '0.1.1227a',
date: '20211227',
@ -2864,6 +2869,7 @@
// transDict.calDict = calDict;
// if (!localStorage.getItem('wh_trans_transDict')) localStorage.setItem('wh_trans_transDict', JSON.stringify(transDict))
const mobile = window.innerWidth <= 600;
// 左侧标签
const zhongIconIntervalID = window.setInterval(() => {
if (!document.querySelector('#wh-trans-icon')) initIcon();
@ -2871,24 +2877,32 @@
const wh_trans_settings = localStorage.getItem('wh_trans_settings')
? JSON.parse(localStorage.getItem('wh_trans_settings'))
: {
transEnable: true,
attBtnPos: 2,
transEnable: false,
quickCrime: true,
missionHint: true,
xmasTownWT: true,
xmasTownNotify: true,
energyAlert: true,
quickAtt: false,
quichAttIndex: 2,
isDev: false,
};
// const quickAttArr = ['pri', 'sec', 'wea', 'gre', 'fis', 'kic'];
initIcon();
addStyle(
`#wh-trans-icon{
addStyle(`#wh-trans-icon{
display: inline-block;
position: fixed;
top: 50%;
top: calc(50% - 100px);
left: 0;
z-index: 10;
background-color: white;
z-index: 20000;
border: solid 1px #b5b5b5;
border-left: none;
border-radius: 0 4px 4px 0;
max-width: 200px;
}
#wh-trans-icon input{
margin:0 4px 0 0;
}
#wh-trans-icon button{
margin:0;
padding:0;
@ -2907,11 +2921,6 @@ padding:16px !important;
}
.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;
const sidebarInterval = setInterval(() => {
// 60秒后取消定时
@ -3017,6 +3027,7 @@ padding:16px !important;
clearInterval(sidebarInterval);
}, 1000);
}
/**
* 迷你资料卡 全局 todo
@ -3069,12 +3080,12 @@ padding:16px !important;
// }
// }, 1000);
};
miniProfile();
if (wh_trans_settings.transEnable) miniProfile();
/**
* header
*/
if ($('div#header-root').length > 0) {
if (wh_trans_settings.transEnable && document.querySelector('div#header-root')) {
const headerOB = new MutationObserver(_ => {
headerOB.disconnect();
headerTrans();
@ -3157,7 +3168,7 @@ padding:16px !important;
/**
* chatbox
*/
if ($('div#chatRoot').length > 0) {
if (wh_trans_settings.transEnable && document.querySelector('div#chatRoot')) {
const chatOB = new MutationObserver(_ => {
chatOB.disconnect();
chatTrans();
@ -3239,13 +3250,14 @@ padding:16px !important;
});
psbtOB.observe(document.body, opt);
}
playerSearchBoxTrans();
if (wh_trans_settings.transEnable) playerSearchBoxTrans();
/**
* 飞行页面
*/
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);
function travelOBInit() {
@ -3283,8 +3295,9 @@ padding:16px !important;
/**
* 主页 todo
*/
if (window.location.href.indexOf('index.php') >= 0 &&
$('h4#skip-to-content').text().indexOf('Home') >= 0) {
if (wh_trans_settings.transEnable &&
window.location.href.contains(/index\.php/) &&
document.querySelector('h4#skip-to-content').innerText.contains(/Home/)) {
titleTrans();
contentTitleLinksTrans();
@ -3340,6 +3353,7 @@ padding:16px !important;
*/
if (window.location.href.contains(/travelagency\.php/)) {
const $$ = $('.content-wrapper');
if (wh_trans_settings.energyAlert) {
const OB = new MutationObserver(() => {
OB.disconnect();
titleTrans();
@ -3384,13 +3398,100 @@ padding:16px !important;
subtree: true,
childList: true
});
}
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
*/
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是否翻译
const cityOB = new MutationObserver(cityOBInit);
@ -3474,7 +3575,7 @@ padding:16px !important;
/**
* 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);
function gymOBInit() {
@ -3627,7 +3728,7 @@ padding:16px !important;
const is_captcha = $$.querySelector('div#tab-menu.captcha') !== null;
const $title = $('div.content-title');
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);
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},
() => {
@ -3756,7 +3857,7 @@ padding:16px !important;
/*
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');
initOB($cont_title, {childList: true, subtree: true},
@ -3892,6 +3993,7 @@ padding:16px !important;
*/
if (window.location.href.contains(/loader\.php\?sid=missions/)) {
const $$ = $('.content-wrapper');
if (wh_trans_settings.missionHint) {
const OB = new MutationObserver(() => {
OB.disconnect();
titleTrans();
@ -3904,11 +4006,8 @@ padding:16px !important;
childList: true
});
});
// const taskList = [];
const taskList = {};
// let isCapTaskList = false;
const trans = () => {
// if (!isCapTaskList) {
$('ul#giver-tabs a.ui-tabs-anchor').each((i, e) => {
if ($(e).children().hasClass('mission-complete-icon')) {
taskList[i] = e.innerText.trim();
@ -3916,8 +4015,6 @@ padding:16px !important;
taskList[i] = $(e).clone().children().remove().end().text().trim();
}
});
// isCapTaskList = true;
// }
// 助手注入
$('div.max-height-fix.info').each((i, e) => {
if ($(e).find('.wh-translated').length !== 0) return;
@ -3939,13 +4036,14 @@ padding:16px !important;
subtree: true,
childList: true
});
}
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(() => {
stockOB.disconnect();
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);
function eduOBInit() {
@ -4162,7 +4260,7 @@ padding:16px !important;
/**
* 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 profileOB = new MutationObserver(() => {
profileOB.disconnect();
@ -4391,6 +4489,7 @@ padding:16px !important;
* 报纸
*/
if (window.location.href.contains(/(newspaper|joblist|freebies|newspaper_class|personals|bounties|comics)\.php/)) {
if (wh_trans_settings.transEnable) {
const newspaperOB = new MutationObserver(() => {
newspaperOB.disconnect();
newspaperTrans();
@ -4576,11 +4675,12 @@ padding:16px !important;
newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true});
return;
}
}
/**
* npc买房 estateagents
*/
if (window.location.href.indexOf('estateagents.php') >= 0) {
if (wh_trans_settings.transEnable && window.location.href.indexOf('estateagents.php') >= 0) {
titleTrans();
contentTitleLinksTrans();
$('div.estate-info div.title').each((i, e) => {
@ -4594,7 +4694,7 @@ padding:16px !important;
/**
* 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 isRentOrSell = isRent || window.location.href.indexOf('sell') >= 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(() => {
ob.disconnect();
titleTrans();
@ -4772,7 +4872,7 @@ padding:16px !important;
/**
* 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(() => {
awOB.disconnect();
awTrans();
@ -4912,7 +5012,7 @@ padding:16px !important;
/**
* preferences设置
*/
if (window.location.href.contains(/preferences\.php/)) {
if (wh_trans_settings.transEnable && window.location.href.contains(/preferences\.php/)) {
const $$ = $('.content-wrapper');
const OB = new MutationObserver(() => {
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');
initOB($page_wrapper, {
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);
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);
function factionOBInit() {
@ -5213,7 +5313,7 @@ padding:16px !important;
/**
* pc电脑
*/
if (window.location.href.contains(/pc\.php/)) {
if (wh_trans_settings.transEnable && window.location.href.contains(/pc\.php/)) {
const $$ = $('.content-wrapper');
const OB = new MutationObserver(() => {
OB.disconnect();
@ -5249,7 +5349,7 @@ padding:16px !important;
*/
if (window.location.href.contains(/calendar\.php/)) {
const $root = document.querySelectorAll('#calendar-root');
$root.forEach(el => {
if (wh_trans_settings.transEnable) $root.forEach(el => {
initOB(el, {childList: true, subtree: true}, () => {
// 页标题
const $h4_title = el.querySelectorAll('h4[class^="title___"]');
@ -5272,15 +5372,17 @@ padding:16px !important;
*/
if (window.location.href.contains(/christmas_town\.php/)) {
const $root = document.querySelector('#christmastownroot');
// 标题和右边的链接
if (wh_trans_settings.transEnable) {
const $title_wrapper = $root.querySelector('div[class^="appHeaderWrapper___"]');
// 标题和右边的链接
initOB($title_wrapper, {childList: true, subtree: true},
() => {
titleTransReact();
contentTitleLinksTransReact();
});
const $city_wrapper = $root.querySelectorAll('div[class^="core-layout__"]');
}
// 解密攻略
if (wh_trans_settings.xmasTownWT) {
const insert_html = `<div id="wh-xmas-cont">
<div class="title-black"><span>水晶球解密地图攻略</span><span><button style="color: white">[]</button></span></div>
<div class="cont-gray select-wrap dropdown-new dropdown-default">
@ -5555,6 +5657,7 @@ margin: 0 0 3px;
</ul>`,
},
};
const $city_wrapper = $root.querySelectorAll('div[class^="core-layout__"]');
$city_wrapper.forEach(el => {
let $wh_container = $root.querySelector('#wh-xmas-cont');
if (!$wh_container) {
@ -5580,7 +5683,9 @@ margin: 0 0 3px;
});
}
});
}
// 宝箱检测
if (wh_trans_settings.xmasTownNotify) {
const chestTypeDict = {'1': '金', '2': '银', '3': '铜',};
const chestTypeColorDict = {'1': 'gold', '2': 'silver', '3': 'sandybrown',};
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-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>
<div id="wh-hist">
<div id="wh-hist-clear">
<p><button>清空数据</button>- bug</p>
</div>
@ -5626,7 +5731,9 @@ margin: 0 0 3px;
#wh-loot-container-main div span img{height: 1em; width: 1em;}
#wh-loot-container-ex{padding: 0.5em;}
#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 tbody {background-color: antiquewhite;}
#wh-loot-container-ex table, #wh-loot-container-ex th, #wh-loot-container-ex td {
padding: 5px;
border: 1px solid black;
@ -5706,7 +5813,10 @@ margin: 0 0 3px;
ob.disconnect();
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___"]');
if (!$pos) return;
if (!$pos) {
ob.observe($ct_wrap, {childList: true, subtree: true});
return;
}
const $pos_spl = $pos.innerText.trim().split(',');
const player_position = {};
player_position.x = parseInt($pos_spl[0]);
@ -5714,6 +5824,7 @@ margin: 0 0 3px;
const $wh_loot_container = $root.querySelector('#wh-loot-container');
if (!$wh_loot_container) {
console.error('掉落助手未找到DOM容器');
ob.observe($ct_wrap, {childList: true, subtree: true});
return;
}
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});
});
getDOMOb.observe($root, {childList: true, subtree: true});
}
return;
}
@ -5813,6 +5925,7 @@ margin: 0 0 3px;
* @param events
*/
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 isReceived = index === 1;
// 通知的类型选择栏
@ -5861,9 +5974,9 @@ margin: 0 0 3px;
// 通知翻译的开关
if (!$('div#event-trans-msg').get(0) && !window.location.href.contains(/index\.php/)) {
msgBox(`<div id="event-trans-msg">插件暂时不能翻译全部通知。<br>
如发现问题请发送通知并联系 <a href="profiles.php?XID=2687093">Woohoo[2687093]</a><br>
<input type="checkbox" id="eventTransCheck" name="eventTransCheck" /><label for="eventTransCheck">开启通知翻译</label> </div>`);
// msgBox(`<div id="event-trans-msg">插件暂时不能翻译全部通知。<br>
// 如发现问题请发送通知并联系 <a href="profiles.php?XID=2687093">Woohoo[2687093]</a><br>
// <input type="checkbox" id="eventTransCheck" name="eventTransCheck" /><label for="eventTransCheck">开启通知翻译</label> 可能会出现卡顿,默认开启</div>`);
$('input#eventTransCheck').attr('checked', localStorage.getItem('wh_trans_event') === 'true');
$('input#eventTransCheck').change(function () {
if ($(this).attr('checked') === undefined) {
@ -6839,19 +6952,55 @@ ${htmlCont}</div></div></div></div><hr class="delimiter-999 m-top10 m-bottom10">
function initIcon() {
const zhongNode = document.createElement('div');
zhongNode.id = 'wh-trans-icon';
zhongNode.classList.add('cont-gray');
zhongNode.innerHTML =
`<div><button id="wh-trans-icon-btn"></button></div>
<div class="wh-container wh-hide">
<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><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>`;
$('body').prepend(zhongNode);
zhongNode.querySelector('#wh-trans-icon-btn').onclick = (e) => {
e.target.blur();
$(e.path[1].nextElementSibling).toggleClass('wh-hide');
e.target.parentElement.nextElementSibling.classList.toggle('wh-hide');
};
let intervalID;
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);
}
}, 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
});
});
}
}());