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(`
${getTaskHint(taskList[i])}
${getTaskHint(taskList[i])}
选项