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
2022年10月17
2022年10月18
### 修改
- 解毒提醒UI调整
- 传单助手UI调整
- 光速拔刀UI错误修复
- 光速跑路功能暂时关闭
### 添加

View File

@ -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 = (

View File

@ -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;

View File

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

View File

@ -15,9 +15,10 @@ export default class Provider {
public static getInstance<T extends typeof Provider>(this: T): InstanceType<T> {
// 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;

View File

@ -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<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) => {
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<HTMLElement> {
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;
}

View File

@ -63,13 +63,20 @@ export default async function attackHelper(): Promise<null> {
// 光速拔刀
if (quickAttIndex !== 6) {
const btn = await CommonUtils.elementReady('div[class^="modal___"] button');
Log.info(btn);
if (!btn.innerText.toLowerCase().includes('fight')) return;
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 = <HTMLInputElement>(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___"]');
// const modal: HTMLElement = document.querySelector('div[class^="modal___"]');
Log.info(`当前设备类型是${ device }`);
// 区分设备
switch (device) {
@ -173,13 +180,14 @@ export default async function attackHelper(): Promise<null> {
}
}
}
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;}
`;
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 = () => {
@ -215,29 +223,30 @@ export default async function attackHelper(): Promise<null> {
}
}
}
}
// 光速跑路 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;
}

View File

@ -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;
}
}