This commit is contained in:
Liwanyi 2022-10-18 18:04:50 +08:00
parent d893c8ac32
commit 7033476b19
8 changed files with 236 additions and 171 deletions

View File

@ -7,13 +7,14 @@
## 0.6.0 ## 0.6.0
2022年10月17 2022年10月18
### 修改 ### 修改
- 解毒提醒UI调整 - 解毒提醒UI调整
- 传单助手UI调整 - 传单助手UI调整
- 光速拔刀UI错误修复 - 光速拔刀UI错误修复
- 光速跑路功能暂时关闭
### 添加 ### 添加

View File

@ -3,14 +3,17 @@ import IWHSettings from "../interface/IWHSettings";
import Provider from "./provider/Provider"; import Provider from "./provider/Provider";
export default class WuhuBase extends Provider { export default class WuhuBase extends Provider {
static glob: IGlobal = null; public static glob: IGlobal = null;
protected readonly className: string = 'WuhuBase'; 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')) || {}; return JSON.parse(localStorage.getItem('wh_trans_settings')) || {};
} }
static conditionInterrupt() { public static conditionInterrupt() {
let title: HTMLElement | { innerText: string } = (document.querySelector('#skip-to-content') || let title: HTMLElement | { innerText: string } = (document.querySelector('#skip-to-content') ||
document.querySelector('[href*="#skip-to-content"]')) as HTMLElement || { innerText: '' }; document.querySelector('[href*="#skip-to-content"]')) as HTMLElement || { innerText: '' };
let condition = ( let condition = (

View File

@ -4,7 +4,12 @@ import Log from "./Log";
export default class WuhuConfig extends WuhuBase { export default class WuhuConfig extends WuhuBase {
className = 'WuhuConfig'; className = 'WuhuConfig';
static get(key: string | string[]) {
/**
*
* @param key
*/
public static get(key: string | string[]) {
let localPool = this.getLocal(); let localPool = this.getLocal();
if (typeof key === 'string') return localPool[key]; if (typeof key === 'string') return localPool[key];
else { 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 config = WuhuConfig.getLocal();
let prev = config[key]; let prev = config[key];
config[key] = val; config[key] = val;

View File

@ -907,7 +907,7 @@ export default class ZhongIcon extends WuhuBase {
], ],
dictName: 'quickFinishAtt', dictName: 'quickFinishAtt',
isHide: true, isHide: true,
tip: '将结束后指定按钮移动到上面指定的格子上', tip: '<del>将结束后指定按钮移动到上面指定的格子上</del>暂时关闭',
}); });
// 攻击链接转跳 // 攻击链接转跳
list.push({ list.push({

View File

@ -15,9 +15,10 @@ export default class Provider {
public static getInstance<T extends typeof Provider>(this: T): InstanceType<T> { public static getInstance<T extends typeof Provider>(this: T): InstanceType<T> {
// return this.instance ||= new this(); // return this.instance ||= new this();
if (!this.instance) { if (!this.instance) {
let startTime = performance.now();
this.instance = new this(); this.instance = new this();
let thatName = this.instance.getClassName() || this.name; 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; Provider.pool[thatName] = this.instance;
} }
return this.instance; return this.instance;

View File

@ -100,12 +100,12 @@ export default class CommonUtils extends WuhuBase {
} }
// 用户设备类型 对应PC MOBILE TABLET // 用户设备类型 对应PC MOBILE TABLET
static getDeviceType(): Device { public static getDeviceType(): Device {
return window.innerWidth >= 1000 return window.innerWidth >= 1000
? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET; ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
} }
static getYaoCD(): string { public static getYaoCD(): string {
if (document.querySelector("#icon49-sidebar")) { // 0-10min if (document.querySelector("#icon49-sidebar")) { // 0-10min
return '<10分' return '<10分'
} else if (document.querySelector("#icon50-sidebar")) { // 10min-1h } 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 { url, referrer = '/', method, body = null } = opt;
let req_params: RequestInit = { let req_params: RequestInit = {
headers: { 'X-Requested-With': 'XMLHttpRequest' }, headers: { 'X-Requested-With': 'XMLHttpRequest' },
@ -142,7 +142,7 @@ export default class CommonUtils extends WuhuBase {
* @param {number} timeout - * @param {number} timeout -
* @returns {Promise<HTMLElement|null>} * @returns {Promise<HTMLElement|null>}
*/ */
static elementReady(selectors: string, content: Document = document, timeout: number = 30000): Promise<HTMLElement> { public static elementReady(selectors: string, content: Document = document, timeout: number = 30000): Promise<HTMLElement> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let el = content.querySelector(selectors) as HTMLElement; let el = content.querySelector(selectors) as HTMLElement;
if (el) { 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<HTMLElement> {
return CommonUtils.elementReady(selectors, content, timeout);
}
public static addStyle(rules: string): void {
let element = document.querySelector('style#wh-trans-gStyle'); let element = document.querySelector('style#wh-trans-gStyle');
if (element) { if (element) {
element.innerHTML += rules; element.innerHTML += rules;
@ -176,7 +180,7 @@ export default class CommonUtils extends WuhuBase {
Log.info('CSS规则已添加', element); Log.info('CSS规则已添加', element);
} }
static loading_gif_html(): string { public static loading_gif_html(): string {
return LOADING_IMG_HTML; return LOADING_IMG_HTML;
} }

View File

@ -63,181 +63,190 @@ export default async function attackHelper(): Promise<null> {
// 光速拔刀 // 光速拔刀
if (quickAttIndex !== 6) { if (quickAttIndex !== 6) {
const btn = await CommonUtils.elementReady('div[class^="modal___"] button'); Log.info('等待响应式内容加载');
Log.info(btn); Log.info((await CommonUtils.querySelector('#react-root div[class*="coreWrap___"]')).innerHTML);
if (!btn.innerText.toLowerCase().includes('fight')) return; Log.info('响应式内容已加载, 查找攻击按钮');
// 判断是否存在脚踢 // const btn = await CommonUtils.elementReady('div[class^="modal___"] button');
const hasKick = !!document.querySelector('#weapon_boots'); // pc-defender mobile-attacker
// modal层 const btn = <HTMLInputElement>(document.querySelector('#attacker button') || document.querySelector('#defender button'));
const modal: HTMLElement = document.querySelector('div[class^="modal___"]'); Log.info({ btn });
Log.info(`当前设备类型是${ device }`); if (!btn.innerText.toLowerCase().includes('fight')) {
// 区分设备 Log.info('未找到攻击按钮, 退出');
switch (device) { } else {
case Device.PC: { // 判断是否存在脚踢
Log.info(`开始调整按钮位置`); const hasKick = !!document.querySelector('#weapon_boots');
// 隐藏modal层 // modal层
// modal.style.display = 'none'; // const modal: HTMLElement = document.querySelector('div[class^="modal___"]');
// 根据选择的武器调整css Log.info(`当前设备类型是${ device }`);
let css_top = '0'; // 区分设备
switch (WuhuConfig.get('quickAttIndex')) { switch (device) {
case 1: { // weapon_second case Device.PC: {
css_top = '97px'; Log.info(`开始调整按钮位置`);
break; // 隐藏modal层
} // modal.style.display = 'none';
case 2: { // weapon_melee // 根据选择的武器调整css
css_top = '194px'; let css_top = '0';
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) {
// 根据选择的武器调整
switch (WuhuConfig.get('quickAttIndex')) { switch (WuhuConfig.get('quickAttIndex')) {
case 1: { // weapon_second case 1: { // weapon_second
css_top = '76px'; css_top = '97px';
break; break;
} }
case 2: { // weapon_melee case 2: { // weapon_melee
css_top = '152px'; css_top = '194px';
break; break;
} }
case 3: { // weapon_temp case 3: { // weapon_temp
css_top = '228px'; css_top = '291px';
break;
}
case 4: { // weapon_fists
css_top = '304px';
break; break;
} }
case 4: // weapon_fists
case 5: { // weapon_boots case 5: { // weapon_boots
css_top = '380px'; css_top = '375px';
break; 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 { } else {
const slot = document.querySelector('#weapon_main') as HTMLElement; btn.click();
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 = `
.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 暂时关闭 // 光速跑路 TODO 暂时关闭
if (quickFinishAtt !== 3 && false) { // if (quickFinishAtt !== 3) {
const user_btn_select = ['leave', 'mug', 'hosp'][WuhuConfig.get('quickFinishAtt')]; // const user_btn_select = ['leave', 'mug', 'hosp'][WuhuConfig.get('quickFinishAtt')];
const wrap = document.querySelector('#react-root'); // const wrap = document.querySelector('#react-root');
Log.info('光速跑路选项选中:', user_btn_select); // Log.info('光速跑路选项选中:', user_btn_select);
new MutationObserver(() => { // new MutationObserver(() => {
const btn_arr = document.querySelectorAll('div[class^="dialogButtons___"] button') as unknown as HTMLButtonElement[]; // const btn_arr = document.querySelectorAll('div[class^="dialogButtons___"] button') as unknown as HTMLButtonElement[];
if (btn_arr.length > 1) btn_arr.forEach(btn => { // if (btn_arr.length > 1) btn_arr.forEach(btn => {
btn = btn as HTMLButtonElement; // btn = btn as HTMLButtonElement;
const flag = btn.innerText.toLowerCase().includes(user_btn_select); // 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'; // if (!flag) btn.style.display = 'none';
// 自动结束 // // 自动结束
else if (WuhuConfig.get('autoStartFinish') === true) { // else if (WuhuConfig.get('autoStartFinish') === true) {
try { // try {
btn.click(); // btn.click();
} catch { // } catch {
} // }
} // }
}); // });
}).observe(wrap, { subtree: true, attributes: true, childList: true }); // }).observe(wrap, { subtree: true, attributes: true, childList: true });
} // }
return; return;
} }

View File

@ -21,8 +21,9 @@
height: 0; height: 0;
} }
/* 此处限制宽度,否则人物模型图片会溢出遮挡武器栏 */
.wh-move-btn #defender div[class^="modelWrap___"] { .wh-move-btn #defender div[class^="modelWrap___"] {
display: none; max-width: 100%;
} }
.wh-move-btn #defender button { .wh-move-btn #defender button {
@ -31,10 +32,51 @@
height: 60px; height: 60px;
} }
/* 解决按钮图标负边距被上层元素限制遮挡问题 */
.wh-move-btn #defender div[class^="playerWindow___"] { .wh-move-btn #defender div[class^="playerWindow___"] {
overflow: unset; 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;
}
} }