From bb83b98a239edb2901a875020bb763aedcfea611 Mon Sep 17 00:00:00 2001 From: Liwanyi Date: Tue, 27 Sep 2022 19:31:14 +0800 Subject: [PATCH] =?UTF-8?q?TS=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/class/Global.ts | 14 +--- src/class/Log.ts | 8 +- src/class/WuhuBase.ts | 4 - src/class/WuhuConfig.ts | 11 +-- src/class/WuhuTornHelper.ts | 55 ++++++++++++-- src/class/ZhongIcon.ts | 20 +++-- src/class/utils/Alert.ts | 75 ++++--------------- src/class/utils/NotificationUtils.ts | 4 +- src/class/utils/Utils.ts | 33 +++++--- src/func/module/attackHelper.ts | 53 ++++++------- src/func/module/cityFinder.ts | 3 +- src/func/module/depoHelper.ts | 2 +- src/func/module/loadGS.ts | 2 +- src/func/module/priceWatcherHandle.ts | 5 +- src/func/module/travelHelper.ts | 2 +- src/func/utils/{ => @deprecated}/COFetch.ts | 16 ++-- src/func/utils/{ => @deprecated}/addStyle.ts | 5 +- .../utils/{ => @deprecated}/getSidebarData.ts | 6 +- src/func/utils/WHNotify.ts | 2 +- src/func/utils/audioPlay.ts | 4 +- src/urlMatch.ts | 18 ++--- 21 files changed, 165 insertions(+), 177 deletions(-) rename src/func/utils/{ => @deprecated}/COFetch.ts (84%) rename src/func/utils/{ => @deprecated}/addStyle.ts (82%) rename src/func/utils/{ => @deprecated}/getSidebarData.ts (91%) diff --git a/src/class/Global.ts b/src/class/Global.ts index 958ab22..71b9879 100644 --- a/src/class/Global.ts +++ b/src/class/Global.ts @@ -21,7 +21,7 @@ export default class Global extends WuhuBase implements IGlobal { // 海外库存 fStock: { get: () => Promise } = null; // 玩家名和数字id - player_info: PlayerInfo = null; + player_info = null; // 设备类型 device: Device = null; // PDA运行环境 @@ -70,18 +70,6 @@ export default class Global extends WuhuBase implements IGlobal { this.unsafeWindow.whtest = 'unsafeWindow'; window = this.unsafeWindow || this.window; Log.info('替换window上下文'); - Log.info({ - setInterval, clearInterval, - 'window.setInterval': window.setInterval, - 'window.clearInterval': window.clearInterval, - 'this.unsafeWindow.setInterval': this.unsafeWindow.setInterval, - 'this.unsafeWindow.clearInterval': this.unsafeWindow.clearInterval, - 'this.window.setInterval': this.window.setInterval, - 'this.window.clearInterval': this.window.clearInterval, - }) - // Log.info(window.whtest) - // Log.info(this.unsafeWindow.whtest) - // Log.info(this.window.whtest) } catch { this.unsafeWindow = null; this.GM_xmlhttpRequest = null; diff --git a/src/class/Log.ts b/src/class/Log.ts index 541ab92..5d89386 100644 --- a/src/class/Log.ts +++ b/src/class/Log.ts @@ -1,15 +1,15 @@ export default class Log { - static info(...o) { + static info(...o): void { if (this.debug()) { console.log('[WH]', this.getTime(), ...o) } } - static error(...o) { + static error(...o): void { (this.debug()) && (console.error('[WH]', this.getTime(), ...o)) } - static debug() { + static debug(): boolean { let ret: boolean; try { let local = JSON.parse(localStorage.getItem('wh_trans_settings')); @@ -21,7 +21,7 @@ export default class Log { return ret; } - static getTime() { + static getTime(): string { let d = new Date(); let year = d.getFullYear(); let month = ('0' + (d.getMonth() + 1)).slice(-2); diff --git a/src/class/WuhuBase.ts b/src/class/WuhuBase.ts index a3a629c..5b426d2 100644 --- a/src/class/WuhuBase.ts +++ b/src/class/WuhuBase.ts @@ -23,8 +23,4 @@ export default class WuhuBase { constructor() { Log.info('创建对象:' + this.constructor.name) } - - static getGlob(): IGlobal { - return this.glob - } } \ No newline at end of file diff --git a/src/class/WuhuConfig.ts b/src/class/WuhuConfig.ts index 4786503..787fdda 100644 --- a/src/class/WuhuConfig.ts +++ b/src/class/WuhuConfig.ts @@ -1,17 +1,18 @@ import WuhuBase from "./WuhuBase"; +import Alert from "./utils/Alert"; export default class WuhuConfig extends WuhuBase { static get(key: string) { - return WuhuBase.getLocal()[key]; + return WuhuConfig.getLocal()[key]; } - static set(key: string, val: any, callback: Function = () => { - }) { - let config = WuhuBase.getLocal(); + static set(key: string, val: any, callback: Function = () => null, isNotify = false) { + let config = WuhuConfig.getLocal(); config[key] = val; localStorage.setItem('wh_trans_settings', JSON.stringify(config)); - // if (isNotify) WHNotify('已保存设置') + if (isNotify) + new Alert('已保存设置') new Promise(() => callback()).then(); return val; } diff --git a/src/class/WuhuTornHelper.ts b/src/class/WuhuTornHelper.ts index 3afdc47..fef901e 100644 --- a/src/class/WuhuTornHelper.ts +++ b/src/class/WuhuTornHelper.ts @@ -1,24 +1,24 @@ -import getWhSettingObj from "../func/utils/getWhSettingObj"; import miniprofTrans from "../func/translate/miniprofTrans"; -import addStyle from "../func/utils/addStyle"; import Utils from "./utils/Utils"; import WuhuBase from "./WuhuBase"; import TravelItem from "./action/TravelItem"; import Global from "./Global"; import Log from "./Log"; +import WuhuConfig from "./WuhuConfig"; export default class WuHuTornHelper extends WuhuBase { init() { Log.info('WuHuTornHelper初始化'); WuhuBase.glob = Global.getInstance(); - let glob = WuhuBase.glob; + let glob = WuHuTornHelper.glob; glob.fStock = TravelItem.getInstance(); - Log.info(glob.fStock) + Log.info('fStock: ', glob.fStock) // 请求通知权限 - if (window.Notification && Notification.permission !== 'granted') { - Notification.requestPermission().then(); + if (window.Notification && window.Notification.permission !== 'granted') { + window.alert("芜湖助手即将请求浏览器通知权限……"); + window.Notification.requestPermission().then(); } else { Log.info({ Notification }); } @@ -42,7 +42,7 @@ export default class WuHuTornHelper extends WuhuBase { } const res = await ori_fetch(url, init); // mini profile 翻译 - if (url.includes('profiles.php?step=getUserNameContextMenu') && getWhSettingObj()['transEnable']) { + if (url.includes('profiles.php?step=getUserNameContextMenu') && WuhuConfig.get('transEnable')) { setTimeout(() => miniprofTrans(), 200); } let clone = res.clone(); @@ -51,7 +51,7 @@ export default class WuHuTornHelper extends WuhuBase { return clone; }; - addStyle(` + Utils.addStyle(` .wh-hide{display:none;} #wh-trans-icon{ user-select:none; @@ -196,6 +196,45 @@ div#wh-popup::after { #wh-gym-info-cont button{ cursor:pointer; } +#wh-notify { + display: inline-block; + position: fixed; + top: 0; + left: calc(50% - 180px); + width: 360px; + z-index: 9999990; + color:#333; +} +#wh-notify a{ +color:red; +text-decoration:none; +} +#wh-notify .wh-notify-item { + /*height: 50px;*/ + background: rgb(239 249 255 / 90%); + border-radius: 2px; + margin: 0.5em 0 0 0; + box-shadow: 0 0 5px 0px #959595; +} +#wh-notify .wh-notify-item:hover { + background: rgb(239 249 255 / 98%); +} +#wh-notify .wh-notify-item .wh-notify-bar { + height:2px; + background:#2196f3; +} +#wh-notify .wh-notify-item .wh-notify-close { + float:right; + padding:0; +width:16px;height:16px; +background:url('data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%201024%201024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M923%20571H130.7c-27.6%200-50-22.4-50-50s22.4-50%2050-50H923c27.6%200%2050%2022.4%2050%2050s-22.4%2050-50%2050z%22%20fill%3D%22%232196f3%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E') no-repeat center; +background-size:100%; +margin: 6px 6px 0 0; +cursor: pointer; +} +#wh-notify .wh-notify-item .wh-notify-msg { + padding:12px; +} `); // 测试用 diff --git a/src/class/ZhongIcon.ts b/src/class/ZhongIcon.ts index 160d0c9..23395f9 100644 --- a/src/class/ZhongIcon.ts +++ b/src/class/ZhongIcon.ts @@ -1,7 +1,6 @@ import popupMsg from "../func/utils/popupMsg"; import WHNotify from "../func/utils/WHNotify"; import forStock from "../func/utils/forStock"; -import addStyle from "../func/utils/addStyle"; import doQuickFly from "../func/module/doQuickFly"; import loadGS from "../func/module/loadGS"; import loading_gif_html from "../func/utils/loading_gif_html"; @@ -16,7 +15,6 @@ import WuhuBase from "./WuhuBase"; import Log from "./Log"; import Utils from "./utils/Utils"; import WuhuConfig from "./WuhuConfig"; -import Alert from "./utils/Alert"; export default class ZhongIcon extends WuhuBase { static ZhongNode: MyHTMLElement = null; @@ -380,7 +378,7 @@ export default class ZhongIcon extends WuhuBase { clickFunc: async function () { if (window.hasWHQuickFlyOpt) return; window.hasWHQuickFlyOpt = true; - addStyle(`#wh-quick-fly-opt{ + Utils.addStyle(`#wh-quick-fly-opt{ position:fixed; left:64px; top:64px; @@ -595,7 +593,7 @@ info{display:block;} domText: '🔗 常用链接', clickFunc: function (e) { if (!this.styleAdded) { - addStyle(` + Utils.addStyle(` .wh-link-collection-cont a{ display: inline-block; border: solid 1px #b3b3b3; @@ -964,11 +962,7 @@ color:black; clickFunc: async function () { Log.info('测试开始'); - // sessionStorage.removeItem('sidebarData2687093') - // Log.info(await Utils.getSidebarData()) - // Log.info(await Utils.getUserState()) - - new Alert('123', { sysNotify: true }); + Utils.getSidebarData().then(data => Log.info(data)) Log.info('测试结束'); }, @@ -1391,6 +1385,7 @@ color:black; // 默认设置 static setDefaultSettings(): void { Log.info('Wuhu设置默认值'); + let count = 0; [ // 开启翻译 { key: 'transEnable', val: false }, @@ -1450,9 +1445,12 @@ color:black; // 危险行为⚠️ { key: 'dangerZone', val: false }, ].forEach(df => { - if (typeof WuhuConfig.get(df.key) !== typeof df.val) WuhuConfig.set(df.key, df.val); + if (typeof WuhuConfig.get(df.key) !== typeof df.val) { + WuhuConfig.set(df.key, df.val); + count++; + } }); - Log.info('Wuhu设置默认值结束'); + Log.info('Wuhu设置默认值结束,设置新值:' + count); } } diff --git a/src/class/utils/Alert.ts b/src/class/utils/Alert.ts index 0f7a307..b8a0319 100644 --- a/src/class/utils/Alert.ts +++ b/src/class/utils/Alert.ts @@ -1,23 +1,19 @@ -import Utils from "./Utils"; -import addStyle from "../../func/utils/addStyle"; import Log from "../Log"; import IWHNotify from "../../interface/IWHNotify"; import NotificationUtils from "./NotificationUtils"; +import WuhuBase from "../WuhuBase"; -export default class Alert extends Utils { - static container: HTMLElement = null; +export default class Alert extends WuhuBase { + private static container: HTMLElement = null; - notify: MyHTMLElement = null; - intervalID = -1; + private notify: MyHTMLElement = null; + private intervalID = -1; + private readonly callback: Function; constructor(msg: string, options: IWHNotify = {}) { super(); - let { - timeout = 3, - callback = () => null, - sysNotify = false, - } = options; + let { timeout, callback, sysNotify, } = options; // 后台窗口、iframe内判断 if (!Alert.glob.isWindowActive.get() || (self !== top)) return null; @@ -25,15 +21,16 @@ export default class Alert extends Utils { // 通知的容器 if (Alert.container === null) Alert.initContainer(); - this.callback = callback; - Alert.create(this, msg, timeout); + this.callback = callback || (() => null); + Alert.create(this, msg, timeout || 3); Log.info('创建新通知:', this); if (sysNotify) NotificationUtils.push(msg, options); } - static create(that: Alert, msg, timeout): void { + private static create(that: Alert, msg, timeout): void { // 通知的唯一id - const uid = '' + Utils.getRandomInt(1000, 9999); + // const uid = '' + Alert.getRandomInt(1000, 9999); + const uid = '' + performance.now(); // 每条通知 const element: MyHTMLElement = document.createElement('div'); element.id = `wh-notify-${ uid }`; @@ -70,61 +67,17 @@ export default class Alert extends Utils { Log.info(that.notify) } - static initContainer() { + private static initContainer() { this.container = document.createElement('div'); this.container.id = 'wh-notify'; - addStyle(` -#wh-notify { - display: inline-block; - position: fixed; - top: 0; - left: calc(50% - 180px); - width: 360px; - z-index: 9999990; - color:#333; -} -#wh-notify a{ -color:red; -text-decoration:none; -} -#wh-notify .wh-notify-item { - /*height: 50px;*/ - background: rgb(239 249 255 / 90%); - border-radius: 2px; - margin: 0.5em 0 0 0; - box-shadow: 0 0 5px 0px #959595; -} -#wh-notify .wh-notify-item:hover { - background: rgb(239 249 255 / 98%); -} -#wh-notify .wh-notify-item .wh-notify-bar { - height:2px; - background:#2196f3; -} -#wh-notify .wh-notify-item .wh-notify-close { - float:right; - padding:0; -width:16px;height:16px; -background:url('data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%201024%201024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M923%20571H130.7c-27.6%200-50-22.4-50-50s22.4-50%2050-50H923c27.6%200%2050%2022.4%2050%2050s-22.4%2050-50%2050z%22%20fill%3D%22%232196f3%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E') no-repeat center; -background-size:100%; -margin: 6px 6px 0 0; -cursor: pointer; -} -#wh-notify .wh-notify-item .wh-notify-msg { - padding:12px; -} -`); document.body.append(this.container); } - close() { + public close() { this.notify.remove(); - // Log.info('父元素:', this.notify.parentElement); this.notify = null; this.callback(); let id = this.intervalID; window.clearInterval(id); } - - callback: Function = () => null; } \ No newline at end of file diff --git a/src/class/utils/NotificationUtils.ts b/src/class/utils/NotificationUtils.ts index ca6a43e..9969ae1 100644 --- a/src/class/utils/NotificationUtils.ts +++ b/src/class/utils/NotificationUtils.ts @@ -1,8 +1,8 @@ -import Utils from "./Utils"; import IWHNotify from "../../interface/IWHNotify"; import Log from "../Log"; +import WuhuBase from "../WuhuBase"; -export default class NotificationUtils extends Utils { +export default class NotificationUtils extends WuhuBase { static permission: boolean = window.Notification && window.Notification.permission === 'granted'; static push(msg: string, options: IWHNotify = {}) { diff --git a/src/class/utils/Utils.ts b/src/class/utils/Utils.ts index de9b1d9..e65da44 100644 --- a/src/class/utils/Utils.ts +++ b/src/class/utils/Utils.ts @@ -4,10 +4,11 @@ import Log from "../Log"; import Device from "../../enum/Device"; import ISidebarData from "../../interface/ISidebarData"; import AjaxFetchOption from "../../interface/AjaxFetchOption"; +import Alert from "./Alert"; export default class Utils extends WuhuBase { static getScriptEngine() { - let glob = WuhuBase.glob; + let glob = Utils.glob; return glob.unsafeWindow ? UserScriptEngine.GM : glob.isPDA ? UserScriptEngine.PDA : UserScriptEngine.RAW; } @@ -57,7 +58,7 @@ export default class Utils extends WuhuBase { break; } case UserScriptEngine.GM: { - let { GM_xmlhttpRequest } = WuhuBase.glob; + let { GM_xmlhttpRequest } = Utils.glob; if (typeof GM_xmlhttpRequest !== 'function') { Log.error('COFetch网络错误:用户脚本扩展API错误'); reject('错误:用户脚本扩展API错误'); @@ -85,9 +86,14 @@ export default class Utils extends WuhuBase { */ static getPlayerInfo(): PlayerInfo { const node = document.querySelector('script[uid]'); - if (node) return { - playername: node.getAttribute('name'), - userID: node.getAttribute('uid') as unknown as number, + if (node) { + return { + playername: node.getAttribute('name'), + userID: node.getAttribute('uid') as unknown as number, + } + } else { + new Alert('严重错误:芜湖助手无法获取用户数据,已退出'); + throw '芜湖助手无法获取用户数据'; } } @@ -115,8 +121,8 @@ export default class Utils extends WuhuBase { return new Promise(resolve => setTimeout(() => resolve(null), time)); } - static getSessionData(): Promise { - let field: string = 'sidebarData' + this.getPlayerInfo().userID; + static async getSessionData(): Promise { + let field: string = 'sidebarData' + (await this.getPlayerInfo()).userID; let ret: ISidebarData = {}; return new Promise(async resolve => { let c = 0; @@ -205,7 +211,16 @@ export default class Utils extends WuhuBase { }); } - static createSystemNotify(): Notification { - return null; + static addStyle(rules: string): void { + let element = document.querySelector('style#wh-trans-gStyle'); + if (element) { + element.innerHTML += rules; + } else { + element = document.createElement("style"); + element.id = 'wh-trans-gStyle'; + element.innerHTML = rules; + document.head.appendChild(element); + } + Log.info('CSS规则已添加', element); } } \ No newline at end of file diff --git a/src/func/module/attackHelper.ts b/src/func/module/attackHelper.ts index e6e2908..694ed63 100644 --- a/src/func/module/attackHelper.ts +++ b/src/func/module/attackHelper.ts @@ -1,14 +1,11 @@ import Device from "../../enum/Device"; -import elementReady from "../utils/elementReady"; -import getWhSettingObj from "../utils/getWhSettingObj"; import addActionBtn from "../utils/addActionBtn"; -import addStyle from "../utils/addStyle"; -import log from "../utils/@deprecated/log"; import ZhongIcon from "../../class/ZhongIcon"; import WuhuBase from "../../class/WuhuBase"; import WuhuConfig from "../../class/WuhuConfig"; import Utils from "../../class/utils/Utils"; import Log from "../../class/Log"; +import Alert from "../../class/utils/Alert"; export default async function attackHelper(): Promise { let { href, device } = WuhuBase.glob; @@ -16,7 +13,9 @@ export default async function attackHelper(): Promise { // 攻击页面 if (href.contains(/loader\.php\?sid=attack/)) { let stop_reload = false; - const { quickAttIndex, quickFinishAtt, attReload } = getWhSettingObj(); + const quickAttIndex = WuhuConfig.get('quickAttIndex'); + const quickFinishAtt = WuhuConfig.get('quickFinishAtt'); + const attReload = WuhuConfig.get('attReload'); // 光速刷新按钮 addActionBtn('光速刷新', doAttackReload, $zhongNode); @@ -31,10 +30,9 @@ export default async function attackHelper(): Promise { 'tablet': '', }; const selector = selector_device_map[device]; - elementReady(selector).then(elem => { + Utils.elementReady(selector).then(elem => { if (!elem.querySelector('button')) { - if (getWhSettingObj().attReload === 0 && stop_reload !== true) { - // window.location.reload(); + if (WuhuConfig.get('attReload') === 0 && stop_reload !== true) { doAttackReload(); } else { let reload_flag; @@ -65,23 +63,23 @@ export default async function attackHelper(): Promise { // 光速拔刀 if (quickAttIndex !== 6) { - const btn = await elementReady('div[class^="modal___"] button'); - log.info(btn); + const btn = await Utils.elementReady('div[class^="modal___"] button'); + Log.info(btn); if (!btn.innerText.toLowerCase().includes('fight')) return; // 判断是否存在脚踢 const hasKick = !!document.querySelector('#weapon_boots'); // modal层 const modal: HTMLElement = document.querySelector('div[class^="modal___"]'); - log.info(`当前设备类型是${ device }`); + Log.info(`当前设备类型是${ device }`); // 区分设备 switch (device) { case Device.PC: { - log.info(`开始调整按钮位置`); + Log.info(`开始调整按钮位置`); // 隐藏modal层 modal.style.display = 'none'; // 根据选择的武器调整css let css_top = '0'; - switch (getWhSettingObj()['quickAttIndex']) { + switch (WuhuConfig.get('quickAttIndex')) { case 1: { // weapon_second css_top = '97px'; break; @@ -107,7 +105,7 @@ export default async function attackHelper(): Promise { .wh-move-btn #defender div[class^="title___"]{height:0;} .wh-move-btn #defender button{width: 100%;margin:17px 0;height: 60px;} `; - addStyle(css_rule); + Utils.addStyle(css_rule); document.body.classList.add('wh-move-btn'); // 绑定点击事件 联动【光速跑路】 btn.onclick = () => { @@ -122,14 +120,14 @@ export default async function attackHelper(): Promise { break; } case Device.MOBILE: { - log.info(`开始调整按钮位置`); + Log.info(`开始调整按钮位置`); // 加入css let css_top = '0'; let slot_height = '76px'; // 判断有没有脚踢 if (hasKick) { // 根据选择的武器调整 - switch (getWhSettingObj()['quickAttIndex']) { + switch (WuhuConfig.get('quickAttIndex')) { case 1: { // weapon_second css_top = '76px'; break; @@ -157,7 +155,7 @@ export default async function attackHelper(): Promise { // TODO 待验证 slot_height = height + 'px'; // 根据选择的武器调整 - switch (getWhSettingObj().quickAttIndex) { + switch (WuhuConfig.get('quickAttIndex')) { case 1: { // weapon_second css_top = `${ height }px`; break; @@ -187,10 +185,10 @@ export default async function attackHelper(): Promise { .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); + Utils.addStyle(css_rule); document.body.classList.toggle('wh-move-btn'); btn.onclick = () => { - if (getWhSettingObj().quickFinishAtt !== 3) { + if (WuhuConfig.get('quickFinishAtt') !== 3) { btn.remove(); // 停止自动刷新 stop_reload = true; @@ -205,7 +203,7 @@ export default async function attackHelper(): Promise { } } // 自动开打 - if (getWhSettingObj()['autoStartFinish'] === true) { + if (WuhuConfig.get('autoStartFinish') === true) { if (btn.innerText.includes('(')) { let interval_id = window.setInterval(() => { if (!btn) { @@ -225,18 +223,18 @@ export default async function attackHelper(): Promise { // 光速跑路 if (quickFinishAtt !== 3) { - const user_btn_select = ['leave', 'mug', 'hosp'][getWhSettingObj()['quickFinishAtt']]; + const user_btn_select = ['leave', 'mug', 'hosp'][WuhuConfig.get('quickFinishAtt')]; const wrap = document.querySelector('#react-root'); - log.info('光速跑路选项选中:', user_btn_select); + Log.info('光速跑路选项选中:', user_btn_select); new MutationObserver(() => { const btn_arr = document.querySelectorAll('div[class^="dialogButtons___"] button') as unknown as HTMLButtonElement[]; if (btn_arr.length > 1) btn_arr.forEach(btn => { btn = btn as HTMLButtonElement; const flag = btn.innerText.toLowerCase().includes(user_btn_select); - log.info('按钮内容:', btn.innerText, ',是否包含选中:', flag); + Log.info('按钮内容:', btn.innerText, ',是否包含选中:', flag); if (!flag) btn.style.display = 'none'; // 自动结束 - else if (getWhSettingObj()['autoStartFinish'] === true) { + else if (WuhuConfig.get('autoStartFinish') === true) { try { btn.click(); } catch { @@ -249,7 +247,7 @@ export default async function attackHelper(): Promise { } // 错误的攻击页面 - if (getWhSettingObj()['attRelocate'] && href.includes('loader2.php')) { + if (WuhuConfig.get('attRelocate') && href.includes('loader2.php')) { const spl = window.location.href.trim().split('='); const uid = spl[spl.length - 1]; if (!/^\d+$/.test(uid)) return; @@ -260,7 +258,10 @@ export default async function attackHelper(): Promise { // 战斗页面快速刷新 function doAttackReload() { - if (!window.ReactDOM) return; + if (!window.ReactDOM) { + new Alert('光速刷新失败:未找到React对象'); + return; + } let react_root = document.querySelector('#react-root'); if (!react_root.querySelector('#attacker')) return; let script = document.querySelector('script[src*="/builds/attack/"]'); diff --git a/src/func/module/cityFinder.ts b/src/func/module/cityFinder.ts index 31ad6d7..f66ba84 100644 --- a/src/func/module/cityFinder.ts +++ b/src/func/module/cityFinder.ts @@ -1,11 +1,10 @@ import elementReady from "../utils/elementReady"; -import addStyle from "../utils/addStyle"; import toThousands from "../utils/toThousands"; import log from "../utils/@deprecated/log"; import Utils from "../../class/utils/Utils"; export default function cityFinder(): void { - addStyle(` + Utils.addStyle(` .wh-city-finds .leaflet-marker-pane img[src*="torn.com/images/items/"]{ display: block !important; box-sizing: border-box; diff --git a/src/func/module/depoHelper.ts b/src/func/module/depoHelper.ts index cf88af9..89b4d23 100644 --- a/src/func/module/depoHelper.ts +++ b/src/func/module/depoHelper.ts @@ -1,6 +1,6 @@ import elementReady from "../utils/elementReady"; import getWhSettingObj from "../utils/getWhSettingObj"; -import addStyle from "../utils/addStyle"; +import addStyle from "../utils/@deprecated/addStyle"; import addActionBtn from "../utils/addActionBtn"; import WHNotify from "../utils/WHNotify"; import jQueryAjax from "../utils/jQueryAjax"; diff --git a/src/func/module/loadGS.ts b/src/func/module/loadGS.ts index c7d3ea2..a5fb2ba 100644 --- a/src/func/module/loadGS.ts +++ b/src/func/module/loadGS.ts @@ -1,6 +1,6 @@ import UserScriptEngine from "../../enum/UserScriptEngine"; import WHNotify from "../utils/WHNotify"; -import addStyle from "../utils/addStyle"; +import addStyle from "../utils/@deprecated/addStyle"; import log from "../utils/@deprecated/log"; import Utils from "../../class/utils/Utils"; diff --git a/src/func/module/priceWatcherHandle.ts b/src/func/module/priceWatcherHandle.ts index 6490f5e..119c344 100644 --- a/src/func/module/priceWatcherHandle.ts +++ b/src/func/module/priceWatcherHandle.ts @@ -2,6 +2,7 @@ import getWhSettingObj from "../utils/getWhSettingObj"; import log from "../utils/@deprecated/log"; import toThousands from "../utils/toThousands"; import WHNotify from "../utils/WHNotify"; +import Log from "../../class/Log"; // 价格监视handle export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) { @@ -10,7 +11,7 @@ export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) { const price_conf = getWhSettingObj()['priceWatcher']; const apikey = isPDA ? PDA_APIKey : localStorage.getItem('APIKey'); if (!apikey) { - log.error('价格监视失败,无apikey') + Log.error('价格监视失败,无apikey') return; } if (price_conf['pt'] !== -1) priceWatcherPt(apikey, price_conf['pt'], priceTemp).then(); @@ -46,7 +47,7 @@ async function priceWatcherPt(apikey, lower_price, priceWatcher) { } } else { // 查询出错了 - log.error('pt查询出错了') + Log.error('pt查询出错了') } } diff --git a/src/func/module/travelHelper.ts b/src/func/module/travelHelper.ts index 137688e..c7ee9f6 100644 --- a/src/func/module/travelHelper.ts +++ b/src/func/module/travelHelper.ts @@ -4,7 +4,7 @@ import Device from "../../enum/Device"; import WHNotify from "../utils/WHNotify"; import getWhSettingObj from "../utils/getWhSettingObj"; import addActionBtn from "../utils/addActionBtn"; -import addStyle from "../utils/addStyle"; +import addStyle from "../utils/@deprecated/addStyle"; import log from "../utils/@deprecated/log"; import doQuickFly from "./doQuickFly"; import ZhongIcon from "../../class/ZhongIcon"; diff --git a/src/func/utils/COFetch.ts b/src/func/utils/@deprecated/COFetch.ts similarity index 84% rename from src/func/utils/COFetch.ts rename to src/func/utils/@deprecated/COFetch.ts index 8b4b516..e3ca306 100644 --- a/src/func/utils/COFetch.ts +++ b/src/func/utils/@deprecated/COFetch.ts @@ -1,6 +1,6 @@ -import UserScriptEngine from "../../enum/UserScriptEngine"; -import getScriptEngine from "./getScriptEngine"; -import log from "./@deprecated/log"; +import UserScriptEngine from "../../../enum/UserScriptEngine"; +import getScriptEngine from "../getScriptEngine"; +import Log from "../../../class/Log"; /** * @deprecated @@ -19,26 +19,26 @@ export default function COFetch(url: URL | string, method: 'get' | 'post' = 'get // get if (method === 'get') { if (typeof PDA_httpGet !== 'function') { - log.error('COFetch网络错误:PDA版本不支持'); + Log.error('COFetch网络错误:PDA版本不支持'); reject('COFetch网络错误:PDA版本不支持'); } PDA_httpGet(url) .then(res => resolve(res.responseText)) .catch(e => { - log.error('COFetch网络错误', e); + Log.error('COFetch网络错误', e); reject(`COFetch网络错误 ${ e }`); }) } // post else { if (typeof PDA_httpPost !== 'function') { - log.error('COFetch网络错误:PDA版本不支持'); + Log.error('COFetch网络错误:PDA版本不支持'); reject('COFetch网络错误:PDA版本不支持'); } PDA_httpPost(url, { 'content-type': 'application/json' }, body) .then(res => resolve(res.responseText)) .catch(e => { - log.error('COFetch网络错误', e); + Log.error('COFetch网络错误', e); reject(`COFetch网络错误 ${ e }`); }); } @@ -47,7 +47,7 @@ export default function COFetch(url: URL | string, method: 'get' | 'post' = 'get case UserScriptEngine.GM: { let { GM_xmlhttpRequest } = window; if (typeof GM_xmlhttpRequest !== 'function') { - log.error('COFetch网络错误:用户脚本扩展API错误'); + Log.error('COFetch网络错误:用户脚本扩展API错误'); reject('错误:用户脚本扩展API错误'); } GM_xmlhttpRequest({ diff --git a/src/func/utils/addStyle.ts b/src/func/utils/@deprecated/addStyle.ts similarity index 82% rename from src/func/utils/addStyle.ts rename to src/func/utils/@deprecated/addStyle.ts index 8e91004..47e90fd 100644 --- a/src/func/utils/addStyle.ts +++ b/src/func/utils/@deprecated/addStyle.ts @@ -1,8 +1,7 @@ -import log from "./@deprecated/log"; +import log from "./log"; /** - * 添加全局style - * @param {string} css CSS规则 + * @deprecated */ export default function addStyle(css: string) { let wh_gStyle = document.querySelector('style#wh-trans-gStyle'); diff --git a/src/func/utils/getSidebarData.ts b/src/func/utils/@deprecated/getSidebarData.ts similarity index 91% rename from src/func/utils/getSidebarData.ts rename to src/func/utils/@deprecated/getSidebarData.ts index 7cc2183..bb000c6 100644 --- a/src/func/utils/getSidebarData.ts +++ b/src/func/utils/@deprecated/getSidebarData.ts @@ -1,10 +1,8 @@ -import elementReady from "./elementReady"; -import log from "./@deprecated/log"; +import elementReady from "../elementReady"; +import log from "./log"; /** - * 边栏信息 * @deprecated - * @returns {unknown} */ export default async function getSidebarData() { let ret = {}; diff --git a/src/func/utils/WHNotify.ts b/src/func/utils/WHNotify.ts index ec5305c..6fa4d7e 100644 --- a/src/func/utils/WHNotify.ts +++ b/src/func/utils/WHNotify.ts @@ -1,4 +1,4 @@ -import addStyle from "./addStyle"; +import addStyle from "./@deprecated/addStyle"; import WuhuBase from "../../class/WuhuBase"; import Utils from "../../class/utils/Utils"; diff --git a/src/func/utils/audioPlay.ts b/src/func/utils/audioPlay.ts index 020e0eb..f3c9831 100644 --- a/src/func/utils/audioPlay.ts +++ b/src/func/utils/audioPlay.ts @@ -1,4 +1,4 @@ -import log from "./@deprecated/log"; +import Log from "../../class/Log"; /** * 播放音频 @@ -9,7 +9,7 @@ export default function audioPlay(url: string = 'https://www.torn.com/js/chat/so const audio = new Audio(url); audio.addEventListener("canplaythrough", () => { audio.play() - .catch(err => log.error(err)) + .catch(err => Log.error(err)) .then(); }); } \ No newline at end of file diff --git a/src/urlMatch.ts b/src/urlMatch.ts index c9ca7ba..685aaa1 100644 --- a/src/urlMatch.ts +++ b/src/urlMatch.ts @@ -2,14 +2,13 @@ import getWhSettingObj from "./func/utils/getWhSettingObj"; import cityFinder from "./func/module/cityFinder"; import WHNotify from "./func/utils/WHNotify"; import elementReady from "./func/utils/elementReady"; -import setWhSetting from "./func/utils/setWhSetting"; import { missionDict } from "./dictionary/translation"; import getTaskHint from "./func/translate/getTaskHint"; import Device from "./enum/Device"; -import addStyle from "./func/utils/addStyle"; import WuhuBase from "./class/WuhuBase"; import Utils from "./class/utils/Utils"; import Log from "./class/Log"; +import WuhuConfig from "./class/WuhuConfig"; export default class UrlPattern extends WuhuBase { constructor() { @@ -17,14 +16,14 @@ export default class UrlPattern extends WuhuBase { } static resolve() { - let { href, beer } = WuhuBase.glob; + let { href, beer } = UrlPattern.glob; // 捡垃圾助手 if (href.includes('city.php') && getWhSettingObj()['cityFinder']) { cityFinder(); } // pt一键购买 - if (getWhSettingObj()['ptQuickBuy'] && href.includes('pmarket.php')) { + if (WuhuConfig.get('ptQuickBuy') && href.includes('pmarket.php')) { WHNotify('一键购买已开启'); // ns脚本 const rmv_cfm = (e) => { @@ -58,9 +57,9 @@ export default class UrlPattern extends WuhuBase { switch_node.querySelector('input').onchange = e => { let target = e.target as HTMLInputElement; cont.classList.toggle('wh-display-none'); - setWhSetting('SEProtect', target.checked); + WuhuConfig.set('SEProtect', target.checked, null, true); }; - elementReady('#gymroot').then(node => { + Utils.elementReady('#gymroot').then(node => { cont = node; if (getWhSettingObj()['SEProtect']) node.classList.add('wh-display-none'); node.before(switch_node); @@ -894,7 +893,7 @@ margin: 0 0 3px; }; const rw_raider = async function () { if (href.includes('#rader')) { - addStyle('div.content-title,div.info-msg-cont{display:none;}'); + Utils.addStyle('div.content-title,div.info-msg-cont{display:none;}'); const wh_node = document.createElement('div'); wh_node.id = 'wh-rd-cont'; wh_node.innerHTML = `
@@ -926,8 +925,9 @@ margin: 0 0 3px; } // 特定代码块 - if (Utils.getPlayerInfo()['userID'] === 2687093 && Utils.getDeviceType() === Device.PC) { - Utils.getSidebarData().then(() => { + if (Utils.getPlayerInfo().userID === 2687093 && Utils.getDeviceType() === Device.PC) { + Utils.getSidebarData().then(data => { + Log.info({ data }) let item = document.getElementById('nav-items'); if (item) { let copy = item.cloneNode(true);