From 4b34e8d3d273a452285012332209e52eb27ef204 Mon Sep 17 00:00:00 2001 From: woohoo Date: Thu, 30 Dec 2021 22:00:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E7=9A=84=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=E3=80=81=E5=A2=9E=E5=8A=A0=E4=BA=86start=20fight=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E9=87=8D=E6=96=B0=E5=AE=9A=E4=BD=8D=E3=80=81=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86loader2=E6=94=BB=E5=87=BB=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E8=BD=AC=E8=B7=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bw/conf.json | 12 ++ bw/index.html | 93 ++++++++++ gengxin/index.html | 12 +- torn-trans-zhcn.user.js | 392 ++++++++++++++++++++++------------------ 4 files changed, 330 insertions(+), 179 deletions(-) create mode 100644 bw/conf.json create mode 100644 bw/index.html diff --git a/bw/conf.json b/bw/conf.json new file mode 100644 index 0000000..47865e0 --- /dev/null +++ b/bw/conf.json @@ -0,0 +1,12 @@ +{ + "latest": [ + { + "ver": "2.9.0", + "name": "冰蛙宝鉴_2.9.0.user.js.txt", + "replace": { + "with": "https://www.torn.com/*.php*", + "to": "https://www.torn.com/*" + } + } + ] +} \ No newline at end of file diff --git a/bw/index.html b/bw/index.html new file mode 100644 index 0000000..0690d35 --- /dev/null +++ b/bw/index.html @@ -0,0 +1,93 @@ + + + + + + 冰蛙复制 + + + + +

+
正在加载配置文件
+
+ +
+
+ +
+ + \ No newline at end of file diff --git a/gengxin/index.html b/gengxin/index.html index 71a8a68..dc65c29 100644 --- a/gengxin/index.html +++ b/gengxin/index.html @@ -2,6 +2,7 @@ + 更新页面 @@ -34,7 +36,7 @@

更新页面

-

+

正与翻译助手建立连接...

diff --git a/torn-trans-zhcn.user.js b/torn-trans-zhcn.user.js index 97ca49d..69c6fc0 100644 --- a/torn-trans-zhcn.user.js +++ b/torn-trans-zhcn.user.js @@ -1,15 +1,13 @@ // ==UserScript== -// @lastmodified 202112291622 +// @lastmodified 202112302200 // @name Torn翻译 // @namespace WOOH -// @version 0.1.1229b +// @version 0.1.1230a // @description Torn UI翻译 // @author Woohoo-[2687093] sabrina_devil[2696209] // @match https://www.torn.com/* // @grant none // ==/UserScript== - - (function () { 'use strict'; const ___window___ = window || window.unsafeWindow; @@ -23,6 +21,11 @@ todo: true, cont: `baza npc商店 imarket及imarket搜索结果`, }, + { + ver: '0.1.1230a', + date: '20211230', + cont: `增加了设置区域的自动生成、增加了start fight按钮重新定位、增加了loader2攻击错误页面的转跳`, + }, { ver: '0.1.1229b', date: '20211229', @@ -2875,6 +2878,131 @@ // if (!localStorage.getItem('wh_trans_transDict')) localStorage.setItem('wh_trans_transDict', JSON.stringify(transDict)) const mobile = window.innerWidth <= 600; + const settingsArr = [ + { + domType: 'checkbox', + domId: 'wh-trans-enable', + domText: ' 开启翻译 (施工中)', + dictName: 'transEnable', + }, + { + domType: 'button', + domId: 'wh-trans-data-update', + domText: '更新翻译词库数据', + clickFunc: function (e) { + e.target.blur(); + if (this.intervalID) return; + const url = isDev() ? 'http://192.168.1.7:8080/' : 'https://jjins.github.io/gengxin/'; + const popup = window.open(url); + let hsCount = 0; + this.intervalID = window.setInterval(() => { + if (hsCount > 20) { + clearInterval(this.intervalID); + this.intervalID = null; + return; + } + popup.postMessage("connect", '*'); + hsCount++; + }, 500); + let connected = false; + if (!this.msgEventCreated) { + window.addEventListener("message", (e) => { + this.msgEventCreated = true; + if (e.data === 'connected') { + connected = true; + clearInterval(this.intervalID); + this.intervalID = null; + return; + } + if (connected) { + // 传回的动态内容 + if (isDev()) console.log(e.data); + } + }, false); + } + }, + }, + { + domType: 'checkbox', + domId: 'wh-quick-crime', + domText: ' 快速犯罪', + dictName: 'quickCrime', + }, + { + domType: 'checkbox', + domId: 'wh-mission-lint', + domText: ' 任务助手', + dictName: 'missionHint', + }, + { + domType: 'checkbox', + domId: 'wh-xmastown-wt', + domText: ' 圣诞小镇攻略', + dictName: 'xmasTownWT', + }, + { + domType: 'checkbox', + domId: 'wh-xmastown-notify', + domText: ' 圣诞小镇物品提示', + dictName: 'xmasTownNotify', + }, + { + domType: 'checkbox', + domId: 'wh-energy-alert', + domText: ' 起飞爆E警告', + dictName: 'energyAlert', + }, + { + domType: 'checkbox', + domId: 'wh-attack-relocate', + domText: ' 攻击错误转跳', + dictName: 'attRelocate', + }, + { + domType: 'checkbox', + domId: 'wh-quick-attack', + domText: ' 攻击按钮重定位', + dictName: 'quickAtt', + }, + { + domType: 'select', + domId: 'wh-quick-attack-index', + domText: '攻击按钮位置 ', + domSelectOpt: [ + { + domVal: 'pri', + domText: '--主手--', + }, + { + domVal: 'sec', + domText: '--副手--', + }, + { + domVal: 'wea', + domText: '--近战--', + }, + { + domVal: 'gre', + domText: '--手雷--', + }, + { + domVal: 'fis', + domText: '--拳头--', + }, + { + domVal: 'kic', + domText: '--脚踢--', + }, + ], + dictName: 'quichAttIndex', + }, + { + domType: 'checkbox', + domId: 'wh-dev-mode', + domText: ' 开发者模式', + dictName: 'isDev', + }, + ]; // 左侧标签 const zhongIconIntervalID = window.setInterval(() => { if (!document.querySelector('#wh-trans-icon')) initIcon(); @@ -2890,13 +3018,14 @@ energyAlert: true, quickAtt: false, quichAttIndex: 2, + attRelocate: true, isDev: false, }; initIcon(); addStyle(`#wh-trans-icon{ display: inline-block; position: fixed; - top: calc(50% - 100px); + top: calc(50% - 123px); left: 0; z-index: 20000; border: solid 1px #b5b5b5; @@ -2904,14 +3033,14 @@ 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; border:0; } +#wh-gSettings div{ +margin: 1px 0; +} #wh-trans-icon .wh-container{ margin:0; padding:0 16px 16px; @@ -3431,65 +3560,60 @@ padding:16px !important; }; const IDMap = ['weapon_main', 'weapon_second', 'weapon_melee', 'weapon_temp', 'weapon_fists', 'weapon_boots']; let dialog_container; - let btnParentElem; + let btn_parent_node; 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`); + 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); + const targetT = getAbsTop(targetNode) + topNodeHeight; 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) { + 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('找不到武器格子,是不是选错了?'); } }); - // 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; + const CUR_DISABLED = false; + if (CUR_DISABLED) { + const original_fetch = window.fetch; + window.fetch = async (url, init) => { + let response = await original_fetch(url, init) + let res = response.clone(); + res.json().then((data) => { + if (isDev()) { + console.log('[url]', url) + console.log('[返回数据]', data) + } + }); + return response; } - 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; } } + return; + } + + // 错误的攻击页面 + if (wh_trans_settings.attRelocate && window.location.href.includes('loader2.php')) { + const spl = window.location.href.trim().split('='); + const uid = spl[spl.length - 1]; + if (!/^[0-9]+$/.test(uid)) return; + window.location.href = `https://www.torn.com/loader.php?sid=attack&user2ID=${uid}`; + return; } /** @@ -6781,25 +6905,6 @@ margin: 0 0 3px; }); } - /** - * 翻译插件提示 - */ - function msgBox(htmlCont = '') { - if ($('div.wh-trans-msg').length === 0) { - console.log('翻译插件消息框已创建'); - $('div.content-title').after(`
-
-
- -
-
-${htmlCont}

