diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 69c6fc0..7b9ecd1 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -1,8 +1,8 @@ // ==UserScript== -// @lastmodified 202112302200 +// @lastmodified 202201041738 // @name Torn翻译 // @namespace WOOH -// @version 0.1.1230a +// @version 0.2.0104a // @description Torn UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* @@ -21,6 +21,11 @@ todo: true, cont: `baza npc商店 imarket及imarket搜索结果`, }, + { + ver: '0.2.0104a', + date: '20220104', + cont: `增加了“光速拔刀”、“光速跑路”功能`, + }, { ver: '0.1.1230a', date: '20211230', @@ -2877,7 +2882,11 @@ // transDict.calDict = calDict; // if (!localStorage.getItem('wh_trans_transDict')) localStorage.setItem('wh_trans_transDict', JSON.stringify(transDict)) - const mobile = window.innerWidth <= 600; + // const mobile = window.innerWidth <= 600; + let device; + if (window.innerWidth > 1000) device = 'pc'; + else if (window.innerWidth <= 600) device = 'mobile'; + else device = 'tablet'; const settingsArr = [ { domType: 'checkbox', @@ -2955,19 +2964,13 @@ { domType: 'checkbox', domId: 'wh-attack-relocate', - domText: ' 攻击错误转跳', + domText: ' 真·攻击界面转跳', dictName: 'attRelocate', }, - { - domType: 'checkbox', - domId: 'wh-quick-attack', - domText: ' 攻击按钮重定位', - dictName: 'quickAtt', - }, { domType: 'select', domId: 'wh-quick-attack-index', - domText: '攻击按钮位置 ', + domText: '光速拔刀 ', domSelectOpt: [ { domVal: 'pri', @@ -2993,8 +2996,36 @@ domVal: 'kic', domText: '--脚踢--', }, + { + domVal: 'none', + domText: '--关闭--', + }, ], - dictName: 'quichAttIndex', + dictName: 'quickAttIndex', + }, + { + domType: 'select', + domId: 'wh-quick-mug', + domText: '光速跑路 ', + domSelectOpt: [ + { + domVal: 'leave', + domText: '跑路(LEAVE)', + }, + { + domVal: 'mug', + domText: '打劫(MUG)', + }, + { + domVal: 'hosp', + domText: '住院(HOSP)', + }, + { + domVal: 'none', + domText: '关闭', + }, + ], + dictName: 'quickFinishAtt', }, { domType: 'checkbox', @@ -3016,8 +3047,9 @@ xmasTownWT: true, xmasTownNotify: true, energyAlert: true, - quickAtt: false, - quichAttIndex: 2, + // quickAtt: false, + quickAttIndex: 2, + quickFinishAtt: 4, attRelocate: true, isDev: false, }; @@ -3052,7 +3084,9 @@ width:16px; background: url('data:image/svg+xml;utf8,') no-repeat center; padding:16px !important; } -.wh-hide{display:none;}`); +#wh-trans-icon .wh-container{display:none;} +#wh-trans-icon.wh-icon-expanded .wh-container{display:block;} +`); /** * 时分秒转换 @@ -3073,7 +3107,7 @@ padding:16px !important; * regexp test */ String.prototype.contains = function contains(keywords) { - if (typeof keywords === 'string') { + if ('string' === typeof keywords) { return new RegExp(keywords).test(this); } if (keywords.test) { @@ -3538,54 +3572,139 @@ padding:16px !important; /** * 攻击页面 */ - 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 btn_parent_node; - let startBtn; - elementReady('div[class^="dialog___"]').then(e => { - dialog_container = e; - const targetNode = document.querySelector(`#${IDMap[wh_trans_settings.quichAttIndex]}`); - const topNodeHeight = (wh_trans_settings.quichAttIndex === 4 || wh_trans_settings.quichAttIndex === 5) ? 0 : 14 - if (targetNode) { - const targetT = getAbsTop(targetNode) + topNodeHeight; - const targetL = getAbsLeft(targetNode); - const targetWidth = targetNode.offsetWidth; - const targetHeight = 66;//targetNode.offsetHeight; - const btn_node = dialog_container.querySelector('button'); - if (!btn_node) return; - startBtn = btn_node; - btn_parent_node = btn_node.parentElement; - btn_node.onclick = () => btn_node.remove(); - document.body.appendChild(btn_node); - btn_node.style.position = 'absolute'; - btn_node.style.top = `${targetT}px`; - btn_node.style.left = `${targetL}px`; - btn_node.style.margin = '0'; - btn_node.style.zIndex = '999'; - btn_node.style.width = `${targetWidth}px`; - btn_node.style.height = `${targetHeight}px`; - } else if (isDev()) { - console.warn('找不到武器格子,是不是选错了?'); + if (window.location.href.contains(/loader\.php\?sid=attack/)) { + if (wh_trans_settings.quickAttIndex !== 6) { + // const selectedId = ['weapon_main', 'weapon_second', 'weapon_melee', 'weapon_temp', 'weapon_fists', 'weapon_boots'] + // [wh_trans_settings.quickAttIndex]; + elementReady('div[class^="modal___"] button').then(btn => { + if (!btn.innerText.toLowerCase().includes('start fight')) return; + if (isDev()) console.log('[WH]', btn); + // 判断是否存在脚踢 + const hasKick = !!document.querySelector('#weapon_boots'); + // modal层 + const modal = document.querySelector('div[class^="modal___"]'); + if (isDev()) console.log(`[WH] 当前设备类型是${device}`); + // 区分设备 + switch (device) { + case 'pc': { + if (isDev()) console.log(`[WH] 开始调整按钮位置`); + // 隐藏modal层 + modal.style.display = 'none'; + // 根据选择的武器调整css + let css_top = '0'; + switch (wh_trans_settings.quickAttIndex) { + case 1: { // weapon_second + css_top = '97px'; + break; + } + case 2: { // weapon_melee + css_top = '194px'; + break; + } + case 3: { // weapon_temp + css_top = '291px'; + break; + } + case 4: // weapon_fists + case 5: { // weapon_boots + css_top = '375px'; + break; + } + } + const css_rule = ` +.wh-move-btn #defender div[class^="modal___"]{display: block;width: 0 !important;top: ${css_top};left: -169px !important;} +.wh-move-btn #defender div[class^="dialog___"]{border:0;width:159px;height:96px;} +.wh-move-btn #defender div[class^="colored___"]{display:block;padding:0;} +.wh-move-btn #defender div[class^="title___"]{height:0;} +.wh-move-btn #defender button{width: 100%;margin:17px 0;height: 60px;} +`; + addStyle(css_rule); + document.body.classList.toggle('wh-move-btn'); + // 绑定点击事件 + btn.onclick = () => { + if (wh_trans_settings.quickFinishAtt !== 3) { + addStyle(`.wh-move-btn #defender button{display:none;}`); + addStyle(`.wh-move-btn #defender button:nth-of-type(${wh_trans_settings.quickFinishAtt+1}){display:inline-block !important;}`); + } + }; + break; + } + case 'mobile': { + if (isDev()) console.log(`[WH] 开始调整按钮位置`); + // 加入css + let css_top = '0'; + let slot_height = '76px'; + // 判断有没有脚踢 + if (hasKick) { + // 根据选择的武器调整 + switch (wh_trans_settings.quickAttIndex) { + case 1: { // weapon_second + css_top = '76px'; + break; + } + case 2: { // weapon_melee + css_top = '152px'; + break; + } + case 3: { // weapon_temp + css_top = '228px'; + break; + } + case 4: { // weapon_fists + css_top = '304px'; + break; + } + case 5: { // weapon_boots + css_top = '380px'; + break; + } + } + } else { + const slot = document.querySelector('#weapon_main'); + const height = slot.offsetHeight + 1; + slot_height = height; + // 根据选择的武器调整 + switch (wh_trans_settings.quickAttIndex) { + case 1: { // weapon_second + css_top = `${height}px`; + break; + } + case 2: { // weapon_melee + css_top = `${height * 2}px`; + break; + } + case 3: { // weapon_temp + css_top = `${height * 3}px`; + break; + } + case 4: { // weapon_fists + css_top = `${height * 4}px`; + break; + } + case 5: { // weapon_boots + css_top = `${height * 5}px`; + break; + } + } + } + const css_rule = ` +.wh-move-btn #attacker div[class^="modal___"]{display: block;width: 0;top: ${css_top};left:0;height:0;} +.wh-move-btn #attacker div[class^="dialog___"]{border:0;width:80px;height:${slot_height};} +.wh-move-btn #attacker div[class^="colored___"]{display:block;padding:0;} +.wh-move-btn #attacker div[class^="title___"]{height:0;} +.wh-move-btn #attacker button{width:100%;margin:0;height:63px;white-space:normal;} +`; + addStyle(css_rule); + document.body.classList.toggle('wh-move-btn'); + btn.onclick = () => { + addStyle(`.wh-move-btn #attacker button{display:none;}`); + addStyle(`.wh-move-btn #attacker button:nth-of-type(${wh_trans_settings.quickFinishAtt+1}){display:inline-block !important;}`); + }; + break; + } + case 'tablet': { + break; + } } }); const CUR_DISABLED = false; @@ -5475,7 +5594,7 @@ padding:16px !important; /* 日历 */ - if (window.location.href.contains(/calendar\.php/)) { + if (wh_trans_settings.transEnable && window.location.href.contains(/calendar\.php/)) { const $root = document.querySelectorAll('#calendar-root'); if (wh_trans_settings.transEnable) $root.forEach(el => { initOB(el, {childList: true, subtree: true}, () => { @@ -7060,6 +7179,7 @@ margin: 0 0 3px; wh_gStyle.innerHTML = v; document.head.append(wh_gStyle); } + console.log('css规则已注入', v); } /* @@ -7070,7 +7190,7 @@ margin: 0 0 3px; zhongNode.id = 'wh-trans-icon'; zhongNode.classList.add('cont-gray'); zhongNode.innerHTML = `
-
+
芜湖的翻译助手
@@ -7083,7 +7203,6 @@ margin: 0 0 3px; case 'checkbox': { newNode.innerHTML += ``; settingNode.appendChild(newNode); - settingNode.append(newNode); settingNode.querySelector(`#${setting.domId}`).onchange = (elem) => { wh_trans_settings[setting.dictName] = elem.target.checked; saveSettings(); @@ -7114,7 +7233,7 @@ margin: 0 0 3px; }); zhongNode.querySelector('#wh-trans-icon-btn').onclick = (e) => { e.target.blur(); - e.target.parentElement.nextElementSibling.classList.toggle('wh-hide'); + e.target.parentElement.parentElement.classList.toggle('wh-icon-expanded'); }; document.body.prepend(zhongNode); }