更新
This commit is contained in:
parent
7033476b19
commit
59c4240c93
15
build.js
15
build.js
@ -2,25 +2,28 @@
|
||||
* 此脚本用于加入userscript meta,
|
||||
* 并生成日期时间与版本号
|
||||
*/
|
||||
|
||||
let startTime = Date.now();
|
||||
let fs = require('fs');
|
||||
|
||||
let date = new Date();
|
||||
let version = process.env.npm_package_version;
|
||||
let head = `// ==UserScript==
|
||||
// @lastmodified ${date.getFullYear()}${('0' + (date.getMonth() + 1)).slice(-2)}${('0' + date.getDate()).slice(-2)}${('0' + date.getHours()).slice(-2)}${('0' + date.getMinutes()).slice(-2)}
|
||||
let formatedDateTime = `${ date.getFullYear() }${ ('0' + (date.getMonth() + 1)).slice(-2) }${ ('0' + date.getDate()).slice(-2) }${ ('0' + date.getHours()).slice(-2) }${ ('0' + date.getMinutes()).slice(-2) }`;
|
||||
let metaData = `// ==UserScript==
|
||||
// @lastmodified ${ formatedDateTime }
|
||||
// @name 芜湖助手
|
||||
// @namespace WOOH
|
||||
// @version ${version}
|
||||
// @version ${ version }
|
||||
// @description 托恩,起飞!
|
||||
// @author Woohoo[2687093] Sabrina_Devil[2696209]
|
||||
// @match https://www.torn.com/*
|
||||
// @grant GM_xmlhttpRequest
|
||||
// @grant unsafeWindow
|
||||
// @connect ljs-lyt.com
|
||||
// @connect yata.yt
|
||||
// @connect *
|
||||
// ==/UserScript==
|
||||
`
|
||||
|
||||
const data = fs.readFileSync('./bundle.min.js', 'utf8');
|
||||
fs.writeFileSync('./release.min.user.js', head + data.replace('$$WUHU_DEV_VERSION$$', version), 'utf8');
|
||||
console.log('构建完成');
|
||||
fs.writeFileSync('./release.min.user.js', metaData + data.replace('$$WUHU_DEV_VERSION$$', version), 'utf8');
|
||||
console.log(`新版本 ${ version } 构建完成, 耗时${ Date.now() - startTime }ms`);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.5.9",
|
||||
"version": "0.6.0",
|
||||
"description": "芜湖助手",
|
||||
"dependencies": {},
|
||||
"scripts": {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -8,7 +8,7 @@ import CommonUtils from "./utils/CommonUtils";
|
||||
|
||||
export class Common extends WuhuBase {
|
||||
className = 'Common';
|
||||
resolve() {
|
||||
public resolve() {
|
||||
let glob = Common.glob;
|
||||
// 价格监控
|
||||
priceWatcherHandle(glob.isPDA, glob.PDA_APIKey);
|
||||
@ -16,8 +16,8 @@ export class Common extends WuhuBase {
|
||||
// 啤酒提醒
|
||||
if (WuhuConfig.get('_15Alarm')) glob.beer.start();
|
||||
|
||||
// 点击4条转跳对应的页面
|
||||
if (WuhuConfig.get('barsRedirect')) {
|
||||
// 点击4条转跳对应的页面//
|
||||
if (WuhuConfig.get('barsRedirect') && !document.body.classList.contains('without-sidebar')) {
|
||||
const eb = document.getElementById('barEnergy') as HTMLAnchorElement;
|
||||
const nb = document.getElementById('barNerve') as HTMLAnchorElement;
|
||||
const hb = document.getElementById('barHappy') as HTMLAnchorElement;
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
export default class Log {
|
||||
private static logs = '';
|
||||
private static counter = { info: 0, error: 0, warning: 0 };
|
||||
|
||||
static info(...o): void {
|
||||
public static info(...o): void {
|
||||
Log.counter.info++;
|
||||
let time = this.getTime();
|
||||
let flag = '[WH] IFO';
|
||||
if (this.debug()) {
|
||||
@ -10,21 +12,23 @@ export default class Log {
|
||||
this.saveLogs(flag, time, ...o);
|
||||
}
|
||||
|
||||
static error(...o): void {
|
||||
public static error(...o): void {
|
||||
Log.counter.error++;
|
||||
let time = this.getTime();
|
||||
let flag = '[WH] ERR';
|
||||
console.error(flag, time, ...o);
|
||||
this.saveLogs(flag, time, ...o);
|
||||
}
|
||||
|
||||
static warn(...o): void {
|
||||
public static warn(...o): void {
|
||||
Log.counter.warning++;
|
||||
let time = this.getTime();
|
||||
let flag = '[WH] WRN';
|
||||
(this.debug()) && (console.warn(flag, time, ...o));
|
||||
this.saveLogs(flag, time, ...o);
|
||||
}
|
||||
|
||||
static debug(): boolean {
|
||||
public static debug(): boolean {
|
||||
let ret: boolean;
|
||||
try {
|
||||
let local = JSON.parse(localStorage.getItem('wh_trans_settings'));
|
||||
@ -36,7 +40,7 @@ export default class Log {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static getTime(): string {
|
||||
public static getTime(): string {
|
||||
let d = new Date();
|
||||
let year = d.getFullYear();
|
||||
let month = ('0' + (d.getMonth() + 1)).slice(-2);
|
||||
@ -48,7 +52,7 @@ export default class Log {
|
||||
return `[${ year }-${ month }-${ date } ${ hours }:${ minutes }:${ seconds }.${ ms }]`;
|
||||
}
|
||||
|
||||
static getLogs() {
|
||||
public static getLogs() {
|
||||
return this.logs;
|
||||
}
|
||||
|
||||
@ -68,4 +72,12 @@ export default class Log {
|
||||
})
|
||||
this.logs += '\r\n';
|
||||
}
|
||||
|
||||
public static getCounter() {
|
||||
return {
|
||||
info: Log.counter.info,
|
||||
error: Log.counter.error,
|
||||
warning: Log.counter.warning,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1186,10 +1186,12 @@ export default class ZhongIcon extends WuhuBase {
|
||||
domId: null,
|
||||
domText: '查看日志',
|
||||
clickFunc: () => {
|
||||
let logCounter = Log.getCounter();
|
||||
let pop = new Popup('<textarea readonly style="width:100%;height:340px;"></textarea>', '查看日志');
|
||||
let text = pop.getElement().querySelector('textarea');
|
||||
text.innerHTML = Log.getLogs();
|
||||
text.onclick = () => text.select();
|
||||
pop.getElement().insertAdjacentHTML('afterbegin', `<p>${ logCounter.info }信息 ${ logCounter.warning }警告 ${ logCounter.error }错误</p>`)
|
||||
}
|
||||
});
|
||||
// 更多设定
|
||||
|
||||
@ -15,7 +15,7 @@ export default class Starter {
|
||||
Log.error('[Starter]', e.message || JSON.stringify(e));
|
||||
}
|
||||
let runTime: number = (performance.now() - started) | 0;
|
||||
Log.info(`加载时间${ runTime }ms`);
|
||||
Log.info(`芜湖脚本完成加载, 耗时${ runTime }ms`);
|
||||
if (ZhongIcon.ZhongNode && ZhongIcon.ZhongNode.initTimer)
|
||||
ZhongIcon.ZhongNode.initTimer.innerHTML = `加载时间 ${ runTime }ms`;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import Device from "../../enum/Device";
|
||||
import AjaxFetchOption from "../../interface/AjaxFetchOption";
|
||||
import Alert from "./Alert";
|
||||
import LOADING_IMG_HTML from "../../static/html/loading_img.html";
|
||||
import Timer from "./Timer";
|
||||
|
||||
export default class CommonUtils extends WuhuBase {
|
||||
className = 'CommonUtils';
|
||||
@ -143,21 +144,27 @@ export default class CommonUtils extends WuhuBase {
|
||||
* @returns {Promise<HTMLElement|null>}
|
||||
*/
|
||||
public static elementReady(selectors: string, content: Document = document, timeout: number = 30000): Promise<HTMLElement> {
|
||||
Log.info('等待元素:' + selectors);
|
||||
let timer = new Timer();
|
||||
return new Promise((resolve, reject) => {
|
||||
let el = content.querySelector(selectors) as HTMLElement;
|
||||
if (el) {
|
||||
Log.info('已获取元素, 耗时' + timer.getTimeMs(), el);
|
||||
resolve(el);
|
||||
return
|
||||
return;
|
||||
}
|
||||
let observer = new MutationObserver((_, observer) => {
|
||||
content.querySelectorAll(selectors).forEach((element) => {
|
||||
Log.info({ innerHTML: element.innerHTML, element });
|
||||
observer.disconnect();
|
||||
Log.info('已获取元素, 耗时' + timer.getTimeMs(), element);
|
||||
resolve(element as HTMLElement);
|
||||
});
|
||||
});
|
||||
setTimeout(() => {
|
||||
observer.disconnect();
|
||||
reject(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }`);
|
||||
Log.error(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs());
|
||||
reject(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs());
|
||||
}, timeout);
|
||||
observer.observe(content.documentElement, { childList: true, subtree: true });
|
||||
});
|
||||
|
||||
14
src/class/utils/Timer.ts
Normal file
14
src/class/utils/Timer.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export default class Timer {
|
||||
private startTime: number;
|
||||
|
||||
constructor() {
|
||||
this.startTime = performance.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回计时毫秒数以ms结束
|
||||
*/
|
||||
public getTimeMs(): string {
|
||||
return ((performance.now() - this.startTime) | 0) + 'ms';
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,9 @@ import MathUtils from "../../class/utils/MathUtils";
|
||||
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
|
||||
import ATTACK_HELPER_CSS from "../../static/css/attack_helper.css";
|
||||
|
||||
/**
|
||||
* TODO class重构、各功能联动
|
||||
*/
|
||||
export default async function attackHelper(): Promise<null> {
|
||||
let { href, device } = WuhuBase.glob;
|
||||
// 攻击页面
|
||||
@ -63,13 +66,16 @@ export default async function attackHelper(): Promise<null> {
|
||||
|
||||
// 光速拔刀
|
||||
if (quickAttIndex !== 6) {
|
||||
Log.info('等待响应式内容加载');
|
||||
Log.info((await CommonUtils.querySelector('#react-root div[class*="coreWrap___"]')).innerHTML);
|
||||
// await CommonUtils.querySelector('#react-root div[class^="players___"]'); // pc 可用
|
||||
await CommonUtils.querySelector('#react-root div[class^="playersModelWrap___"]');
|
||||
Log.info('响应式内容已加载, 查找攻击按钮');
|
||||
// const btn = await CommonUtils.elementReady('div[class^="modal___"] button');
|
||||
// pc-defender mobile-attacker
|
||||
/**
|
||||
* pc #defender
|
||||
* mobile #attacker
|
||||
*/
|
||||
const btn = <HTMLInputElement>(document.querySelector('#attacker button') || document.querySelector('#defender button'));
|
||||
Log.info({ btn });
|
||||
Log.info('操作按钮按钮', { btn });
|
||||
if (!btn.innerText.toLowerCase().includes('fight')) {
|
||||
Log.info('未找到攻击按钮, 退出');
|
||||
} else {
|
||||
@ -87,27 +93,31 @@ export default async function attackHelper(): Promise<null> {
|
||||
// 根据选择的武器调整css
|
||||
let css_top = '0';
|
||||
switch (WuhuConfig.get('quickAttIndex')) {
|
||||
case 1: { // weapon_second
|
||||
// weapon_second
|
||||
case 1: {
|
||||
css_top = '97px';
|
||||
break;
|
||||
}
|
||||
case 2: { // weapon_melee
|
||||
// weapon_melee
|
||||
case 2: {
|
||||
css_top = '194px';
|
||||
break;
|
||||
}
|
||||
case 3: { // weapon_temp
|
||||
// weapon_temp
|
||||
case 3: {
|
||||
css_top = '291px';
|
||||
break;
|
||||
}
|
||||
case 4: // weapon_fists
|
||||
case 5: { // weapon_boots
|
||||
// weapon_fists
|
||||
case 4:
|
||||
// weapon_boots
|
||||
case 5: {
|
||||
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);
|
||||
CommonUtils.addStyle(`.wh-move-btn #defender div[class^="modal___"]{top: ${ css_top };}`);
|
||||
document.body.classList.add('wh-move-btn');
|
||||
// 绑定点击事件 联动【光速跑路】
|
||||
btn.onclick = () => {
|
||||
|
||||
@ -3,21 +3,22 @@ import log from "../utils/@deprecated/log";
|
||||
import toThousands from "../utils/toThousands";
|
||||
import Log from "../../class/Log";
|
||||
import Alert from "../../class/utils/Alert";
|
||||
import WuhuConfig from "../../class/WuhuConfig";
|
||||
|
||||
// 价格监视handle
|
||||
export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) {
|
||||
let priceTemp = {};
|
||||
setInterval(() => {
|
||||
const price_conf = getWhSettingObj()['priceWatcher'];
|
||||
let intervalId = window.setInterval(() => {
|
||||
const price_conf = WuhuConfig.get('priceWatcher');
|
||||
const apikey = isPDA ? PDA_APIKey : localStorage.getItem('APIKey');
|
||||
if (!apikey) {
|
||||
Log.error('价格监视失败,无apikey')
|
||||
if (!apikey || (price_conf['pt'] === -1 && price_conf['xan'] === -1)) {
|
||||
Log.error('价格监视失败,无apikey');
|
||||
window.clearInterval(intervalId);
|
||||
return;
|
||||
}
|
||||
if (price_conf['pt'] !== -1) priceWatcherPt(apikey, price_conf['pt'], priceTemp).then();
|
||||
if (price_conf['xan'] !== -1) priceWatcherXan(apikey, price_conf['xan'], priceTemp).then();
|
||||
}, 10000)
|
||||
// return { status: true };
|
||||
}
|
||||
|
||||
// pt价格监视
|
||||
@ -71,6 +72,6 @@ async function priceWatcherXan(apikey, lower_price, priceWatcher) {
|
||||
}
|
||||
} else {
|
||||
// 查询出错了
|
||||
log.info('xan查询出错了')
|
||||
Log.error('xan查询出错了')
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user