From e79f094fce163fc8b895949bb9e574591d0c3104 Mon Sep 17 00:00:00 2001 From: woohoo Date: Wed, 29 Dec 2021 00:11:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E9=95=87=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E9=94=99=E8=AF=AF=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E7=9A=84=E5=8A=9F=E8=83=BD=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- torn-trans-zhcn.user.js | 1390 +++++++++++++++++++++++---------------- 1 file changed, 808 insertions(+), 582 deletions(-) diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 0552b46..2c63eb4 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -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,70 +2962,72 @@ padding:16px !important; * 边栏 * 目前默认所有页面调用边栏翻译 */ - let sidebarTimeOut = 60; - const sidebarInterval = setInterval(() => { - // 60秒后取消定时 - if ($('div[class^="sidebar"]').length === 0) { - sidebarTimeOut--; - if (sidebarTimeOut < 0) { - clearInterval(sidebarInterval); + if (wh_trans_settings.transEnable) { + let sidebarTimeOut = 60; + const sidebarInterval = setInterval(() => { + // 60秒后取消定时 + if ($('div[class^="sidebar"]').length === 0) { + sidebarTimeOut--; + if (sidebarTimeOut < 0) { + clearInterval(sidebarInterval); + } + return; } - return; - } - // 边栏块标题 - $('h2[class^="header"]').each((i, e) => { - if (!sidebarDict[e.firstChild.nodeValue]) return; - e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; - // if ($(e).css('display')!=='none' && sidebarDict[e.firstChild.nodeValue]) { - // let original=$(e).clone(true); - // original.text(original.text().replace(e.firstChild.nodeValue,sidebarDict[e.firstChild.nodeValue])); - // $(e).css('display', 'none').after(original); - // $(original).append($(e).children('i')); + // 边栏块标题 + $('h2[class^="header"]').each((i, e) => { + if (!sidebarDict[e.firstChild.nodeValue]) return; + e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; + // if ($(e).css('display')!=='none' && sidebarDict[e.firstChild.nodeValue]) { + // let original=$(e).clone(true); + // original.text(original.text().replace(e.firstChild.nodeValue,sidebarDict[e.firstChild.nodeValue])); + // $(e).css('display', 'none').after(original); + // $(original).append($(e).children('i')); + // } + }); + // 边栏人物名字 + $('span[class^="menu-name"]').each((i, e) => { + e.firstChild.nodeValue = '名字:'; + }); + // 钱 等级 pt 天赋点 + $('p[class^="point-block"]').each((i, e) => { + if (sidebarDict[e.firstChild.firstChild.nodeValue]) + e.firstChild.firstChild.nodeValue = sidebarDict[e.firstChild.firstChild.nodeValue]; + }); + // 4条 状态条 + $('p[class^="bar-name"]').each((i, e) => { + if (sidebarDict[e.firstChild.nodeValue]) + e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; + }); + // 边栏菜单 + $('span[class^="linkName"]').each((i, e) => { + if (sidebarDict[e.firstChild.nodeValue]) + e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; + }); + // [use]按钮 + if ($('#pointsMerits').length !== 0) + $('#pointsMerits')[0].firstChild.nodeValue = '[使用]'; + if ($('#pointsPoints').length !== 0) + $('#pointsPoints')[0].firstChild.nodeValue = '[使用]'; + if ($('#pointsLevel').length !== 0) + $('#pointsLevel')[0].firstChild.nodeValue = '[升级]'; + + // 手机 区域菜单 + $('div[class*="areas-mobile"] span:nth-child(2)').contents().each((i, e) => { + //console.log(e); + if (sidebarDict[e.nodeValue]) + e.nodeValue = sidebarDict[e.nodeValue]; + }); + + // let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); + // if (barDescr.length !== 0) { + // barDescr[0].childNodes.forEach(i => { + // if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue]; + // }) // } - }); - // 边栏人物名字 - $('span[class^="menu-name"]').each((i, e) => { - e.firstChild.nodeValue = '名字:'; - }); - // 钱 等级 pt 天赋点 - $('p[class^="point-block"]').each((i, e) => { - if (sidebarDict[e.firstChild.firstChild.nodeValue]) - e.firstChild.firstChild.nodeValue = sidebarDict[e.firstChild.firstChild.nodeValue]; - }); - // 4条 状态条 - $('p[class^="bar-name"]').each((i, e) => { - if (sidebarDict[e.firstChild.nodeValue]) - e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; - }); - // 边栏菜单 - $('span[class^="linkName"]').each((i, e) => { - if (sidebarDict[e.firstChild.nodeValue]) - e.firstChild.nodeValue = sidebarDict[e.firstChild.nodeValue]; - }); - // [use]按钮 - if ($('#pointsMerits').length !== 0) - $('#pointsMerits')[0].firstChild.nodeValue = '[使用]'; - if ($('#pointsPoints').length !== 0) - $('#pointsPoints')[0].firstChild.nodeValue = '[使用]'; - if ($('#pointsLevel').length !== 0) - $('#pointsLevel')[0].firstChild.nodeValue = '[升级]'; - // 手机 区域菜单 - $('div[class*="areas-mobile"] span:nth-child(2)').contents().each((i, e) => { - //console.log(e); - if (sidebarDict[e.nodeValue]) - e.nodeValue = sidebarDict[e.nodeValue]; - }); - - // let barDescr = $('div[class^="tooltip"]').children('p[class^="bar-descr"]'); - // if (barDescr.length !== 0) { - // barDescr[0].childNodes.forEach(i => { - // if (tooltipDict[i.nodeValue]) i.nodeValue = tooltipDict[i.nodeValue]; - // }) - // } - - clearInterval(sidebarInterval); - }, 1000); + 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,10 +3353,44 @@ padding:16px !important; */ if (window.location.href.contains(/travelagency\.php/)) { const $$ = $('.content-wrapper'); - const OB = new MutationObserver(() => { - OB.disconnect(); - titleTrans(); - contentTitleLinksTrans(); + if (wh_trans_settings.energyAlert) { + const OB = new MutationObserver(() => { + OB.disconnect(); + titleTrans(); + contentTitleLinksTrans(); + trans(); + OB.observe($$.get(0), { + characterData: true, + attributes: true, + subtree: true, + childList: true + }); + }); + const trans = () => { + // 当前能量e + const energyBarStr = $('#barEnergy p[class^="bar-value__"]').text().trim(); + const [curE, maxE] = energyBarStr.split('/').length === 2 + ? [parseInt(energyBarStr.split('/')[0]), parseInt(energyBarStr.split('/')[1])] + : [NaN, NaN]; + const incTime = maxE === 150 ? 10 : 15; + const fullEnergyTime = !(isNaN(curE) || isNaN(maxE)) ? (maxE - 5 - curE) / 5 * incTime + + (incTime - new Date().getMinutes() % incTime) : NaN; + // 起飞前提示 + $('.travel-confirm .travel-question .q-wrap span:nth-of-type(2)').each((i, e) => { + if (isNaN(fullEnergyTime)) return; + const spl = e.innerText.trim().split(' '); + const [hours, minutes] = spl.length === 5 + ? [parseInt(spl[0]), parseInt(spl[3])] + : [0, parseInt(spl[0])]; + if (fullEnergyTime < (hours * 60 + minutes) * 2) { + if (!$(e).parent().hasClass('wh-translated')) { + $(e).parent() + .prepend(`
警告:该次飞行往返时间大于体力回复时间,将会爆体!
`) + .addClass('wh-translated'); + } + } + }); + }; trans(); OB.observe($$.get(0), { characterData: true, @@ -3351,46 +3398,100 @@ padding:16px !important; subtree: true, childList: true }); - }); - const trans = () => { - // 当前能量e - const energyBarStr = $('#barEnergy p[class^="bar-value__"]').text().trim(); - const [curE, maxE] = energyBarStr.split('/').length === 2 - ? [parseInt(energyBarStr.split('/')[0]), parseInt(energyBarStr.split('/')[1])] - : [NaN, NaN]; - const incTime = maxE === 150 ? 10 : 15; - const fullEnergyTime = !(isNaN(curE) || isNaN(maxE)) ? (maxE - 5 - curE) / 5 * incTime - + (incTime - new Date().getMinutes() % incTime) : NaN; - // 起飞前提示 - $('.travel-confirm .travel-question .q-wrap span:nth-of-type(2)').each((i, e) => { - if (isNaN(fullEnergyTime)) return; - const spl = e.innerText.trim().split(' '); - const [hours, minutes] = spl.length === 5 - ? [parseInt(spl[0]), parseInt(spl[3])] - : [0, parseInt(spl[0])]; - if (fullEnergyTime < (hours * 60 + minutes) * 2) { - if (!$(e).parent().hasClass('wh-translated')) { - $(e).parent() - .prepend(`
警告:该次飞行往返时间大于体力回复时间,将会爆体!
`) - .addClass('wh-translated'); - } + } + 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('找不到武器格子,是不是选错了?'); } }); - }; - trans(); - OB.observe($$.get(0), { - characterData: true, - attributes: true, - subtree: true, - childList: true - }); - return; + // 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,10 +3993,42 @@ padding:16px !important; */ if (window.location.href.contains(/loader\.php\?sid=missions/)) { const $$ = $('.content-wrapper'); - const OB = new MutationObserver(() => { - OB.disconnect(); - titleTrans(); - contentTitleLinksTrans(); + if (wh_trans_settings.missionHint) { + const OB = new MutationObserver(() => { + OB.disconnect(); + titleTrans(); + contentTitleLinksTrans(); + trans(); + OB.observe($$.get(0), { + characterData: true, + attributes: true, + subtree: true, + childList: true + }); + }); + const taskList = {}; + const trans = () => { + $('ul#giver-tabs a.ui-tabs-anchor').each((i, e) => { + if ($(e).children().hasClass('mission-complete-icon')) { + taskList[i] = e.innerText.trim(); + } else { + taskList[i] = $(e).clone().children().remove().end().text().trim(); + } + }); + // 助手注入 + $('div.max-height-fix.info').each((i, e) => { + if ($(e).find('.wh-translated').length !== 0) return; + $(e).append(`
任务助手

${getTaskHint(taskList[i])}

`); + }); + // 任务目标 + $('ul.tasks-list span.title-wrap').contents().each((i, e) => { + if (e.nodeType === 3) { + if (missionDict[e.nodeValue.trim()]) { + e.nodeValue = missionDict[e.nodeValue.trim()]; + } + } + }); + }; trans(); OB.observe($$.get(0), { characterData: true, @@ -3903,49 +4036,14 @@ padding:16px !important; subtree: true, 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(); - } else { - 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; - $(e).append(`
任务助手

${getTaskHint(taskList[i])}

`); - }); - // 任务目标 - $('ul.tasks-list span.title-wrap').contents().each((i, e) => { - if (e.nodeType === 3) { - if (missionDict[e.nodeValue.trim()]) { - e.nodeValue = missionDict[e.nodeValue.trim()]; - } - } - }); - }; - trans(); - OB.observe($$.get(0), { - characterData: true, - attributes: true, - 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,196 +4489,198 @@ padding:16px !important; * 报纸 */ if (window.location.href.contains(/(newspaper|joblist|freebies|newspaper_class|personals|bounties|comics)\.php/)) { - const newspaperOB = new MutationObserver(() => { - newspaperOB.disconnect(); - newspaperTrans(); - newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true}); - }); + if (wh_trans_settings.transEnable) { + const newspaperOB = new MutationObserver(() => { + newspaperOB.disconnect(); + newspaperTrans(); + newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true}); + }); - function newspaperTrans() { - titleTrans(); - contentTitleLinksTrans(); - if ($('a.newspaper-link').length === 0) return; - // 导航菜单 - $('a.newspaper-link').contents().each((i, e) => { - if (newspaperDict[e.nodeValue]) - e.nodeValue = newspaperDict[e.nodeValue]; - }); - // 公众号广告 - $('div.price.left').contents()[2].nodeValue = '文章翻译请关注中文公众号Torncity'; - // 日期翻译 - const $date_label = document.querySelector('span.date-label'); - const date_reg = /^[FMSTW][adehinorstuy]+, [ADFJMNOS][abceglnoprtuvy]+ [1-3]?[0-9], 20[0-9][0-9]$/; - if ($date_label && $date_label.innerText.trim().contains(date_reg)) { - const date_format = $date_label.innerText.trim().replaceAll(',', ''); - const date_spl = date_format.split(' '); - const date = {w: date_spl[0], m: date_spl[1], d: date_spl[2], y: date_spl[3]}; - const month_trans = { - 'Jan': 1, - 'Feb': 2, - 'Mar': 3, - 'Apr': 4, - 'May': 5, - 'Jun': 6, - 'Jul': 7, - 'Aug': 8, - 'Sep': 9, - 'Oct': 10, - 'Nov': 11, - 'Dec': 12 - }; - $date_label.innerText = `${date.y}年${month_trans[date.m] || date.m}月${date.d}日`; - } - // 菜单下的信息 工作 壁纸 广告 悬赏 - $('div.help-message').find('*').contents().each((i, e) => { - if (!e.nodeValue || e.nodeValue.trim() === '') return; - if (newspaperDict[e.nodeValue.trim()]) - e.nodeValue = newspaperDict[e.nodeValue.trim()]; - else if (newspaperDict[e.nodeValue.trim().slice(0, 50)]) - e.nodeValue = newspaperDict[e.nodeValue.trim().slice(0, 50)]; - }); - // 右边栏 - $('div[class^="sideCont"] [class^="title"]').contents().each((i, e) => { - if (newspaperDict[e.nodeValue]) - e.nodeValue = newspaperDict[e.nodeValue]; - }); - // 彩票信息 - $('span[class^="winner"]').each((i, e) => { - }); - // 底部链接 - // Why not visit our sponsor? - if (newspaperDict[$('div.link-left').text().trim()]) - $('div.link-left').text(newspaperDict[$('div.link-left').text().trim()]); - // View all | Advertise here - $('div.link-right a').contents().each((i, e) => { - if (newspaperDict[e.nodeValue.trim()]) - e.nodeValue = newspaperDict[e.nodeValue.trim()]; - }) - $('.bounties-list-title li').each((i, e) => { - if (newspaperDict[$(e).text().trim()]) { - $(e).text(newspaperDict[$(e).text().trim()]); + function newspaperTrans() { + titleTrans(); + contentTitleLinksTrans(); + if ($('a.newspaper-link').length === 0) return; + // 导航菜单 + $('a.newspaper-link').contents().each((i, e) => { + if (newspaperDict[e.nodeValue]) + e.nodeValue = newspaperDict[e.nodeValue]; + }); + // 公众号广告 + $('div.price.left').contents()[2].nodeValue = '文章翻译请关注中文公众号Torncity'; + // 日期翻译 + const $date_label = document.querySelector('span.date-label'); + const date_reg = /^[FMSTW][adehinorstuy]+, [ADFJMNOS][abceglnoprtuvy]+ [1-3]?[0-9], 20[0-9][0-9]$/; + if ($date_label && $date_label.innerText.trim().contains(date_reg)) { + const date_format = $date_label.innerText.trim().replaceAll(',', ''); + const date_spl = date_format.split(' '); + const date = {w: date_spl[0], m: date_spl[1], d: date_spl[2], y: date_spl[3]}; + const month_trans = { + 'Jan': 1, + 'Feb': 2, + 'Mar': 3, + 'Apr': 4, + 'May': 5, + 'Jun': 6, + 'Jul': 7, + 'Aug': 8, + 'Sep': 9, + 'Oct': 10, + 'Nov': 11, + 'Dec': 12 + }; + $date_label.innerText = `${date.y}年${month_trans[date.m] || date.m}月${date.d}日`; } - }); - // 交友 - if (window.location.href.contains(/personals/)) { - $('div.personals-wrap span.msg').find('*').contents().each((i, e) => { + // 菜单下的信息 工作 壁纸 广告 悬赏 + $('div.help-message').find('*').contents().each((i, e) => { if (!e.nodeValue || e.nodeValue.trim() === '') return; if (newspaperDict[e.nodeValue.trim()]) e.nodeValue = newspaperDict[e.nodeValue.trim()]; + else if (newspaperDict[e.nodeValue.trim().slice(0, 50)]) + e.nodeValue = newspaperDict[e.nodeValue.trim().slice(0, 50)]; }); - } - // 漫画 - if (window.location.href.contains(/freebies/)) { - if (newspaperDict[$('div.bonus-wrap a').text().trim()]) - $('div.bonus-wrap a').text(newspaperDict[$('div.bonus-wrap a').text().trim()]); - } - // 悬赏 - if (window.location.href.contains(/bounties/)) { - // 列表前的总数 - const $total = $('.bounties-total'); - if ($total.text().contains(/A total of [0-9]+ listings were found/)) { - const num = $total.text().trim().split(' ')[3]; - if (newspaperDict['A total of {$} listings were found.']) { - $total.text(newspaperDict['A total of {$} listings were found.'] - .replace('{$}', num)); + // 右边栏 + $('div[class^="sideCont"] [class^="title"]').contents().each((i, e) => { + if (newspaperDict[e.nodeValue]) + e.nodeValue = newspaperDict[e.nodeValue]; + }); + // 彩票信息 + $('span[class^="winner"]').each((i, e) => { + }); + // 底部链接 + // Why not visit our sponsor? + if (newspaperDict[$('div.link-left').text().trim()]) + $('div.link-left').text(newspaperDict[$('div.link-left').text().trim()]); + // View all | Advertise here + $('div.link-right a').contents().each((i, e) => { + if (newspaperDict[e.nodeValue.trim()]) + e.nodeValue = newspaperDict[e.nodeValue.trim()]; + }) + $('.bounties-list-title li').each((i, e) => { + if (newspaperDict[$(e).text().trim()]) { + $(e).text(newspaperDict[$(e).text().trim()]); } + }); + // 交友 + if (window.location.href.contains(/personals/)) { + $('div.personals-wrap span.msg').find('*').contents().each((i, e) => { + if (!e.nodeValue || e.nodeValue.trim() === '') return; + if (newspaperDict[e.nodeValue.trim()]) + e.nodeValue = newspaperDict[e.nodeValue.trim()]; + }); } - // 列表 - $('.user-info-wrap div *').contents().each((i, e) => { - if (e.nodeType === 3) { - if (newspaperDict[e.nodeValue.trim()]) { - e.nodeValue = newspaperDict[e.nodeValue.trim()]; + // 漫画 + if (window.location.href.contains(/freebies/)) { + if (newspaperDict[$('div.bonus-wrap a').text().trim()]) + $('div.bonus-wrap a').text(newspaperDict[$('div.bonus-wrap a').text().trim()]); + } + // 悬赏 + if (window.location.href.contains(/bounties/)) { + // 列表前的总数 + const $total = $('.bounties-total'); + if ($total.text().contains(/A total of [0-9]+ listings were found/)) { + const num = $total.text().trim().split(' ')[3]; + if (newspaperDict['A total of {$} listings were found.']) { + $total.text(newspaperDict['A total of {$} listings were found.'] + .replace('{$}', num)); } } - }); - // claim - $('ul.bounties-list div.claim button').each((i, e) => { - if (newspaperDict[$(e).text().trim()]) { - $(e).text(newspaperDict[$(e).text().trim()]); - } - }); - $('ul.bounties-list div.claim a').each((i, e) => { - if (newspaperDict[$(e).text().trim()]) { - $(e).text(newspaperDict[$(e).text().trim()]); - } - }); - // 3选项框 - $('.add-bounties-wrap .name').contents().each((i, e) => { - if (e.nodeType === 3) { - if (newspaperDict[e.nodeValue.trim()]) { - e.nodeValue = newspaperDict[e.nodeValue.trim()]; + // 列表 + $('.user-info-wrap div *').contents().each((i, e) => { + if (e.nodeType === 3) { + if (newspaperDict[e.nodeValue.trim()]) { + e.nodeValue = newspaperDict[e.nodeValue.trim()]; + } } - } else if (e.nodeType === 1) { + }); + // claim + $('ul.bounties-list div.claim button').each((i, e) => { if (newspaperDict[$(e).text().trim()]) { $(e).text(newspaperDict[$(e).text().trim()]); } - } - }); - // 匿名选项 - const $anony = $('.choice-container label'); - if (newspaperDict[$anony.text().trim()]) { - $anony.text(newspaperDict[$anony.text().trim()]); - } - // 发钱按钮 - const $$symbol = $('span.input-money-symbol'); - if (sendCashDict[$$symbol.attr('title')]) { - $$symbol.attr('title', sendCashDict[$$symbol.attr('title')]) - } - // 10/10滑动 - const $slider_title = $('.slider-title'); - if ($slider_title.text().contains(/Quantity:/)) { - $slider_title.text($slider_title.text().replace('Quantity', '数量')); - } - // 价钱信息 - $('.confirm-bounties *').contents().each((i, e) => { - if (e.nodeType === 3) { - if (newspaperDict[e.nodeValue.trim()]) { - e.nodeValue = newspaperDict[e.nodeValue.trim()]; + }); + $('ul.bounties-list div.claim a').each((i, e) => { + if (newspaperDict[$(e).text().trim()]) { + $(e).text(newspaperDict[$(e).text().trim()]); } - } - }); - // 下单前确认对话 - $('.confirm-buttons *').contents().each((i, e) => { - if (e.nodeType === 3) { - if (newspaperDict[e.nodeValue.trim()]) { - e.nodeValue = newspaperDict[e.nodeValue.trim()]; - return; - } - switch (i) { - case 7: - case 10: { - if (e.nodeValue.contains(/[0-9] bounties/)) { - e.nodeValue = e.nodeValue.replace('bounties', '次') - } else if (e.nodeValue.contains(/with the reason: .+\?/)) { - e.nodeValue = e.nodeValue.replace('with the reason', '吗,悬赏原因') - } - break; + }); + // 3选项框 + $('.add-bounties-wrap .name').contents().each((i, e) => { + if (e.nodeType === 3) { + if (newspaperDict[e.nodeValue.trim()]) { + e.nodeValue = newspaperDict[e.nodeValue.trim()]; + } + } else if (e.nodeType === 1) { + if (newspaperDict[$(e).text().trim()]) { + $(e).text(newspaperDict[$(e).text().trim()]); } } + }); + // 匿名选项 + const $anony = $('.choice-container label'); + if (newspaperDict[$anony.text().trim()]) { + $anony.text(newspaperDict[$anony.text().trim()]); + } + // 发钱按钮 + const $$symbol = $('span.input-money-symbol'); + if (sendCashDict[$$symbol.attr('title')]) { + $$symbol.attr('title', sendCashDict[$$symbol.attr('title')]) + } + // 10/10滑动 + const $slider_title = $('.slider-title'); + if ($slider_title.text().contains(/Quantity:/)) { + $slider_title.text($slider_title.text().replace('Quantity', '数量')); + } + // 价钱信息 + $('.confirm-bounties *').contents().each((i, e) => { + if (e.nodeType === 3) { + if (newspaperDict[e.nodeValue.trim()]) { + e.nodeValue = newspaperDict[e.nodeValue.trim()]; + } + } + }); + // 下单前确认对话 + $('.confirm-buttons *').contents().each((i, e) => { + if (e.nodeType === 3) { + if (newspaperDict[e.nodeValue.trim()]) { + e.nodeValue = newspaperDict[e.nodeValue.trim()]; + return; + } + switch (i) { + case 7: + case 10: { + if (e.nodeValue.contains(/[0-9] bounties/)) { + e.nodeValue = e.nodeValue.replace('bounties', '次') + } else if (e.nodeValue.contains(/with the reason: .+\?/)) { + e.nodeValue = e.nodeValue.replace('with the reason', '吗,悬赏原因') + } + break; + } + } + } + }); + // place + const $place = $('.place-buttons input'); + if (newspaperDict[$place.attr('value')]) { + $place.attr('value', newspaperDict[$place.attr('value')]); + } + // cancel + const $cancel = $('.place-buttons a.cancel'); + if (newspaperDict[$cancel.text().trim()]) { + $cancel.text(newspaperDict[$cancel.text().trim()]); } - }); - // place - const $place = $('.place-buttons input'); - if (newspaperDict[$place.attr('value')]) { - $place.attr('value', newspaperDict[$place.attr('value')]); - } - // cancel - const $cancel = $('.place-buttons a.cancel'); - if (newspaperDict[$cancel.text().trim()]) { - $cancel.text(newspaperDict[$cancel.text().trim()]); } } - } - newspaperTrans(); - newspaperOB.observe($('div.content-wrapper')[0], {childList: true, subtree: true}); - return; + newspaperTrans(); + 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,16 +5372,18 @@ padding:16px !important; */ if (window.location.href.contains(/christmas_town\.php/)) { const $root = document.querySelector('#christmastownroot'); - // 标题和右边的链接 - 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.transEnable) { + const $title_wrapper = $root.querySelector('div[class^="appHeaderWrapper___"]'); + // 标题和右边的链接 + initOB($title_wrapper, {childList: true, subtree: true}, + () => { + titleTransReact(); + contentTitleLinksTransReact(); + }); + } // 解密攻略 - const insert_html = `
+ if (wh_trans_settings.xmasTownWT) { + const insert_html = `
水晶球解密地图攻略
-
+

- 如果长时间不清空数据会有奇怪的bug

历史记录
坐标地图类型发现获取
-
+
@@ -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; @@ -5647,160 +5754,165 @@ margin: 0 0 3px; 100% {background: #f2f2f2} } `; - $($ct_wrap).before(insert_html); + $($ct_wrap).before(insert_html); + const $wh_loot_container = $root.querySelector('#wh-loot-container'); + const $btn = $wh_loot_container.querySelector('#wh-loot-btn button'); + const $clear_btn = $wh_loot_container.querySelector('#wh-hist-clear button'); + const $ex = $wh_loot_container.querySelector('#wh-loot-container-ex'); + const $tbody = $wh_loot_container.querySelector('tbody'); + const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink'); + const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound'); + const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest'); + const $audio = $wh_loot_container.querySelector('audio'); + $btn.onclick = e => { + e.target.innerText = e.target.innerText === '设置' ? '收起' : '设置'; + $($ex).toggleClass('wh-hide'); + e.target.blur(); + }; + $clear_btn.onclick = e => { + e.target.blur(); + dropHist = {}; + $tbody.innerHTML = ''; + localStorage.setItem('wh-loot-store', JSON.stringify(dropHist)); + }; + $blink.onchange = e => { + if (e.target.checked) { + alertSettings.blink = 'y'; + if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') { + $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite'; + } + } else { + alertSettings.blink = 'n'; + $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = ''; + } + localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); + }; + $sound.onchange = e => { + if (e.target.checked) { + alertSettings.sound = 'y'; + if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') { + soundLoopFlag = true; + } + } else { + alertSettings.sound = 'n'; + soundLoopFlag = false; + } + localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); + }; + $chest.onchange = e => { + alertSettings.chest = e.target.checked ? 'y' : 'n'; + localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); + }; + const soundIntervalID = window.setInterval(() => { + if (soundLoopFlag) $audio.play().then(); + }, 1200); + ob.observe($ct_wrap, {childList: true, subtree: true}); + } + }); + const ob = new MutationObserver(() => { + 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) { + 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]); + player_position.y = parseInt($pos_spl[1]); const $wh_loot_container = $root.querySelector('#wh-loot-container'); - const $btn = $wh_loot_container.querySelector('#wh-loot-btn button'); - const $clear_btn = $wh_loot_container.querySelector('#wh-hist-clear button'); - const $ex = $wh_loot_container.querySelector('#wh-loot-container-ex'); - const $tbody = $wh_loot_container.querySelector('tbody'); + 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'); const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound'); const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest'); - const $audio = $wh_loot_container.querySelector('audio'); - $btn.onclick = e => { - e.target.innerText = e.target.innerText === '设置' ? '收起' : '设置'; - $($ex).toggleClass('wh-hide'); - e.target.blur(); - }; - $clear_btn.onclick = e => { - e.target.blur(); - dropHist = {}; - $tbody.innerHTML = ''; - localStorage.setItem('wh-loot-store', JSON.stringify(dropHist)); - }; - $blink.onchange = e => { - if (e.target.checked) { - alertSettings.blink = 'y'; - if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') { - $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite'; - } + const $tbody = $wh_loot_container.querySelector('tbody'); + const nearby_arr = []; + const items = $root.querySelectorAll('div.grid-layer div.items-layer div.ct-item'); + // 附近的所有物品 + items.forEach(el => { + const item_props = {x: 0, y: 0, name: '', type: '', url: '',}; + item_props.x = parseInt(el.style.left.replaceAll('px', '')) / 30; + item_props.y = -parseInt(el.style.top.replaceAll('px', '')) / 30; + item_props.url = el.firstElementChild.src; + const srcSpl = item_props.url.trim().split('/'); + item_props.name = srcSpl[6]; + item_props.type = srcSpl[8].slice(0, 1); + nearby_arr.push(item_props); + }); + const $wh_loot_container_items = $wh_loot_container.querySelector('#wh-loot-container-items'); + const $wh_loot_container_chests = $wh_loot_container.querySelector('#wh-loot-container-chests'); + let item_count = 0, chest_count = 0; + $wh_loot_container_items.innerHTML = ''; + $wh_loot_container_chests.innerHTML = ''; + nearby_arr.forEach(nearby_item => { + let path = '='; + if (nearby_item.x < player_position.x && nearby_item.y < player_position.y) path = '↙'; + else if (nearby_item.x < player_position.x && nearby_item.y === player_position.y) path = '←'; + else if (nearby_item.x < player_position.x && nearby_item.y > player_position.y) path = '↖'; + else if (nearby_item.x === player_position.x && nearby_item.y > player_position.y) path = '↑'; + else if (nearby_item.x > player_position.x && nearby_item.y > player_position.y) path = '↗'; + else if (nearby_item.x > player_position.x && nearby_item.y === player_position.y) path = '→'; + else if (nearby_item.x > player_position.x && nearby_item.y < player_position.y) path = '↘'; + else if (nearby_item.x === player_position.x && nearby_item.y < player_position.y) path = '↓'; + let item_name; + if (nearby_item.name === 'chests') { + chest_count++; + item_name = chestTypeDict[nearby_item.type] + lootTypeDict[nearby_item.name]; + $wh_loot_container_chests.innerHTML += `${path}[${nearby_item.x},${nearby_item.y}] ${item_name}` } else { - alertSettings.blink = 'n'; - $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = ''; + item_count++; + item_name = (nearby_item.name === 'keys' ? keyTypeDict[nearby_item.type] || '' : '') + lootTypeDict[nearby_item.name] || nearby_item.name; + $wh_loot_container_items.innerHTML += `${path}[${nearby_item.x},${nearby_item.y}] ${item_name}` } - localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); - }; - $sound.onchange = e => { - if (e.target.checked) { - alertSettings.sound = 'y'; - if ($wh_loot_container.querySelector('#wh-loot-item-count').innerText !== '(0)') { - soundLoopFlag = true; + // 确认地图坐标存在 + if ($ct_title) { + const hist_key = `[${nearby_item.x},${nearby_item.y}]"${$ct_title.firstChild.nodeValue.trim()}"${item_name}`; + const el = dropHist[hist_key]; + if (el) { + if (path === '=' && (nearby_item.name === 'keys' || nearby_item.name === 'gifts')) { + el.isPassed = true; + } + } else { + if (!(nearby_item.name === 'chests' && $chest.checked)) { + const now = new Date(); + dropHist[hist_key] = { + pos: `[${nearby_item.x},${nearby_item.y}]`, + map: $ct_title.firstChild.nodeValue.trim(), + last: `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`, + name: item_name, + id: Object.keys(dropHist).length, + }; + } } - } else { - alertSettings.sound = 'n'; - soundLoopFlag = false; } - localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); - }; - $chest.onchange = e => { - alertSettings.chest = e.target.checked ? 'y' : 'n'; - localStorage.setItem('wh-loot-setting', JSON.stringify(alertSettings)); - }; - const soundIntervalID = window.setInterval(() => { - if (soundLoopFlag) $audio.play().then(); - }, 1200); - ob.observe($ct_wrap, {childList: true, subtree: true}); - } - }); - const ob = new MutationObserver(() => { - 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; - const $pos_spl = $pos.innerText.trim().split(','); - const player_position = {}; - player_position.x = parseInt($pos_spl[0]); - player_position.y = parseInt($pos_spl[1]); - const $wh_loot_container = $root.querySelector('#wh-loot-container'); - if (!$wh_loot_container) { - console.error('掉落助手未找到DOM容器'); - return; - } - const $blink = $wh_loot_container.querySelector('#wh-loot-setting-blink'); - const $sound = $wh_loot_container.querySelector('#wh-loot-setting-sound'); - const $chest = $wh_loot_container.querySelector('#wh-loot-setting-chest'); - const $tbody = $wh_loot_container.querySelector('tbody'); - const nearby_arr = []; - const items = $root.querySelectorAll('div.grid-layer div.items-layer div.ct-item'); - // 附近的所有物品 - items.forEach(el => { - const item_props = {x: 0, y: 0, name: '', type: '', url: '',}; - item_props.x = parseInt(el.style.left.replaceAll('px', '')) / 30; - item_props.y = -parseInt(el.style.top.replaceAll('px', '')) / 30; - item_props.url = el.firstElementChild.src; - const srcSpl = item_props.url.trim().split('/'); - item_props.name = srcSpl[6]; - item_props.type = srcSpl[8].slice(0, 1); - nearby_arr.push(item_props); - }); - const $wh_loot_container_items = $wh_loot_container.querySelector('#wh-loot-container-items'); - const $wh_loot_container_chests = $wh_loot_container.querySelector('#wh-loot-container-chests'); - let item_count = 0, chest_count = 0; - $wh_loot_container_items.innerHTML = ''; - $wh_loot_container_chests.innerHTML = ''; - nearby_arr.forEach(nearby_item => { - let path = '='; - if (nearby_item.x < player_position.x && nearby_item.y < player_position.y) path = '↙'; - else if (nearby_item.x < player_position.x && nearby_item.y === player_position.y) path = '←'; - else if (nearby_item.x < player_position.x && nearby_item.y > player_position.y) path = '↖'; - else if (nearby_item.x === player_position.x && nearby_item.y > player_position.y) path = '↑'; - else if (nearby_item.x > player_position.x && nearby_item.y > player_position.y) path = '↗'; - else if (nearby_item.x > player_position.x && nearby_item.y === player_position.y) path = '→'; - else if (nearby_item.x > player_position.x && nearby_item.y < player_position.y) path = '↘'; - else if (nearby_item.x === player_position.x && nearby_item.y < player_position.y) path = '↓'; - let item_name; - if (nearby_item.name === 'chests') { - chest_count++; - item_name = chestTypeDict[nearby_item.type] + lootTypeDict[nearby_item.name]; - $wh_loot_container_chests.innerHTML += `${path}[${nearby_item.x},${nearby_item.y}] ${item_name}` + }); + $wh_loot_container.querySelector('#wh-loot-item-count').innerText = `(${item_count})`; + if (item_count === 0) { + $wh_loot_container_items.innerText = '暂无'; + $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = ''; + soundLoopFlag = false; } else { - item_count++; - item_name = (nearby_item.name === 'keys' ? keyTypeDict[nearby_item.type] || '' : '') + lootTypeDict[nearby_item.name] || nearby_item.name; - $wh_loot_container_items.innerHTML += `${path}[${nearby_item.x},${nearby_item.y}] ${item_name}` - } - // 确认地图坐标存在 - if ($ct_title) { - const hist_key = `[${nearby_item.x},${nearby_item.y}]"${$ct_title.firstChild.nodeValue.trim()}"${item_name}`; - const el = dropHist[hist_key]; - if (el) { - if (path === '=' && (nearby_item.name === 'keys' || nearby_item.name === 'gifts')) { - el.isPassed = true; - } - } else { - if (!(nearby_item.name === 'chests' && $chest.checked)) { - const now = new Date(); - dropHist[hist_key] = { - pos: `[${nearby_item.x},${nearby_item.y}]`, - map: $ct_title.firstChild.nodeValue.trim(), - last: `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`, - name: item_name, - id: Object.keys(dropHist).length, - }; - } - } + if ($blink.checked) $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite'; + if ($sound.checked) soundLoopFlag = true; } + $wh_loot_container.querySelector('#wh-loot-chest-count').innerText = `(${chest_count})`; + if (chest_count === 0) $wh_loot_container_chests.innerText = '暂无'; + const history = Object.keys(dropHist).map(key => dropHist[key]).sort((a, b) => a.id - b.id); + let table_html = ''; + history.forEach(e => { + table_html += `${e.pos}${e.map}${e.name}${e.last}${e.isPassed ? '已取得' : '不确定'}`; + }); + $tbody.innerHTML = table_html; + localStorage.setItem('wh-loot-store', JSON.stringify(dropHist)); + ob.observe($ct_wrap, {childList: true, subtree: true}); }); - $wh_loot_container.querySelector('#wh-loot-item-count').innerText = `(${item_count})`; - if (item_count === 0) { - $wh_loot_container_items.innerText = '暂无'; - $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = ''; - soundLoopFlag = false; - } else { - if ($blink.checked) $wh_loot_container.querySelector('#wh-loot-container-main').style.animation = 'lootFoundAlert 2s infinite'; - if ($sound.checked) soundLoopFlag = true; - } - $wh_loot_container.querySelector('#wh-loot-chest-count').innerText = `(${chest_count})`; - if (chest_count === 0) $wh_loot_container_chests.innerText = '暂无'; - const history = Object.keys(dropHist).map(key => dropHist[key]).sort((a, b) => a.id - b.id); - let table_html = ''; - history.forEach(e => { - table_html += `${e.pos}${e.map}${e.name}${e.last}${e.isPassed ? '已取得' : '不确定'}`; - }); - $tbody.innerHTML = table_html; - localStorage.setItem('wh-loot-store', JSON.stringify(dropHist)); - ob.observe($ct_wrap, {childList: true, subtree: true}); - }); - getDOMOb.observe($root, {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(`
插件暂时不能翻译全部通知。
-如发现问题请发送通知并联系 Woohoo[2687093]
- 可能会出现卡顿,默认开启
`); +// msgBox(`
插件暂时不能翻译全部通知。
+// 如发现问题请发送通知并联系 Woohoo[2687093]
+// 可能会出现卡顿,默认开启
`); $('input#eventTransCheck').attr('checked', localStorage.getItem('wh_trans_event') === 'true'); $('input#eventTransCheck').change(function () { if ($(this).attr('checked') === undefined) { @@ -6839,19 +6952,55 @@ ${htmlCont}
function initIcon() { const zhongNode = document.createElement('div'); zhongNode.id = 'wh-trans-icon'; + zhongNode.classList.add('cont-gray'); zhongNode.innerHTML = `
-
翻译助手
-
-

选项

+
芜湖的翻译助手
+
+
+ (施工中) +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
`; $('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}
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 + }); + }); } }());