diff --git a/CHANGELOG.md b/CHANGELOG.md index 55745f6..39b1a3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,14 @@ ## 0.6.0 -2022年10月17日 +2022年10月18日 ### 修改 - 解毒提醒UI调整 - 传单助手UI调整 - 光速拔刀UI错误修复 +- 光速跑路功能暂时关闭 ### 添加 diff --git a/src/class/WuhuBase.ts b/src/class/WuhuBase.ts index b9b30d3..ecc39e7 100644 --- a/src/class/WuhuBase.ts +++ b/src/class/WuhuBase.ts @@ -3,14 +3,17 @@ import IWHSettings from "../interface/IWHSettings"; import Provider from "./provider/Provider"; export default class WuhuBase extends Provider { - static glob: IGlobal = null; + public static glob: IGlobal = null; protected readonly className: string = 'WuhuBase'; - static getLocal(): IWHSettings { + /** + * 获取 localStorage 中的 wh_trans_settings 值 (json),以对象形式返回 + */ + public static getLocal(): IWHSettings { return JSON.parse(localStorage.getItem('wh_trans_settings')) || {}; } - static conditionInterrupt() { + public static conditionInterrupt() { let title: HTMLElement | { innerText: string } = (document.querySelector('#skip-to-content') || document.querySelector('[href*="#skip-to-content"]')) as HTMLElement || { innerText: '' }; let condition = ( diff --git a/src/class/WuhuConfig.ts b/src/class/WuhuConfig.ts index 3547f23..662bdec 100644 --- a/src/class/WuhuConfig.ts +++ b/src/class/WuhuConfig.ts @@ -4,7 +4,12 @@ import Log from "./Log"; export default class WuhuConfig extends WuhuBase { className = 'WuhuConfig'; - static get(key: string | string[]) { + + /** + * 获取键或多个键对应的值,返回值或列表 + * @param key + */ + public static get(key: string | string[]) { let localPool = this.getLocal(); if (typeof key === 'string') return localPool[key]; else { @@ -16,7 +21,7 @@ export default class WuhuConfig extends WuhuBase { } } - static set(key: string, val: any, isNotify = false, callback: Function = () => null) { + public static set(key: string, val: any, isNotify = false, callback: Function = () => null) { let config = WuhuConfig.getLocal(); let prev = config[key]; config[key] = val; diff --git a/src/class/ZhongIcon.ts b/src/class/ZhongIcon.ts index a2aa707..5db8f56 100644 --- a/src/class/ZhongIcon.ts +++ b/src/class/ZhongIcon.ts @@ -907,7 +907,7 @@ export default class ZhongIcon extends WuhuBase { ], dictName: 'quickFinishAtt', isHide: true, - tip: '将结束后指定按钮移动到上面指定的格子上', + tip: '将结束后指定按钮移动到上面指定的格子上暂时关闭', }); // 攻击链接转跳 list.push({ diff --git a/src/class/provider/Provider.ts b/src/class/provider/Provider.ts index 0640476..0f2bb8f 100644 --- a/src/class/provider/Provider.ts +++ b/src/class/provider/Provider.ts @@ -15,9 +15,10 @@ export default class Provider { public static getInstance(this: T): InstanceType { // return this.instance ||= new this(); if (!this.instance) { + let startTime = performance.now(); this.instance = new this(); let thatName = this.instance.getClassName() || this.name; - Log.info('新建实例,', thatName, this.instance); + Log.info('实例已创建,', thatName, this.instance, '耗时' + ((performance.now() - startTime) | 0) + 'ms'); Provider.pool[thatName] = this.instance; } return this.instance; diff --git a/src/class/utils/CommonUtils.ts b/src/class/utils/CommonUtils.ts index c53b699..fd7cd2d 100644 --- a/src/class/utils/CommonUtils.ts +++ b/src/class/utils/CommonUtils.ts @@ -100,12 +100,12 @@ export default class CommonUtils extends WuhuBase { } // 用户设备类型 对应PC MOBILE TABLET - static getDeviceType(): Device { + public static getDeviceType(): Device { return window.innerWidth >= 1000 ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET; } - static getYaoCD(): string { + public static getYaoCD(): string { if (document.querySelector("#icon49-sidebar")) { // 0-10min return '<10分' } else if (document.querySelector("#icon50-sidebar")) { // 10min-1h @@ -121,7 +121,7 @@ export default class CommonUtils extends WuhuBase { } } - static ajaxFetch(opt: AjaxFetchOption) { + public static ajaxFetch(opt: AjaxFetchOption) { let { url, referrer = '/', method, body = null } = opt; let req_params: RequestInit = { headers: { 'X-Requested-With': 'XMLHttpRequest' }, @@ -142,7 +142,7 @@ export default class CommonUtils extends WuhuBase { * @param {number} timeout - 超时毫秒数 * @returns {Promise} */ - static elementReady(selectors: string, content: Document = document, timeout: number = 30000): Promise { + public static elementReady(selectors: string, content: Document = document, timeout: number = 30000): Promise { return new Promise((resolve, reject) => { let el = content.querySelector(selectors) as HTMLElement; if (el) { @@ -163,7 +163,11 @@ export default class CommonUtils extends WuhuBase { }); } - static addStyle(rules: string): void { + public static querySelector(selectors: string, content: Document = document, timeout: number = 30000): Promise { + return CommonUtils.elementReady(selectors, content, timeout); + } + + public static addStyle(rules: string): void { let element = document.querySelector('style#wh-trans-gStyle'); if (element) { element.innerHTML += rules; @@ -176,7 +180,7 @@ export default class CommonUtils extends WuhuBase { Log.info('CSS规则已添加', element); } - static loading_gif_html(): string { + public static loading_gif_html(): string { return LOADING_IMG_HTML; } diff --git a/src/func/module/attackHelper.ts b/src/func/module/attackHelper.ts index 9551d17..187046b 100644 --- a/src/func/module/attackHelper.ts +++ b/src/func/module/attackHelper.ts @@ -63,181 +63,190 @@ export default async function attackHelper(): Promise { // 光速拔刀 if (quickAttIndex !== 6) { - const btn = await CommonUtils.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 }`); - // 区分设备 - switch (device) { - case Device.PC: { - Log.info(`开始调整按钮位置`); - // 隐藏modal层 - // modal.style.display = 'none'; - // 根据选择的武器调整css - let css_top = '0'; - switch (WuhuConfig.get('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___"]{top: ${ css_top };}`; - CommonUtils.addStyle(ATTACK_HELPER_CSS); - CommonUtils.addStyle(css_rule); - document.body.classList.add('wh-move-btn'); - // 绑定点击事件 联动【光速跑路】 - btn.onclick = () => { - if (quickFinishAtt !== 3) { - btn.remove(); - // 停止自动刷新 - stop_reload = true; - } else { - document.body.classList.remove('wh-move-btn'); - } - }; - break; - } - case Device.MOBILE: { - Log.info(`开始调整按钮位置`); - // 加入css - let css_top = '0'; - let slot_height = '76px'; - // 判断有没有脚踢 - if (hasKick) { - // 根据选择的武器调整 + Log.info('等待响应式内容加载'); + Log.info((await CommonUtils.querySelector('#react-root div[class*="coreWrap___"]')).innerHTML); + Log.info('响应式内容已加载, 查找攻击按钮'); + // const btn = await CommonUtils.elementReady('div[class^="modal___"] button'); + // pc-defender mobile-attacker + const btn = (document.querySelector('#attacker button') || document.querySelector('#defender button')); + Log.info({ btn }); + if (!btn.innerText.toLowerCase().includes('fight')) { + Log.info('未找到攻击按钮, 退出'); + } else { + // 判断是否存在脚踢 + const hasKick = !!document.querySelector('#weapon_boots'); + // modal层 + // const modal: HTMLElement = document.querySelector('div[class^="modal___"]'); + Log.info(`当前设备类型是${ device }`); + // 区分设备 + switch (device) { + case Device.PC: { + Log.info(`开始调整按钮位置`); + // 隐藏modal层 + // modal.style.display = 'none'; + // 根据选择的武器调整css + let css_top = '0'; switch (WuhuConfig.get('quickAttIndex')) { case 1: { // weapon_second - css_top = '76px'; + css_top = '97px'; break; } case 2: { // weapon_melee - css_top = '152px'; + css_top = '194px'; break; } case 3: { // weapon_temp - css_top = '228px'; - break; - } - case 4: { // weapon_fists - css_top = '304px'; + css_top = '291px'; break; } + case 4: // weapon_fists case 5: { // weapon_boots - css_top = '380px'; + css_top = '375px'; break; } } + const css_rule = `.wh-move-btn #defender div[class^="modal___"]{top: ${ css_top };}`; + CommonUtils.addStyle(ATTACK_HELPER_CSS); + CommonUtils.addStyle(css_rule); + document.body.classList.add('wh-move-btn'); + // 绑定点击事件 联动【光速跑路】 + btn.onclick = () => { + if (quickFinishAtt !== 3) { + btn.remove(); + // 停止自动刷新 + stop_reload = true; + } else { + document.body.classList.remove('wh-move-btn'); + } + }; + break; + } + case Device.MOBILE: { + Log.info(`开始调整按钮位置`); + // 加入css + let css_top = '0'; + let slot_height = '76px'; + // 判断有没有脚踢 + if (hasKick) { + // 根据选择的武器调整 + switch (WuhuConfig.get('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') as HTMLElement; + const height = slot.offsetHeight + 1; + // TODO 待验证 + slot_height = height + 'px'; + // 根据选择的武器调整 + switch (WuhuConfig.get('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 = ATTACK_HELPER_CSS.replace('CSSVAR', css_top).replace('CSSVAR', slot_height); +// ` +// .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;} +// `; + CommonUtils.addStyle(css_rule); + document.body.classList.toggle('wh-move-btn'); + btn.onclick = () => { + if (WuhuConfig.get('quickFinishAtt') !== 3) { + btn.remove(); + // 停止自动刷新 + stop_reload = true; + } else { + document.body.classList.toggle('wh-move-btn'); + } + }; + break; + } + case Device.TABLET: { + break; + } + } + // 自动开打 + if (WuhuConfig.get('autoStartFinish') === true) { + if (btn.innerText.includes('(')) { + let interval_id = window.setInterval(() => { + if (!btn) { + clearInterval(interval_id); + return; + } + try { + btn.click(); + } catch { + } + }, 100); } else { - const slot = document.querySelector('#weapon_main') as HTMLElement; - const height = slot.offsetHeight + 1; - // TODO 待验证 - slot_height = height + 'px'; - // 根据选择的武器调整 - switch (WuhuConfig.get('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; - } - } + btn.click(); } - 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;} -`; - CommonUtils.addStyle(css_rule); - document.body.classList.toggle('wh-move-btn'); - btn.onclick = () => { - if (WuhuConfig.get('quickFinishAtt') !== 3) { - btn.remove(); - // 停止自动刷新 - stop_reload = true; - } else { - document.body.classList.toggle('wh-move-btn'); - } - }; - break; - } - case Device.TABLET: { - break; - } - } - // 自动开打 - if (WuhuConfig.get('autoStartFinish') === true) { - if (btn.innerText.includes('(')) { - let interval_id = window.setInterval(() => { - if (!btn) { - clearInterval(interval_id); - return; - } - try { - btn.click(); - } catch { - } - }, 100); - } else { - btn.click(); } } } // 光速跑路 TODO 暂时关闭 - if (quickFinishAtt !== 3 && false) { - const user_btn_select = ['leave', 'mug', 'hosp'][WuhuConfig.get('quickFinishAtt')]; - const wrap = document.querySelector('#react-root'); - 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); - if (!flag) btn.style.display = 'none'; - // 自动结束 - else if (WuhuConfig.get('autoStartFinish') === true) { - try { - btn.click(); - } catch { - } - } - }); - }).observe(wrap, { subtree: true, attributes: true, childList: true }); - } + // if (quickFinishAtt !== 3) { + // const user_btn_select = ['leave', 'mug', 'hosp'][WuhuConfig.get('quickFinishAtt')]; + // const wrap = document.querySelector('#react-root'); + // 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); + // if (!flag) btn.style.display = 'none'; + // // 自动结束 + // else if (WuhuConfig.get('autoStartFinish') === true) { + // try { + // btn.click(); + // } catch { + // } + // } + // }); + // }).observe(wrap, { subtree: true, attributes: true, childList: true }); + // } return; } diff --git a/src/static/css/attack_helper.css b/src/static/css/attack_helper.css index 0699a60..646a5eb 100644 --- a/src/static/css/attack_helper.css +++ b/src/static/css/attack_helper.css @@ -21,8 +21,9 @@ height: 0; } +/* 此处限制宽度,否则人物模型图片会溢出遮挡武器栏 */ .wh-move-btn #defender div[class^="modelWrap___"] { - display: none; + max-width: 100%; } .wh-move-btn #defender button { @@ -31,10 +32,51 @@ height: 60px; } +/* 解决按钮图标负边距被上层元素限制遮挡问题 */ .wh-move-btn #defender div[class^="playerWindow___"] { overflow: unset; } -.wh-move-btn #defender img { - display: none; +/* 手机端 */ +@media screen and (max-width: 600px) { + .wh-move-btn #attacker div[class^="playerWindow___"] { + overflow: unset; + } + + .wh-move-btn #attacker div[class^="modelWrap___"] { + max-width: 100%; + } + + .wh-move-btn #attacker div[class^="modal___"] { + display: block; + width: 0; + top: CSSVAR; + left: -80px; + height: 0; + } + + .wh-move-btn #attacker div[class^="dialog___"] { + border: 0; + width: 80px; + /* torn的规则限制90% */ + max-width: unset; + height: CSSVAR; + } + + .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; + } + } \ No newline at end of file