`) - } else { - console.log('翻译插件消息框内容已更改'); - $('div.wh-trans-msg div.msg.right-round').html(htmlCont); - } - } - /** * 发钱翻译 */ @@ -6964,115 +7069,54 @@ ${htmlCont}
const zhongNode = document.createElement('div'); zhongNode.id = 'wh-trans-icon'; zhongNode.classList.add('cont-gray'); - zhongNode.innerHTML = - `
+ zhongNode.innerHTML = `
芜湖的翻译助手
-
-
- (施工中) -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
+
`; - $('body').prepend(zhongNode); + const settingNode = zhongNode.querySelector('#wh-gSettings'); + settingsArr.forEach(setting => { + const newNode = document.createElement('div'); + switch (setting.domType) { + 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(); + }; + break; + } + case 'button': { + newNode.innerHTML += ``; + settingNode.appendChild(newNode); + settingNode.querySelector(`#${setting.domId}`).onclick = setting.clickFunc; + break; + } + case 'select': { + let optHtml = ''; + setting.domSelectOpt.forEach((optObj, i) => { + const selected = i === wh_trans_settings[setting.dictName] ? 'selected' : ''; + optHtml += ``; + }); + newNode.innerHTML += ``; + settingNode.appendChild(newNode); + settingNode.querySelector(`#${setting.domId}`).onchange = (elem) => { + wh_trans_settings[setting.dictName] = elem.target.selectedIndex; + saveSettings(); + }; + break; + } + } + }); zhongNode.querySelector('#wh-trans-icon-btn').onclick = (e) => { e.target.blur(); e.target.parentElement.nextElementSibling.classList.toggle('wh-hide'); }; - let intervalID; - let connected = false; - zhongNode.querySelector('#wh-trans-data-update').onclick = (e) => { - e.target.blur(); - if (intervalID) return; - const url = wh_trans_settings.isDev ? 'http://localhost:8080/' : 'https://jjins.github.io/gengxin/'; - const popup = window.open(url); - intervalID = window.setInterval(() => { - popup.postMessage("connect", url); - }, 1000); - }; - window.addEventListener("message", (e) => { - if (e.data === 'connected') { - connected = true; - if (intervalID) clearInterval(intervalID); - intervalID = null; - return; - } - if (connected) { - // 传回的动态内容 - // console.log(e.data) - 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(); - }; + document.body.prepend(zhongNode); } /*