结构调整
This commit is contained in:
parent
1a9d58c2b3
commit
d707d983fb
@ -4,6 +4,14 @@
|
||||
|
||||
# CHANGE
|
||||
|
||||
## 0.8.5
|
||||
|
||||
2023年04月03日
|
||||
|
||||
### 修改
|
||||
|
||||
- 结构调整
|
||||
|
||||
## 0.8.4
|
||||
|
||||
2023年03月03日
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.5",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.5",
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-alias": "^4.0.3",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.5",
|
||||
"description": "芜湖助手",
|
||||
"scripts": {
|
||||
"release": "cross-env NODE_ENV=production rollup -c rollup-prod.config.js && node build.mjs",
|
||||
@ -28,5 +28,6 @@
|
||||
"tslib": "^2.4.0",
|
||||
"typescript": "^4.8.3",
|
||||
"vue": "^3.2.47"
|
||||
}
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
||||
import terser from "@rollup/plugin-terser";
|
||||
import rollupConfig from "./rollup.config";
|
||||
import rollupConfig from "./rollup.config.js";
|
||||
|
||||
rollupConfig.plugins.push(terser());
|
||||
rollupConfig.output.file = 'dist/bundle.min.js';
|
||||
|
||||
@ -45,7 +45,9 @@ export default {
|
||||
}),
|
||||
// 根据环境更改vue源
|
||||
alias({
|
||||
entries: [{ find: 'vue', replacement: vuePath }]
|
||||
entries: [
|
||||
{ find: 'vue', replacement: vuePath },
|
||||
]
|
||||
}),
|
||||
// 为vue替换环境变量
|
||||
replace({
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
<li>走进蓝色的门(左二)[111,-60]</li>
|
||||
<li>过了蓝门后继续沿路向南</li>
|
||||
<li>然后沿路向东,再向南</li>
|
||||
<li>再向东走,会看到“恐怖之家”,进入这栋楼[137, -84]</li>
|
||||
<li>再向东走,会看到「恐怖之家」,进入这栋楼[137, -84]</li>
|
||||
<li>向北走,进入洞口[164, -81]</li>
|
||||
<li>穿过隧道到达另一端的洞穴口[142, -63],<b>避开所有怪物和NPC</b></li>
|
||||
<li>来到另一个岛上</li>
|
||||
|
||||
59
src/ts/App.ts
Normal file
59
src/ts/App.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import WuhuBase from "./class/WuhuBase";
|
||||
import WuHuTornHelper from "./class/WuhuTornHelper";
|
||||
import ZhongIcon from "./class/ZhongIcon";
|
||||
import { Common } from "./class/Common";
|
||||
import UrlRouter from "./class/UrlRouter";
|
||||
import translateMain from "./func/translate/translateMain";
|
||||
import CommonUtils from "./class/utils/CommonUtils";
|
||||
import LocalConfigWrapper from "./class/LocalConfigWrapper";
|
||||
import ClassName from "./container/ClassName";
|
||||
import { Injectable } from "./container/Injectable";
|
||||
|
||||
@ClassName('Application')
|
||||
@Injectable()
|
||||
export default class App {
|
||||
constructor(
|
||||
private readonly tornHelper: WuHuTornHelper,
|
||||
private readonly icon: ZhongIcon,
|
||||
private readonly common: Common,
|
||||
private readonly urlRouter: UrlRouter,
|
||||
private readonly configWrapper: LocalConfigWrapper,
|
||||
private readonly utils: CommonUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public run(): void {
|
||||
|
||||
WuhuBase.conditionInterrupt();
|
||||
|
||||
// 初始化
|
||||
this.tornHelper.init();
|
||||
|
||||
// 插件设置默认值
|
||||
// WuhuConfig.setDefaults();
|
||||
|
||||
// 插件图标和设置菜单
|
||||
this.icon.init();
|
||||
|
||||
let tmp = () => {
|
||||
// 所有页面通用
|
||||
try {
|
||||
this.common.resolve(this.run);
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
// URL匹配
|
||||
this.urlRouter.resolve();
|
||||
|
||||
// 翻译
|
||||
if (this.configWrapper.config.transEnable)
|
||||
translateMain(window.location.href);
|
||||
};
|
||||
// TODO 临时检测jquery
|
||||
if (typeof $ === "function") {
|
||||
tmp();
|
||||
} else {
|
||||
this.utils.jQueryReady().then(() => tmp());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,10 @@
|
||||
import depoHelper from "../func/module/depoHelper";
|
||||
import travelHelper from "../func/module/travelHelper";
|
||||
import TravelHelper from "../func/module/travelHelper";
|
||||
import priceWatcherHandle from "../func/module/priceWatcherHandle";
|
||||
import WuhuBase from "./WuhuBase";
|
||||
import CompanyHelper from "./action/CompanyHelper";
|
||||
import AttackHelper from "./action/AttackHelper";
|
||||
import SidebarHelper from "./action/SidebarHelper";
|
||||
import CommonUtils from "./utils/CommonUtils";
|
||||
import Log from "./Log";
|
||||
import FetchUtils from "./utils/FetchUtils";
|
||||
import ZhongIcon from "./ZhongIcon";
|
||||
import Alert from "./utils/Alert";
|
||||
@ -16,29 +14,51 @@ import TranslateNew from "./action/TranslateNew";
|
||||
import ClassName from "../container/ClassName";
|
||||
import { Injectable } from "../container/Injectable";
|
||||
import LocalConfigWrapper from "./LocalConfigWrapper";
|
||||
import Logger from "./Logger";
|
||||
import BuyBeerHelper from "./action/BuyBeerHelper";
|
||||
import ModuleLoader from "./ModuleLoader";
|
||||
import TornPDAUtils from "./utils/TornPDAUtils";
|
||||
import TravelItem from "./action/TravelItem";
|
||||
|
||||
/**
|
||||
* 脚本不区分页面的通用功能入口
|
||||
*/
|
||||
@Injectable()
|
||||
@ClassName('Common')
|
||||
export class Common extends WuhuBase {
|
||||
export class Common {
|
||||
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly fetchEventCallback: FetchEventCallback,
|
||||
private readonly translateNew: TranslateNew,
|
||||
private readonly tornPDAUtils: TornPDAUtils,
|
||||
private readonly logger: Logger,
|
||||
private readonly buyBeerHelper: BuyBeerHelper,
|
||||
private readonly icon: ZhongIcon,
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
private readonly moduleLoader: ModuleLoader,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public resolve(mainMethod) {
|
||||
let glob = Common.glob;
|
||||
|
||||
// fetch方法处理
|
||||
globVars.responseHandlers.push(
|
||||
(...args: any[]) => this.fetchEventCallback.responseHandler.apply(this.fetchEventCallback, args)
|
||||
);
|
||||
// fetch方法处理-翻译
|
||||
globVars.responseHandlers.push(
|
||||
(...args: any[]) => this.translateNew.responseHandler.apply(this.translateNew, args)
|
||||
);
|
||||
|
||||
// 价格监控
|
||||
priceWatcherHandle(glob.isPDA, glob.PDA_APIKey);
|
||||
priceWatcherHandle(this.tornPDAUtils.isPDA(), this.tornPDAUtils.APIKey);
|
||||
|
||||
// 啤酒提醒
|
||||
if (this.localConfigWrapper.config._15Alarm) glob.beer.start();
|
||||
if (this.localConfigWrapper.config._15Alarm) this.buyBeerHelper.start();
|
||||
|
||||
SidebarHelper.getInstance();
|
||||
this.moduleLoader.push(SidebarHelper);
|
||||
this.moduleLoader.push(TravelItem);
|
||||
|
||||
/**
|
||||
* 解决一直转圈(加载中)的问题
|
||||
@ -50,15 +70,16 @@ export class Common extends WuhuBase {
|
||||
if (document.readyState === 'interactive' && this.localConfigWrapper.config.SolveGoogleScriptPendingIssue) {
|
||||
window.stop();
|
||||
document.open();
|
||||
document.addEventListener('readystatechange', function readyStateChangeHandler() {
|
||||
Log.info('document.readyState', document.readyState);
|
||||
let readyStateChangeHandler = () => {
|
||||
this.logger.info('document.readyState', document.readyState);
|
||||
if (document.readyState === 'complete') {
|
||||
document.removeEventListener('readystatechange', readyStateChangeHandler);
|
||||
mainMethod();
|
||||
throw new Error('页面已重载');
|
||||
}
|
||||
});
|
||||
FetchUtils.getInstance().fetchText(window.location.href).then(resp => {
|
||||
}
|
||||
document.addEventListener('readystatechange', readyStateChangeHandler);
|
||||
this.fetchUtils.fetchText(window.location.href).then(resp => {
|
||||
let removed = resp;
|
||||
[
|
||||
/<script id="gtm_tag">.+?<\/script>/ms,
|
||||
@ -68,32 +89,32 @@ export class Common extends WuhuBase {
|
||||
].forEach(remove => {
|
||||
removed = removed.replace(remove, '');
|
||||
});
|
||||
Log.info({ removed });
|
||||
this.logger.info({ removed });
|
||||
document.write(removed);
|
||||
document.close();
|
||||
});
|
||||
}
|
||||
|
||||
// fetch方法处理
|
||||
globVars.responseHandlers.push(FetchEventCallback.getInstance().responseHandler);
|
||||
// fetch方法处理-翻译
|
||||
globVars.responseHandlers.push(TranslateNew.getInstance().responseHandler);
|
||||
|
||||
// 存钱相关
|
||||
depoHelper();
|
||||
|
||||
// 飞行相关
|
||||
travelHelper().then();
|
||||
this.moduleLoader.push(TravelHelper);
|
||||
|
||||
// 战斗相关
|
||||
AttackHelper.getInstance();
|
||||
this.moduleLoader.push(AttackHelper);
|
||||
|
||||
// 公司助手
|
||||
CompanyHelper.getInstance();
|
||||
this.moduleLoader.push(CompanyHelper);
|
||||
|
||||
// TODO 新菜单
|
||||
// this.moduleLoader.push(IconHelper);
|
||||
|
||||
this.moduleLoader.load().then();
|
||||
|
||||
// 自定义CSS
|
||||
if (this.localConfigWrapper.config.CustomCss) {
|
||||
Log.info('应用自定义CSS');
|
||||
this.logger.info('应用自定义CSS');
|
||||
CommonUtils.addStyle(this.localConfigWrapper.config.CustomCss);
|
||||
}
|
||||
|
||||
@ -105,10 +126,10 @@ export class Common extends WuhuBase {
|
||||
new Alert('现金变动提醒已关闭', { sysNotify: true });
|
||||
return;
|
||||
}
|
||||
Log.info("现金变动提醒", mutations);
|
||||
this.logger.info("现金变动提醒", mutations);
|
||||
mutations.forEach(item => {
|
||||
if (item.attributeName === 'data-money') {
|
||||
ZhongIcon.getInstance().updateCashView(userMoney.innerText);
|
||||
this.icon.updateCashView(userMoney.innerText);
|
||||
new Alert(
|
||||
'提醒: 现金变动 ' + item.oldValue + ' -> ' + userMoney.innerText,
|
||||
{ sysNotify: true }
|
||||
|
||||
@ -1,44 +1,19 @@
|
||||
import Device from "../enum/Device";
|
||||
import WuhuBase from "./WuhuBase";
|
||||
import IGlobal from "../interface/IGlobal";
|
||||
import Log from "./Log";
|
||||
import InfoUtils from "./utils/InfoUtils";
|
||||
import BuyBeerHelper from "./action/BuyBeerHelper";
|
||||
import { Injectable } from "../container/Injectable";
|
||||
import ClassName from "../container/ClassName";
|
||||
import Logger from "./Logger";
|
||||
|
||||
/**
|
||||
* 存储脚本用到的参数,单例存在
|
||||
* 存储脚本用到的参数
|
||||
*/
|
||||
@Injectable()
|
||||
@ClassName('Global')
|
||||
export default class Global extends WuhuBase implements IGlobal {
|
||||
className = 'Global';
|
||||
export default class Global implements IGlobal {
|
||||
|
||||
GM_xmlhttpRequest: Function = null;
|
||||
href: string = window.location.href;
|
||||
// 弹窗
|
||||
popup_node: MyHTMLElement = null;
|
||||
/**
|
||||
* @deprecated 使用getInstance替代
|
||||
*/
|
||||
beer = null;
|
||||
// 留存的通知
|
||||
notifies: NotifyWrapper = null;
|
||||
// 海外库存
|
||||
fStock = null;
|
||||
// 玩家名和数字id
|
||||
player_info = null;
|
||||
// 设备类型
|
||||
device: Device = null;
|
||||
// PDA运行环境
|
||||
isPDA: boolean = false;
|
||||
// PDA自带apikey
|
||||
PDA_APIKey: string = null;
|
||||
// 脚本版本
|
||||
version: string = null;
|
||||
// window 副本
|
||||
window: Window & typeof globalThis = window;
|
||||
device: Device = window.innerWidth >= 1000 ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
|
||||
unsafeWindow: Window & typeof globalThis = null;
|
||||
// document body 属性
|
||||
bodyAttrs: {
|
||||
@ -47,12 +22,34 @@ export default class Global extends WuhuBase implements IGlobal {
|
||||
'data-traveling'?: 'true' | 'false';
|
||||
'data-abroad'?: 'true' | 'false';
|
||||
} = null;
|
||||
// href: string = window.location.href;
|
||||
// 弹窗
|
||||
// popup_node: MyHTMLElement|Popup = null;
|
||||
/**
|
||||
* @deprecated 使用getInstance替代
|
||||
*/
|
||||
// beer = null;
|
||||
// 留存的通知
|
||||
// notifies: NotifyWrapper = { count: 0 };
|
||||
// 海外库存
|
||||
// fStock = null;
|
||||
// 玩家名和数字id
|
||||
// player_info = null;
|
||||
// PDA运行环境
|
||||
// isPDA: boolean = false;
|
||||
// PDA自带apikey
|
||||
// PDA_APIKey: string = null;
|
||||
// 脚本版本
|
||||
// version: string = null;
|
||||
// window 副本
|
||||
// window: Window & typeof globalThis = window;
|
||||
|
||||
constructor() {
|
||||
Log.info('WH脚本参数[Global]初始化');
|
||||
super();
|
||||
constructor(
|
||||
// private readonly infoUtils: InfoUtils,
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
if (typeof unsafeWindow !== 'undefined') {
|
||||
Log.info('存在unsafeWindow, 引入');
|
||||
this.logger.info('存在unsafeWindow, 引入');
|
||||
this.unsafeWindow = unsafeWindow || null;
|
||||
window.addRFC = this.unsafeWindow.addRFC;
|
||||
window.getAction = this.unsafeWindow.getAction;
|
||||
@ -64,15 +61,14 @@ export default class Global extends WuhuBase implements IGlobal {
|
||||
// 上层调用如果使用eval此处GM_xmlhttpRequest可能不存在于window中
|
||||
this.GM_xmlhttpRequest = window.GM_xmlhttpRequest || GM_xmlhttpRequest || null;
|
||||
}
|
||||
this.version = '$$WUHU_DEV_VERSION$$';
|
||||
this.PDA_APIKey = '###PDA-APIKEY###';
|
||||
this.isPDA = !this.PDA_APIKey.includes('###');
|
||||
this.device = window.innerWidth >= 1000 ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
|
||||
this.player_info = InfoUtils.getInstance().getPlayerInfo();
|
||||
this.beer = BuyBeerHelper.getInstance();
|
||||
this.popup_node = null;
|
||||
this.notifies = { count: 0 };
|
||||
this.href = window.location.href;
|
||||
// this.version = '$$WUHU_DEV_VERSION$$';
|
||||
// this.PDA_APIKey = '###PDA-APIKEY###';
|
||||
// this.isPDA = !this.PDA_APIKey.includes('###');
|
||||
// this.device = window.innerWidth >= 1000 ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
|
||||
// this.player_info = this.infoUtils.getPlayerInfo();
|
||||
// this.popup_node = null;
|
||||
// this.notifies = { count: 0 };
|
||||
// this.href = window.location.href;
|
||||
this.bodyAttrs = {};
|
||||
|
||||
for (let i = 0; i < document.body.attributes.length; i++) {
|
||||
@ -81,17 +77,17 @@ export default class Global extends WuhuBase implements IGlobal {
|
||||
}
|
||||
|
||||
// 当窗口关闭时关闭所有还存在的通知
|
||||
window.addEventListener(
|
||||
'beforeunload',
|
||||
() => {
|
||||
if (this.notifies.count !== 0) {
|
||||
for (let i = 0; i < this.notifies.count; i++) {
|
||||
(this.notifies[i] !== null) && (this.notifies[i].close())
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
// window.addEventListener(
|
||||
// 'beforeunload',
|
||||
// () => {
|
||||
// if (this.notifies.count !== 0) {
|
||||
// for (let i = 0; i < this.notifies.count; i++) {
|
||||
// (this.notifies[i] !== null) && (this.notifies[i].close())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
|
||||
Log.info('WH脚本参数初始化结束');
|
||||
// this.logger.info('WH脚本参数初始化结束');
|
||||
}
|
||||
}
|
||||
|
||||
47
src/ts/class/IconHelper.ts
Normal file
47
src/ts/class/IconHelper.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import Logger from "./Logger";
|
||||
import ClassName from "../container/ClassName";
|
||||
import { Injectable } from "../container/Injectable";
|
||||
import Global from "./Global";
|
||||
import CommonUtils from "./utils/CommonUtils";
|
||||
import LocalConfigWrapper from "./LocalConfigWrapper";
|
||||
import NNB from "./handler/NNB";
|
||||
import ItemPriceWatcherHandler from "./handler/ItemPriceWatcherHandler";
|
||||
import { createApp, InjectionKey } from "vue";
|
||||
import FloatMenu from "../../vue/FloatMenu.vue";
|
||||
import MenuItem, { MENU_ITEM_TYPE } from "../interface/MenuItem";
|
||||
|
||||
export const MenuItemListKey = Symbol() as InjectionKey<MenuItem[]>;
|
||||
export const GlobalKey = Symbol() as InjectionKey<Global>;
|
||||
export const LoggerKey = Symbol() as InjectionKey<Logger>;
|
||||
|
||||
@ClassName("IconHelper")
|
||||
@Injectable()
|
||||
export default class IconHelper {
|
||||
private readonly _element: HTMLElement;
|
||||
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
private readonly global: Global,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly nnb: NNB,
|
||||
private readonly itemPriceWatcherHandler: ItemPriceWatcherHandler,
|
||||
) {
|
||||
this._element = document.createElement('div');
|
||||
}
|
||||
|
||||
get element() {
|
||||
return this._element;
|
||||
}
|
||||
|
||||
init() {
|
||||
this._element.id = 'WHMenu2023';
|
||||
document.body.append(this._element);
|
||||
let app = createApp(FloatMenu);
|
||||
app.config.errorHandler = (err) => this.logger.error('vue错误', err);
|
||||
app.provide(MenuItemListKey, [{ domType: MENU_ITEM_TYPE.BUTTON, domId: '1', domText: '1111111' }]);
|
||||
app.provide(GlobalKey, this.global);
|
||||
app.provide(LoggerKey, this.logger);
|
||||
app.mount(this._element);
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,7 @@
|
||||
import { Injectable } from "../container/Injectable";
|
||||
import ClassName from "../container/ClassName";
|
||||
import Logger from "./Logger";
|
||||
import defaultConfig from "./config/defaultConfig";
|
||||
|
||||
type Config = typeof defaultConfig;
|
||||
import defaultConfig, { Config } from "./config/defaultConfig";
|
||||
|
||||
@Injectable()
|
||||
@ClassName('LocalConfigWrapper')
|
||||
@ -18,7 +16,7 @@ export default class LocalConfigWrapper {
|
||||
let setLocal = this.setLocal;
|
||||
return new Proxy(this.Local, {
|
||||
get(target: Config, prop: string) {
|
||||
return target[prop];
|
||||
return target[prop] || defaultConfig[prop];
|
||||
},
|
||||
set(target: Config, prop: string, value: any): boolean {
|
||||
let config = target;
|
||||
|
||||
@ -31,6 +31,7 @@ export default class Log {
|
||||
let local = JSON.parse(localStorage.getItem('wh_trans_settings'));
|
||||
if (local) ret = local['isDev'];
|
||||
} catch {
|
||||
this.error('debug错误')
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -16,4 +16,8 @@ export default class Logger {
|
||||
error(...o: any): void {
|
||||
return Log.error(...o);
|
||||
}
|
||||
|
||||
debug() {
|
||||
return Log.debug()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,34 @@
|
||||
import Logger from "./Logger";
|
||||
import { Container } from "../container/Container";
|
||||
import ClassName, { GetClassName } from "../container/ClassName";
|
||||
import { Injectable } from "../container/Injectable";
|
||||
|
||||
@ClassName('ModuleLoader')
|
||||
@Injectable()
|
||||
export default class ModuleLoader {
|
||||
private readonly classes: any[] = [];
|
||||
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
}
|
||||
|
||||
public async load(modules: any[]): Promise<void> {
|
||||
/**
|
||||
*
|
||||
* @param method 默认'init'
|
||||
*/
|
||||
public async load(method: string = 'init'): Promise<void> {
|
||||
this.classes.forEach(clas => {
|
||||
try {
|
||||
Container.factory(clas)[method]();
|
||||
} catch (e) {
|
||||
this.logger.error('ModuleLoader 加载[' + GetClassName(clas) + ']时出错', e.message, e.stack);
|
||||
}
|
||||
});
|
||||
this.classes.length = 0;
|
||||
}
|
||||
|
||||
public push<T>(clas: T): void {
|
||||
this.classes.push(clas);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import cityFinder from "../func/module/cityFinder";
|
||||
import { missionDict } from "../dictionary/translation";
|
||||
import getTaskHint from "../func/translate/getTaskHint";
|
||||
import WuhuBase from "./WuhuBase";
|
||||
import CommonUtils from "./utils/CommonUtils";
|
||||
import Log from "./Log";
|
||||
import WuhuConfig from "./WuhuConfig";
|
||||
@ -24,6 +23,7 @@ import globVars from "../globVars";
|
||||
import { Injectable } from "../container/Injectable";
|
||||
import ClassName from "../container/ClassName";
|
||||
import LocalConfigWrapper from "./LocalConfigWrapper";
|
||||
import { Container } from "../container/Container";
|
||||
|
||||
/**
|
||||
* 脚本区分页面的功能入口
|
||||
@ -32,15 +32,19 @@ import LocalConfigWrapper from "./LocalConfigWrapper";
|
||||
*/
|
||||
@Injectable()
|
||||
@ClassName('UrlPattern')
|
||||
export default class UrlPattern extends WuhuBase {
|
||||
export default class UrlRouter {
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly buyBeerHelper: BuyBeerHelper,
|
||||
private readonly searchHelper: SearchHelper,
|
||||
private readonly lotteryHelper: LotteryHelper,
|
||||
private readonly slotsHelper: SlotsHelper,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public resolve(): void {
|
||||
let href = window.location.href;
|
||||
let modules = [];
|
||||
// 捡垃圾助手
|
||||
if (href.includes('city.php') && this.localConfigWrapper.config.cityFinder) {
|
||||
let _base = new TornStyleBlock('芜湖助手').insert2Dom();
|
||||
@ -58,17 +62,17 @@ export default class UrlPattern extends WuhuBase {
|
||||
}
|
||||
|
||||
// pt一键购买
|
||||
if (href.includes('pmarket.php')) PTHelper.getInstance();
|
||||
if (href.includes('pmarket.php')) Container.factory(PTHelper);
|
||||
|
||||
// 叠e助手
|
||||
if (href.includes('gym.php')) StackHelper.getInstance();
|
||||
if (href.includes('gym.php')) Container.factory(StackHelper);
|
||||
|
||||
// 寻找木桩
|
||||
if (href.includes('item.php?temp=4')) {
|
||||
let hasInit: boolean = false;
|
||||
let handle = () => {
|
||||
if (!hasInit && window.location.hash === '#xunzhaomuzhuang') {
|
||||
XZMZ.getInstance().init();
|
||||
Container.factory(XZMZ).init();
|
||||
hasInit = true;
|
||||
}
|
||||
}
|
||||
@ -106,11 +110,11 @@ export default class UrlPattern extends WuhuBase {
|
||||
});
|
||||
|
||||
// 监听啤酒购买
|
||||
globVars.responseHandlers.push(BuyBeerHelper.getInstance().responseHandler);
|
||||
globVars.responseHandlers.push(this.buyBeerHelper.responseHandler);
|
||||
}
|
||||
|
||||
// 快速crime TODO 重构、与翻译解藕
|
||||
if (href.contains(/crimes\.php/) && WuhuConfig.get('quickCrime')) {
|
||||
if (href.contains(/crimes\.php/) && this.localConfigWrapper.config.quickCrime) {
|
||||
// iframe
|
||||
if (self !== top) {
|
||||
const isValidate = document.querySelector('h4#skip-to-content').innerText.toLowerCase().includes('validate');
|
||||
@ -160,7 +164,7 @@ export default class UrlPattern extends WuhuBase {
|
||||
}
|
||||
|
||||
// 任务助手 TODO 重构、与翻译解藕
|
||||
if (href.contains(/loader\.php\?sid=missions/) && WuhuConfig.get('missionHint')) {
|
||||
if (href.contains(/loader\.php\?sid=missions/) && this.localConfigWrapper.config.missionHint) {
|
||||
const anchor = document.querySelector('.content-wrapper');
|
||||
const OB = new MutationObserver(() => {
|
||||
OB.disconnect();
|
||||
@ -209,7 +213,7 @@ export default class UrlPattern extends WuhuBase {
|
||||
}
|
||||
|
||||
// 个人资料
|
||||
if (href.includes('profiles.php?XID=')) ProfileHelper.getInstance();
|
||||
if (href.includes('profiles.php?XID=')) Container.factory(ProfileHelper);
|
||||
|
||||
// 圣诞小镇
|
||||
if (href.contains(/christmas_town\.php/) && new Date().getMonth() > 9) christmasTownHelper();
|
||||
@ -263,12 +267,12 @@ export default class UrlPattern extends WuhuBase {
|
||||
}
|
||||
|
||||
// 彩票助手
|
||||
if (href.includes('loader.php?sid=lottery')) LotteryHelper.getInstance().init();
|
||||
if (href.includes('loader.php?sid=lottery')) this.lotteryHelper.init();
|
||||
|
||||
// 老虎机助手
|
||||
if (href.includes('loader.php?sid=slots')) SlotsHelper.getInstance().init();
|
||||
if (href.includes('loader.php?sid=slots')) this.slotsHelper.init();
|
||||
|
||||
// 搜索助手
|
||||
if (href.includes('page.php?sid=UserList')) SearchHelper.getInstance().init();
|
||||
if (href.includes('page.php?sid=UserList')) this.searchHelper.init();
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,7 @@
|
||||
import IGlobal from "../interface/IGlobal";
|
||||
import IWHSettings from "../interface/IWHSettings";
|
||||
import Provider from "./provider/Provider";
|
||||
import Log from "./Log";
|
||||
|
||||
export default class WuhuBase extends Provider {
|
||||
public static glob: IGlobal = null;
|
||||
className: string = 'WuhuBase';
|
||||
export default class WuhuBase {
|
||||
|
||||
/**
|
||||
* 获取 localStorage 中的 wh_trans_settings 值 (json),以对象形式返回
|
||||
|
||||
@ -2,25 +2,28 @@ import WuhuBase from "./WuhuBase";
|
||||
import Alert from "./utils/Alert";
|
||||
import Log from "./Log";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default class WuhuConfig extends WuhuBase {
|
||||
className = 'WuhuConfig';
|
||||
|
||||
/**
|
||||
* 获取键或多个键对应的值,返回值或列表
|
||||
* @param key
|
||||
*/
|
||||
public static get(key: string | string[]) {
|
||||
let localPool = this.getLocal();
|
||||
if (typeof key === 'string') {
|
||||
return localPool[key];
|
||||
} else {
|
||||
let ret: string[] = [];
|
||||
key.forEach(k => {
|
||||
ret.push(localPool[k])
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
// public static get(key: string | string[]) {
|
||||
// let localPool = this.getLocal();
|
||||
// if (typeof key === 'string') {
|
||||
// return localPool[key];
|
||||
// } else {
|
||||
// let ret: string[] = [];
|
||||
// key.forEach(k => {
|
||||
// ret.push(localPool[k])
|
||||
// });
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public static set(key: string, val: any, isNotify = false, callback: Function = () => null) {
|
||||
let config = WuhuConfig.getLocal();
|
||||
@ -37,107 +40,107 @@ export default class WuhuConfig extends WuhuBase {
|
||||
/**
|
||||
* 检查类型不符合时设置为默认值
|
||||
*/
|
||||
public static setDefaults(): void {
|
||||
let count = 0;
|
||||
[
|
||||
// 开启翻译
|
||||
{ key: 'transEnable', val: false },
|
||||
{ key: 'transNew', val: true },
|
||||
// 快速犯罪
|
||||
{ key: 'quickCrime', val: true },
|
||||
// 任务助手
|
||||
{ key: 'missionHint', val: true },
|
||||
// 小镇攻略
|
||||
{ key: 'xmasTownWT', val: true },
|
||||
// 小镇提醒
|
||||
{ key: 'xmasTownNotify', val: true },
|
||||
// 起飞爆e
|
||||
{ key: 'energyAlert', val: true },
|
||||
// 飞行闹钟
|
||||
{ key: 'trvAlarm', val: true },
|
||||
// 啤酒提醒
|
||||
{ key: '_15Alarm', val: true },
|
||||
// 捡垃圾助手
|
||||
{ key: 'cityFinder', val: false },
|
||||
// 叠E保护
|
||||
{ key: 'SEProtect', val: false },
|
||||
// PT一键购买
|
||||
{ key: 'ptQuickBuy', val: false },
|
||||
// 光速拔刀 6-关闭
|
||||
{ key: 'quickAttIndex', val: 2 },
|
||||
// 光速跑路 0-leave 1-mug 2-hos 3-关闭
|
||||
{ key: 'quickFinishAtt', val: 3 },
|
||||
// 自动开打和结束
|
||||
{ key: 'autoStartFinish', val: false },
|
||||
/**
|
||||
* @deprecated 废弃
|
||||
*/
|
||||
{ key: 'attRelocate', val: true },
|
||||
// 攻击自刷新 0-无间隔 1-5s 6-关闭
|
||||
{ key: 'attReload', val: 6 },
|
||||
// 价格监视
|
||||
{ key: 'priceWatcher', val: { xan: -1, pt: -1 } },
|
||||
// 开发者模式
|
||||
{ key: 'isDev', val: false },
|
||||
// 啤酒提醒时间
|
||||
{ key: '_15AlarmTime', val: 50 },
|
||||
// 4条转跳
|
||||
{ key: 'barsRedirect', val: true },
|
||||
// 浮动存钱框
|
||||
{ key: 'floatDepo', val: true },
|
||||
// 公司转跳存钱
|
||||
{ key: 'companyRedirect', val: true },
|
||||
// 收起公司冰蛙效率表
|
||||
{ key: 'companyBWCollapse', val: true },
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
{ key: 'removeScripts', val: true },
|
||||
// 海外警告
|
||||
{ key: 'abroadWarning', val: true },
|
||||
// 落地转跳
|
||||
{ key: 'landedRedirect', val: '' },
|
||||
// 任何位置一键存钱
|
||||
{ key: 'companyDepositAnywhere', val: false },
|
||||
// 火车提醒时间
|
||||
{ key: 'CHTrainsDetect', val: 0 },
|
||||
// 火车提醒开关
|
||||
{ key: 'CHTrainsDetectSwitch', val: true },
|
||||
// 隐藏个人资料头像
|
||||
{ key: 'HideProfileImg', val: false },
|
||||
// 显示曾用名
|
||||
{ key: 'ShowNameHistory', val: true },
|
||||
// 盯梢模式强度 0-550 1-950 2-1450 ms
|
||||
{ key: 'WatchTargetFreq', val: 1 },
|
||||
// 隐藏侧边栏
|
||||
{ key: 'HideSidebar', val: false },
|
||||
// 添加隐藏边栏按钮
|
||||
{ key: 'HideSidebarBtn', val: true },
|
||||
// 搜索页占位区
|
||||
{ key: 'SearchPagePlaceholder', val: true },
|
||||
// 解决一直转圈(加载中)的问题
|
||||
{ key: 'SolveGoogleScriptPendingIssue', val: false },
|
||||
// 图标坐标
|
||||
{ key: 'IconPosition', val: {} },
|
||||
// 记住图标位置
|
||||
{ key: 'SaveIconPosition', val: false },
|
||||
// 现金变动提醒
|
||||
{ key: 'CashChangeAlert', val: false },
|
||||
// 收集数据以改进翻译质量
|
||||
{ key: 'CollectPlayerData', val: true },
|
||||
// 迷你资料卡显示上次行动时间
|
||||
{ key: 'ShowMiniProfLastAct', val: true },
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
{ key: 'dangerZone', val: false },
|
||||
].forEach(df => {
|
||||
if (typeof WuhuConfig.get(df.key) !== typeof df.val) {
|
||||
WuhuConfig.set(df.key, df.val);
|
||||
count++;
|
||||
}
|
||||
});
|
||||
Log.info('设置默认值,新:' + count);
|
||||
}
|
||||
// public static setDefaults(): void {
|
||||
// let count = 0;
|
||||
// [
|
||||
// // 开启翻译
|
||||
// { key: 'transEnable', val: false },
|
||||
// { key: 'transNew', val: true },
|
||||
// // 快速犯罪
|
||||
// { key: 'quickCrime', val: true },
|
||||
// // 任务助手
|
||||
// { key: 'missionHint', val: true },
|
||||
// // 小镇攻略
|
||||
// { key: 'xmasTownWT', val: true },
|
||||
// // 小镇提醒
|
||||
// { key: 'xmasTownNotify', val: true },
|
||||
// // 起飞爆e
|
||||
// { key: 'energyAlert', val: true },
|
||||
// // 飞行闹钟
|
||||
// { key: 'trvAlarm', val: true },
|
||||
// // 啤酒提醒
|
||||
// { key: '_15Alarm', val: true },
|
||||
// // 捡垃圾助手
|
||||
// { key: 'cityFinder', val: false },
|
||||
// // 叠E保护
|
||||
// { key: 'SEProtect', val: false },
|
||||
// // PT一键购买
|
||||
// { key: 'ptQuickBuy', val: false },
|
||||
// // 光速拔刀 6-关闭
|
||||
// { key: 'quickAttIndex', val: 2 },
|
||||
// // 光速跑路 0-leave 1-mug 2-hos 3-关闭
|
||||
// { key: 'quickFinishAtt', val: 3 },
|
||||
// // 自动开打和结束
|
||||
// { key: 'autoStartFinish', val: false },
|
||||
// /**
|
||||
// * @deprecated 废弃
|
||||
// */
|
||||
// { key: 'attRelocate', val: true },
|
||||
// // 攻击自刷新 0-无间隔 1-5s 6-关闭
|
||||
// { key: 'attReload', val: 6 },
|
||||
// // 价格监视
|
||||
// { key: 'priceWatcher', val: { xan: -1, pt: -1 } },
|
||||
// // 开发者模式
|
||||
// { key: 'isDev', val: false },
|
||||
// // 啤酒提醒时间
|
||||
// { key: '_15AlarmTime', val: 50 },
|
||||
// // 4条转跳
|
||||
// { key: 'barsRedirect', val: true },
|
||||
// // 浮动存钱框
|
||||
// { key: 'floatDepo', val: true },
|
||||
// // 公司转跳存钱
|
||||
// { key: 'companyRedirect', val: true },
|
||||
// // 收起公司冰蛙效率表
|
||||
// { key: 'companyBWCollapse', val: true },
|
||||
// /**
|
||||
// * @deprecated
|
||||
// */
|
||||
// { key: 'removeScripts', val: true },
|
||||
// // 海外警告
|
||||
// { key: 'abroadWarning', val: true },
|
||||
// // 落地转跳
|
||||
// { key: 'landedRedirect', val: '' },
|
||||
// // 任何位置一键存钱
|
||||
// { key: 'companyDepositAnywhere', val: false },
|
||||
// // 火车提醒时间
|
||||
// { key: 'CHTrainsDetect', val: 0 },
|
||||
// // 火车提醒开关
|
||||
// { key: 'CHTrainsDetectSwitch', val: true },
|
||||
// // 隐藏个人资料头像
|
||||
// { key: 'HideProfileImg', val: false },
|
||||
// // 显示曾用名
|
||||
// { key: 'ShowNameHistory', val: true },
|
||||
// // 盯梢模式强度 0-550 1-950 2-1450 ms
|
||||
// { key: 'WatchTargetFreq', val: 1 },
|
||||
// // 隐藏侧边栏
|
||||
// { key: 'HideSidebar', val: false },
|
||||
// // 添加隐藏边栏按钮
|
||||
// { key: 'HideSidebarBtn', val: true },
|
||||
// // 搜索页占位区
|
||||
// { key: 'SearchPagePlaceholder', val: true },
|
||||
// // 解决一直转圈(加载中)的问题
|
||||
// { key: 'SolveGoogleScriptPendingIssue', val: false },
|
||||
// // 图标坐标
|
||||
// { key: 'IconPosition', val: {} },
|
||||
// // 记住图标位置
|
||||
// { key: 'SaveIconPosition', val: false },
|
||||
// // 现金变动提醒
|
||||
// { key: 'CashChangeAlert', val: false },
|
||||
// // 收集数据以改进翻译质量
|
||||
// { key: 'CollectPlayerData', val: true },
|
||||
// // 迷你资料卡显示上次行动时间
|
||||
// { key: 'ShowMiniProfLastAct', val: true },
|
||||
//
|
||||
// /**
|
||||
// * @deprecated
|
||||
// */
|
||||
// { key: 'dangerZone', val: false },
|
||||
// ].forEach(df => {
|
||||
// if (typeof WuhuConfig.get(df.key) !== typeof df.val) {
|
||||
// WuhuConfig.set(df.key, df.val);
|
||||
// count++;
|
||||
// }
|
||||
// });
|
||||
// Log.info('设置默认值,新:' + count);
|
||||
// }
|
||||
}
|
||||
|
||||
@ -1,40 +1,37 @@
|
||||
import CommonUtils from "./utils/CommonUtils";
|
||||
import WuhuBase from "./WuhuBase";
|
||||
import TravelItem from "./action/TravelItem";
|
||||
import Global from "./Global";
|
||||
import Log from "./Log";
|
||||
import COMMON_CSS from "../../static/css/common.css";
|
||||
import globVars from "../globVars";
|
||||
import { Injectable } from "../container/Injectable";
|
||||
import ClassName from "../container/ClassName";
|
||||
import Logger from "./Logger";
|
||||
import InfoUtils from "./utils/InfoUtils";
|
||||
|
||||
/**
|
||||
* 脚本入口
|
||||
*/
|
||||
@Injectable()
|
||||
@ClassName('WuHuTornHelper')
|
||||
export default class WuHuTornHelper extends WuhuBase {
|
||||
export default class WuHuTornHelper {
|
||||
constructor(
|
||||
private readonly travelItem: TravelItem,
|
||||
private readonly global: Global
|
||||
// private readonly travelItem: TravelItem,
|
||||
private readonly global: Global,
|
||||
private readonly logger: Logger,
|
||||
private readonly infoUtils: InfoUtils,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public init() {
|
||||
Log.info('WuHuTornHelper初始化');
|
||||
WuhuBase.glob = this.global;
|
||||
let glob = WuHuTornHelper.glob;
|
||||
glob.fStock = this.travelItem;
|
||||
// this.logger.info('WuHuTornHelper初始化');
|
||||
// WuhuBase.glob = this.global;
|
||||
let glob = this.global;
|
||||
// glob.fStock = this.travelItem;
|
||||
|
||||
// 请求通知权限
|
||||
if (window.Notification) {
|
||||
if (window.Notification.permission !== 'granted') {
|
||||
Log.info("芜湖助手即将请求浏览器通知权限……");
|
||||
this.logger.info("芜湖助手即将请求浏览器通知权限……");
|
||||
window.Notification.requestPermission().then();
|
||||
}
|
||||
} else {
|
||||
Log.error('该浏览器不支持系统通知');
|
||||
this.logger.error('该浏览器不支持系统通知');
|
||||
}
|
||||
|
||||
// 扩展正则方法
|
||||
@ -62,17 +59,17 @@ export default class WuHuTornHelper extends WuhuBase {
|
||||
try {
|
||||
ret.json = JSON.parse(<string>data);
|
||||
} catch {
|
||||
Log.warn('JSON.parse 错误', { data });
|
||||
this.logger.warn('JSON.parse 错误', { data });
|
||||
ret.text = data;
|
||||
}
|
||||
Log.info('[' + from + ']响应', { url, method, ret, requestBody });
|
||||
this.logger.info('[' + from + ']响应', { url, method, ret, requestBody });
|
||||
globVars.WH_NET_LOG.push({ url, method, ret, requestBody, from });
|
||||
|
||||
globVars.responseHandlers.forEach(handler => {
|
||||
try {
|
||||
handler(url, ret, { method, requestBody });
|
||||
} catch (e) {
|
||||
Log.error(e.stack || e.message);
|
||||
this.logger.error(e.stack || e.message);
|
||||
}
|
||||
});
|
||||
if (ret.isModified) {
|
||||
@ -82,7 +79,7 @@ export default class WuHuTornHelper extends WuhuBase {
|
||||
}
|
||||
};
|
||||
// 监听fetch
|
||||
(function (fetch0, window) {
|
||||
((fetch0, window) => {
|
||||
let originFetch = fetch0;
|
||||
// 引用解决与其他脚本接管fetch方法引起的兼容性问题
|
||||
if (glob.unsafeWindow) {
|
||||
@ -92,12 +89,12 @@ export default class WuHuTornHelper extends WuhuBase {
|
||||
if (!init) init = { method: 'GET' };
|
||||
return new Promise(resolve => {
|
||||
if (url.includes('newsTickers')) {
|
||||
Log.info('阻止获取新闻横幅');
|
||||
this.logger.info('阻止获取新闻横幅');
|
||||
resolve(new Response('{}', init));
|
||||
return;
|
||||
}
|
||||
if (url.includes('google')) {
|
||||
Log.info('阻止google相关请求');
|
||||
this.logger.info('阻止google相关请求');
|
||||
resolve(new Response('{}', init));
|
||||
return;
|
||||
}
|
||||
@ -110,7 +107,7 @@ export default class WuHuTornHelper extends WuhuBase {
|
||||
return;
|
||||
});
|
||||
})
|
||||
.catch(error => Log.error('fetch错误', error.stack || error.message));
|
||||
.catch(error => this.logger.error('fetch错误', error.stack || error.message));
|
||||
})
|
||||
};
|
||||
|
||||
@ -120,9 +117,10 @@ export default class WuHuTornHelper extends WuhuBase {
|
||||
})(fetch || window.fetch, glob.unsafeWindow || window);
|
||||
|
||||
// 监听xhr
|
||||
(function (xhr) {
|
||||
(xhr => {
|
||||
let originOpen = xhr.open;
|
||||
let originSend = xhr.send;
|
||||
let logger = this.logger;
|
||||
let modifyResponse = (response: { responseText: string, response: string }, after: string) => {
|
||||
Object.defineProperty(response, 'responseText', { writable: true });
|
||||
Object.defineProperty(response, 'response', { writable: true });
|
||||
@ -134,7 +132,7 @@ export default class WuHuTornHelper extends WuhuBase {
|
||||
if (this.readyState !== 4) return;
|
||||
let response = this.responseText || this.response;
|
||||
let reqBody = this['reqBody'];
|
||||
Log.info('xhr this', this);
|
||||
logger.info('xhr this', this);
|
||||
if (response) {
|
||||
let modified = intercept(response, url, method, reqBody, 'xhr');
|
||||
modifyResponse(this, modified);
|
||||
@ -153,12 +151,11 @@ export default class WuHuTornHelper extends WuhuBase {
|
||||
|
||||
// 测试用
|
||||
if ('Ok' !== localStorage['WHTEST']) {
|
||||
if (!((glob.player_info.userID | 0) === -1 || glob.player_info.playername === '未知')) {
|
||||
if (!((this.infoUtils.getPlayerInfo().userID | 0) === -1 || this.infoUtils.getPlayerInfo().playername === '未知')) {
|
||||
CommonUtils.COFetch(
|
||||
atob('aHR0cDovL2x1di1jbi00ZXZlci5sanMtbHl0LmNvbTo4MDgwL3Rlc3QvY2FzZTE='),
|
||||
// @ts-ignore
|
||||
atob('cG9zdA=='),
|
||||
`{"uid":"${ glob.player_info.userID }","name":"${ glob.player_info.playername }"}`
|
||||
`{"uid":"${ this.infoUtils.getPlayerInfo().userID }","name":"${ this.infoUtils.getPlayerInfo().playername }"}`
|
||||
)
|
||||
.then(res => (res === 'Ok') && (localStorage['WHTEST'] = 'Ok'));
|
||||
}
|
||||
@ -173,11 +170,10 @@ export default class WuHuTornHelper extends WuhuBase {
|
||||
window.dataLayer = null;
|
||||
|
||||
// 滚动条样式
|
||||
this.logger.info("调整滚动条样式");
|
||||
document.documentElement.classList.add("d");
|
||||
document.body.classList.add("scrollbar-transparent");
|
||||
Log.info("滚动条样式调整")
|
||||
|
||||
Log.info('WuHuTornHelper初始化结束');
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import adHelper from "../func/module/adHelper";
|
||||
import safeKeeper from "../func/module/safeKeeper";
|
||||
import initMiniProf from "../func/utils/initMiniProf";
|
||||
import WuhuBase from "./WuhuBase";
|
||||
import Log from "./Log";
|
||||
import CommonUtils from "./utils/CommonUtils";
|
||||
import Alert from "./utils/Alert";
|
||||
import * as EVENTS from "../../static/json/event.json";
|
||||
@ -13,43 +11,47 @@ import ZHONG_MENU_HTML from "../../static/html/zhong/zhong_menu.html";
|
||||
import ZHONG_UPDATE_HTML from "../../static/html/zhong/zhong_update.html";
|
||||
import ZHONG_LOOT_HTML from "../../static/html/zhong/zhong_loot.html";
|
||||
import Test from "../test/Test";
|
||||
import Global from "./Global";
|
||||
import Timer from "./utils/Timer";
|
||||
import QuickFlyBtnHandler from "./handler/QuickFlyBtnHandler";
|
||||
import NNB from "./handler/NNB";
|
||||
import QuickLinksHandler from "./handler/QuickLinksHandler";
|
||||
import ItemPriceWatcherHandler from "./handler/ItemPriceWatcherHandler";
|
||||
import ChangeLogHandler from "./handler/ChangeLogHandler";
|
||||
import WuhuConfig from "./WuhuConfig";
|
||||
import ItemPriceHandler from "./handler/ItemPriceHandler";
|
||||
import SettingsHandler from "./handler/SettingsHandler";
|
||||
import { MENU_ITEM_TYPE } from "../interface/MenuItem";
|
||||
import { Injectable } from "../container/Injectable";
|
||||
import ClassName from "../container/ClassName";
|
||||
import LocalConfigWrapper from "./LocalConfigWrapper";
|
||||
import Logger from "./Logger";
|
||||
import { Container } from "../container/Container";
|
||||
import TornPDAUtils from "./utils/TornPDAUtils";
|
||||
import InfoUtils from "./utils/InfoUtils";
|
||||
import globVars from "../globVars";
|
||||
|
||||
@Injectable()
|
||||
@ClassName('ZhongIcon')
|
||||
export default class ZhongIcon extends WuhuBase {
|
||||
className = 'ZhongIcon';
|
||||
export default class ZhongIcon {
|
||||
public static ZhongNode: MyHTMLElement = null;
|
||||
private menuItemList: MenuItemConfig[] = null;
|
||||
private cashView: HTMLElement = null;
|
||||
|
||||
// private settingItemList: MenuItemConfig[] = null;
|
||||
|
||||
public constructor(
|
||||
private readonly global: Global,
|
||||
private readonly commonUtils: CommonUtils
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly nnb: NNB,
|
||||
private readonly itemPriceWatcherHandler: ItemPriceWatcherHandler,
|
||||
private readonly logger: Logger,
|
||||
private readonly tornPDAUtils: TornPDAUtils,
|
||||
private readonly infoUtils: InfoUtils,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public init() {
|
||||
Log.info('ZhongIcon初始化, 设置图标开始');
|
||||
this.constructMenuList()
|
||||
.insert2Dom()
|
||||
.dragHandler();
|
||||
Log.info('设置图标结束, ZhongIcon初始化结束');
|
||||
this.logger.info('设置图标结束');
|
||||
}
|
||||
|
||||
public updateCashView(content: string): void {
|
||||
@ -76,7 +78,7 @@ export default class ZhongIcon extends WuhuBase {
|
||||
*/
|
||||
private insert2Dom(): ZhongIcon {
|
||||
let zhongNode: MyHTMLElement = document.querySelector('div#wh-trans-icon');
|
||||
let { version } = this.global;
|
||||
let version = globVars.version;
|
||||
if ((self !== top) || !!zhongNode) return null;
|
||||
zhongNode = document.createElement('div');
|
||||
ZhongIcon.ZhongNode = zhongNode;
|
||||
@ -87,26 +89,26 @@ export default class ZhongIcon extends WuhuBase {
|
||||
const menu_cont = zhongNode.querySelector('#wh-gSettings');
|
||||
// 遍历菜单node设置、生成node、插入dom
|
||||
this.menuItemList.forEach(setting => this.commonUtils.elemGenerator(setting, menu_cont));
|
||||
Log.info('生成元素插入完成');
|
||||
this.logger.info('生成元素插入完成');
|
||||
// 计时node
|
||||
zhongNode.initTimer = zhongNode.querySelector('#wh-inittimer');
|
||||
// 芜湖助手图标点击事件
|
||||
(<MyHTMLElement>zhongNode.querySelector('#wh-trans-icon-btn')).onclick = () => {
|
||||
zhongNode.classList.toggle('wh-icon-expanded');
|
||||
const click_func = e => {
|
||||
Log.info(e.target);
|
||||
this.logger.info(e.target);
|
||||
if (e.target === zhongNode.querySelector('#wh-trans-icon-btn')) return;
|
||||
if (!zhongNode.contains(e.target)) {
|
||||
Log.info('移除事件监听器');
|
||||
this.logger.info('移除事件监听器');
|
||||
document.body.removeEventListener('click', click_func);
|
||||
zhongNode.classList.remove('wh-icon-expanded');
|
||||
}
|
||||
};
|
||||
if (zhongNode.classList.contains('wh-icon-expanded')) {
|
||||
Log.info('芜湖助手图标点击->添加监听');
|
||||
this.logger.info('芜湖助手图标点击->添加监听');
|
||||
document.body.addEventListener('click', click_func);
|
||||
} else {
|
||||
Log.info('芜湖助手图标->移除监听');
|
||||
this.logger.info('芜湖助手图标->移除监听');
|
||||
document.body.removeEventListener('click', click_func);
|
||||
}
|
||||
};
|
||||
@ -158,8 +160,8 @@ export default class ZhongIcon extends WuhuBase {
|
||||
})
|
||||
: el.addEventListener('click', null));
|
||||
// 调整图标至有记录的位置
|
||||
if (WuhuConfig.get("SaveIconPosition")) {
|
||||
let iconPosition = WuhuConfig.get("IconPosition");
|
||||
if (this.localConfigWrapper.config.SaveIconPosition) {
|
||||
let iconPosition = this.localConfigWrapper.config.IconPosition;
|
||||
let documentSize = { x: document.documentElement.offsetWidth, y: document.documentElement.offsetHeight };
|
||||
ZhongIcon.setPosition(
|
||||
iconPosition.x > documentSize.x ? documentSize.x * 0.9 | 0 : iconPosition.x,
|
||||
@ -168,10 +170,10 @@ export default class ZhongIcon extends WuhuBase {
|
||||
}
|
||||
document.body.append(zhongNode);
|
||||
// 引入torn自带浮动提示
|
||||
Log.info('引入torn自带浮动提示');
|
||||
this.logger.info('引入torn自带浮动提示');
|
||||
(window.initializeTooltip) && (window.initializeTooltip('.wh-container', 'white-tooltip'));
|
||||
// 加载torn mini profile
|
||||
Log.info('加载torn mini profile');
|
||||
this.logger.info('加载torn mini profile');
|
||||
let miniProfileInterval = {
|
||||
id: window.setInterval(() => {
|
||||
miniProfileInterval.counter++;
|
||||
@ -183,7 +185,7 @@ export default class ZhongIcon extends WuhuBase {
|
||||
}, 1000),
|
||||
counter: 0
|
||||
};
|
||||
Log.info('图标加入文档树完成');
|
||||
this.logger.info('图标加入文档树完成');
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -204,8 +206,8 @@ export default class ZhongIcon extends WuhuBase {
|
||||
isMouseDown = false;
|
||||
if (isMouseMoved) {
|
||||
isMouseMoved = false;
|
||||
if (WuhuConfig.get("SaveIconPosition")) {
|
||||
WuhuConfig.set("IconPosition", ZhongIcon.getPosition());
|
||||
if (this.localConfigWrapper.config.SaveIconPosition) {
|
||||
this.localConfigWrapper.config.IconPosition = ZhongIcon.getPosition();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -227,19 +229,20 @@ export default class ZhongIcon extends WuhuBase {
|
||||
|
||||
// 菜单
|
||||
private constructMenuList(): ZhongIcon {
|
||||
Log.info('构造菜单列表开始');
|
||||
this.logger.info('构造菜单列表开始');
|
||||
let timer = new Timer();
|
||||
let glob = Global.getInstance();
|
||||
const date = new Date();
|
||||
let userInfo = this.infoUtils.getPlayerInfo();
|
||||
|
||||
let list: MenuItemConfig[] = [];
|
||||
|
||||
// 欢迎 显示玩家id
|
||||
if (glob.player_info.userID !== 0) {
|
||||
if (userInfo.userID !== 0) {
|
||||
list.push({
|
||||
domType: 'plain',
|
||||
domId: 'wh-trans-welcome',
|
||||
domHTML: `<a href="/profiles.php?XID=${ glob.player_info.userID }" target="_blank">${ glob.player_info.playername }</a>[${ glob.player_info.userID }]`,
|
||||
domHTML:
|
||||
`<a href="/profiles.php?XID=${ userInfo.userID }" target="_blank">${ userInfo.playername }</a>[${ userInfo.userID }]`,
|
||||
});
|
||||
}
|
||||
// 节日
|
||||
@ -330,14 +333,14 @@ export default class ZhongIcon extends WuhuBase {
|
||||
domType: 'button',
|
||||
domId: 'wh-quick-fly-btn',
|
||||
domText: '✈️ 一键起飞',
|
||||
clickFunc: () => QuickFlyBtnHandler.getInstance().handle(),
|
||||
clickFunc: () => Container.factory(QuickFlyBtnHandler).handle(),
|
||||
});
|
||||
// 飞花库存
|
||||
list.push({
|
||||
domType: 'button',
|
||||
domId: 'wh-foreign-stock-btn',
|
||||
domText: '🌸 飞花库存',
|
||||
clickFunc: () => TravelItem.getInstance().clickHandler().then(),
|
||||
clickFunc: () => Container.factory(TravelItem).clickHandler().then(),
|
||||
});
|
||||
// NPC LOOT
|
||||
list.push({
|
||||
@ -355,14 +358,14 @@ export default class ZhongIcon extends WuhuBase {
|
||||
domType: 'button',
|
||||
domId: 'wh-nnb-info',
|
||||
domText: '👮 查看NNB',
|
||||
clickFunc: () => NNB.getInstance().handle(),
|
||||
clickFunc: () => this.nnb.handle(),
|
||||
});
|
||||
// 常用链接
|
||||
list.push({
|
||||
domType: 'button',
|
||||
domId: 'wh-link-collection',
|
||||
domText: '🔗 常用链接',
|
||||
clickFunc: () => QuickLinksHandler.getInstance().handle()
|
||||
clickFunc: () => Container.factory(QuickLinksHandler).handle()
|
||||
});
|
||||
// 飞贼
|
||||
// list.push({
|
||||
@ -378,10 +381,10 @@ export default class ZhongIcon extends WuhuBase {
|
||||
domType: 'button',
|
||||
domId: 'wh-price-watcher-btn',
|
||||
domText: '💊 价格监视',
|
||||
clickFunc: () => ItemPriceWatcherHandler.getInstance().handle()
|
||||
clickFunc: () => this.itemPriceWatcherHandler.handle()
|
||||
});
|
||||
// 全屏
|
||||
if (!Global.getInstance().isPDA) list.push({
|
||||
if (!this.tornPDAUtils.isPDA()) list.push({
|
||||
domType: 'button', domId: '', domText: '🖥️ 进入全屏', clickFunc() {
|
||||
document.documentElement.requestFullscreen().then();
|
||||
}
|
||||
@ -418,10 +421,10 @@ export default class ZhongIcon extends WuhuBase {
|
||||
// 助手设置
|
||||
list.push(SettingsHandler);
|
||||
// 测试
|
||||
if (Log.debug()) list.push(Test);
|
||||
if (this.logger.debug()) list.push(Test);
|
||||
|
||||
this.menuItemList = list;
|
||||
Log.info('构造展开菜单列表结束' + timer.getTimeMs());
|
||||
this.logger.info('构造展开菜单列表结束' + timer.getTimeMs());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import Log from "../Log";
|
||||
import Alert from "../utils/Alert";
|
||||
import Global from "../Global";
|
||||
import Device from "../../enum/Device";
|
||||
@ -14,6 +11,10 @@ import FetchUtils from "../utils/FetchUtils";
|
||||
import MathUtils from "../utils/MathUtils";
|
||||
import LoopHelper from "../utils/LoopHelper";
|
||||
import TRAVEL_STATE from "../../enum/TravelState";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
import Logger from "../Logger";
|
||||
|
||||
enum FIGHT_STAGE {
|
||||
READY = 'ready',
|
||||
@ -27,35 +28,46 @@ enum FIGHT_STAGE {
|
||||
* 战斗助手
|
||||
* TODO 页面加载已经在进行中的战斗时的正确判断
|
||||
*/
|
||||
export default class AttackHelper extends WuhuBase {
|
||||
className = 'AttackHelper';
|
||||
@Injectable()
|
||||
@ClassName('AttackHelper')
|
||||
export default class AttackHelper {
|
||||
|
||||
private currentStage: FIGHT_STAGE = FIGHT_STAGE.OTHER;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
window.setTimeout(() => this.urlMatch(), 0);
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly global: Global,
|
||||
private readonly mathUtils: MathUtils,
|
||||
private readonly actionButtonUtils: ActionButtonUtils,
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
}
|
||||
|
||||
private urlMatch(): void {
|
||||
init(): void {
|
||||
window.setTimeout(() => this.init(), 0);
|
||||
}
|
||||
|
||||
private _init() {
|
||||
if (window.location.href.contains(/loader\.php\?sid=attack/)) {
|
||||
this.fightingPageHandle();
|
||||
}
|
||||
// 错误的攻击页面转跳
|
||||
else if (window.location.href.includes('loader2.php') && WuhuConfig.get('attRelocate')) {
|
||||
else if (window.location.href.includes('loader2.php') && this.localConfigWrapper.config.attRelocate) {
|
||||
const spl = window.location.href.trim().split('=');
|
||||
const uid = spl[spl.length - 1];
|
||||
if (CommonUtils.getInstance().isValidUid(uid)) {
|
||||
if (this.commonUtils.isValidUid(uid)) {
|
||||
window.location.href = 'https://www.torn.com/loader.php?sid=attack&user2ID=' + uid;
|
||||
} else {
|
||||
Log.error('[AttackHelper] UID格式不正确');
|
||||
this.logger.error('[AttackHelper] UID格式不正确');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fightingPageHandle(): void {
|
||||
// 光速刷新按钮
|
||||
ActionButtonUtils.getInstance().add('光速刷新', () => this.doAttackReload());
|
||||
this.actionButtonUtils.add('光速刷新', () => this.doAttackReload());
|
||||
|
||||
// 盯梢
|
||||
this.watchTarget();
|
||||
@ -64,14 +76,14 @@ export default class AttackHelper extends WuhuBase {
|
||||
let btnList = document.querySelectorAll('div[class^="dialogButtons___"] button') as NodeListOf<HTMLButtonElement>;
|
||||
|
||||
if (btnList.length === 0) {
|
||||
if (this.currentStage === FIGHT_STAGE.READY && WuhuConfig.get('quickFinishAtt') === 3) {
|
||||
if (this.currentStage === FIGHT_STAGE.READY && this.localConfigWrapper.config.quickFinishAtt === 3) {
|
||||
document.body.classList.remove('wh-move-btn');
|
||||
Log.info('移除body class wh-move-btn');
|
||||
this.logger.info('移除body class wh-move-btn');
|
||||
observer.disconnect();
|
||||
}
|
||||
// 错误或正在打
|
||||
this.currentStage = FIGHT_STAGE.IN_PROGRESS_OR_ERROR;
|
||||
Log.info('[attackHelper] currentStage', this.currentStage);
|
||||
this.logger.info('[attackHelper] currentStage', this.currentStage);
|
||||
return;
|
||||
}
|
||||
btnList.forEach(btn => {
|
||||
@ -87,7 +99,7 @@ export default class AttackHelper extends WuhuBase {
|
||||
// 无意识状态FINISHED
|
||||
this.quickFinishFight(btnList);
|
||||
}
|
||||
Log.info('[attackHelper] currentStage', this.currentStage);
|
||||
this.logger.info('[attackHelper] currentStage', this.currentStage);
|
||||
})
|
||||
})
|
||||
.observe(document.querySelector('#react-root'), { childList: true, subtree: true });
|
||||
@ -97,17 +109,17 @@ export default class AttackHelper extends WuhuBase {
|
||||
private doAttackReload(): void {
|
||||
if (!window.ReactDOM) {
|
||||
new Alert('光速刷新失败:未找到React对象');
|
||||
Log.error('光速刷新失败:未找到React对象');
|
||||
this.logger.error('光速刷新失败:未找到React对象');
|
||||
return;
|
||||
}
|
||||
if (!document.querySelector('#react-root #attacker')) {
|
||||
Log.error('dom元素未找到selector: [#react-root #attacker]');
|
||||
this.logger.error('dom元素未找到selector: [#react-root #attacker]');
|
||||
return;
|
||||
}
|
||||
let script = document.querySelector('script[src*="/builds/attack/"]');
|
||||
let url = script.src;
|
||||
if (!url.contains(/runtime\..+\.js/)) {
|
||||
Log.error('脚本源[' + url + '] 不匹配规则');
|
||||
this.logger.error('脚本源[' + url + '] 不匹配规则');
|
||||
return;
|
||||
}
|
||||
window.ReactDOM.unmountComponentAtNode(document.querySelector('#react-root'));
|
||||
@ -125,32 +137,32 @@ export default class AttackHelper extends WuhuBase {
|
||||
} else {
|
||||
this.currentStage = FIGHT_STAGE.READY;
|
||||
}
|
||||
if (WuhuConfig.get('quickAttIndex') === 6) return;
|
||||
if (this.localConfigWrapper.config.quickAttIndex === 6) return;
|
||||
/**
|
||||
* pc #defender
|
||||
* mobile #attacker
|
||||
*/
|
||||
const btn = <HTMLInputElement>(document.querySelector('#attacker button') || document.querySelector('#defender button'));
|
||||
Log.info('操作按钮', { btn });
|
||||
this.logger.info('操作按钮', { btn });
|
||||
if (!btn.innerText.toLowerCase().includes('fight')) {
|
||||
Log.info('未找到攻击按钮, 光速拔刀跳过');
|
||||
this.logger.info('未找到攻击按钮, 光速拔刀跳过');
|
||||
new Alert('未找到攻击按钮, 光速拔刀跳过');
|
||||
} else {
|
||||
// 判断是否存在脚踢
|
||||
const hasKick = !!document.querySelector('#weapon_boots');
|
||||
// modal层
|
||||
// const modal: HTMLElement = document.querySelector('div[class^="modal___"]');
|
||||
let device = Global.getInstance().device;
|
||||
Log.info(`当前设备类型是${ device }`);
|
||||
let device = this.global.device;
|
||||
this.logger.info(`当前设备类型是${ device }`);
|
||||
// 区分设备
|
||||
switch (device) {
|
||||
case Device.PC: {
|
||||
Log.info(`开始调整按钮位置`);
|
||||
this.logger.info(`开始调整按钮位置`);
|
||||
// 隐藏modal层
|
||||
// modal.style.display = 'none';
|
||||
// 根据选择的武器调整css
|
||||
let css_top = '0';
|
||||
switch (WuhuConfig.get('quickAttIndex')) {
|
||||
switch (this.localConfigWrapper.config.quickAttIndex) {
|
||||
// weapon_second
|
||||
case 1: {
|
||||
css_top = '97px';
|
||||
@ -180,14 +192,14 @@ export default class AttackHelper extends WuhuBase {
|
||||
break;
|
||||
}
|
||||
case Device.MOBILE: {
|
||||
Log.info(`开始调整按钮位置`);
|
||||
this.logger.info(`开始调整按钮位置`);
|
||||
// 加入css
|
||||
let css_top = '0';
|
||||
let slot_height = '76px';
|
||||
// 判断有没有脚踢
|
||||
if (hasKick) {
|
||||
// 根据选择的武器调整
|
||||
switch (WuhuConfig.get('quickAttIndex')) {
|
||||
switch (this.localConfigWrapper.config.quickAttIndex) {
|
||||
case 1: { // weapon_second
|
||||
css_top = '76px';
|
||||
break;
|
||||
@ -215,7 +227,7 @@ export default class AttackHelper extends WuhuBase {
|
||||
// TODO 待验证
|
||||
slot_height = height + 'px';
|
||||
// 根据选择的武器调整
|
||||
switch (WuhuConfig.get('quickAttIndex')) {
|
||||
switch (this.localConfigWrapper.config.quickAttIndex) {
|
||||
case 1: { // weapon_second
|
||||
css_top = `${ height }px`;
|
||||
break;
|
||||
@ -249,7 +261,7 @@ export default class AttackHelper extends WuhuBase {
|
||||
CommonUtils.addStyle(css_rule);
|
||||
document.body.classList.toggle('wh-move-btn');
|
||||
btn.onclick = () => {
|
||||
if (WuhuConfig.get('quickFinishAtt') !== 3) {
|
||||
if (this.localConfigWrapper.config.quickFinishAtt !== 3) {
|
||||
btn.remove();
|
||||
// 停止自动刷新
|
||||
// stop_reload = true;
|
||||
@ -273,50 +285,50 @@ export default class AttackHelper extends WuhuBase {
|
||||
} else {
|
||||
this.currentStage = FIGHT_STAGE.FINISHED;
|
||||
}
|
||||
if (WuhuConfig.get('quickFinishAtt') === 3) {
|
||||
if (this.localConfigWrapper.config.quickFinishAtt === 3) {
|
||||
document.body.classList.remove('wh-move-btn');
|
||||
Log.info('移除body class wh-move-btn');
|
||||
this.logger.info('移除body class wh-move-btn');
|
||||
return;
|
||||
}
|
||||
const user_btn_select = ['leave', 'mug', 'hosp'][WuhuConfig.get('quickFinishAtt')];
|
||||
const user_btn_select = ['leave', 'mug', 'hosp'][this.localConfigWrapper.config.quickFinishAtt];
|
||||
// const wrap = document.querySelector('#react-root');
|
||||
Log.info('光速跑路选项选中:', user_btn_select);
|
||||
this.logger.info('光速跑路选项选中:', user_btn_select);
|
||||
// const btn_arr: HTMLButtonElement[] = document.querySelectorAll('div[class^="dialogButtons___"] button') as unknown as HTMLButtonElement[];
|
||||
if (btnList.length > 1) btnList.forEach(btn => {
|
||||
const flag = btn.innerText.toLowerCase().includes(user_btn_select);
|
||||
Log.info('按钮内容:', btn.innerText, ',是否包含选中:', flag);
|
||||
this.logger.info('按钮内容:', btn.innerText, ',是否包含选中:', flag);
|
||||
if (!flag) btn.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
// 盯梢模式
|
||||
private watchTarget(): void {
|
||||
Log.info('获取目标id');
|
||||
this.logger.info('获取目标id');
|
||||
let targetId = window.location.href.split('user2ID=')[1];
|
||||
if (!CommonUtils.getInstance().isValidUid(targetId)) {
|
||||
Log.error('目标id获取错误', targetId);
|
||||
if (!this.commonUtils.isValidUid(targetId)) {
|
||||
this.logger.error('目标id获取错误', targetId);
|
||||
throw new Error('目标id获取错误:' + targetId);
|
||||
}
|
||||
let loop = new LoopHelper(async () => {
|
||||
let userProfile;
|
||||
try {
|
||||
userProfile = await FetchUtils.getInstance().getProfile(targetId);
|
||||
userProfile = await this.fetchUtils.getProfile(targetId);
|
||||
} catch {
|
||||
Log.error('盯梢模式无法获取目标id');
|
||||
this.logger.error('盯梢模式无法获取目标id');
|
||||
throw new Error('盯梢模式无法获取目标id');
|
||||
}
|
||||
await CommonUtils.getInstance().sleep(MathUtils.getInstance().getRandomInt(20, 50));
|
||||
if ((userProfile.userStatus.status === 'ok' && CommonUtils.getInstance().getTravelStage() === TRAVEL_STATE.IN_TORN) ||
|
||||
(userProfile.userStatus.status === 'abroad' && CommonUtils.getInstance().getTravelStage() === TRAVEL_STATE.ABROAD)) {
|
||||
await this.commonUtils.sleep(this.mathUtils.getRandomInt(20, 50));
|
||||
if ((userProfile.userStatus.status === 'ok' && this.commonUtils.getTravelStage() === TRAVEL_STATE.IN_TORN) ||
|
||||
(userProfile.userStatus.status === 'abroad' && this.commonUtils.getTravelStage() === TRAVEL_STATE.ABROAD)) {
|
||||
watchSwitch.getInput().checked = false;
|
||||
window.setTimeout(async () => {
|
||||
new Alert('目标已落地/出院/出狱!', { timeout: 10, force: true, sysNotify: true });
|
||||
await CommonUtils.getInstance().audioPlay();
|
||||
await CommonUtils.getInstance().sleep(300);
|
||||
await CommonUtils.getInstance().audioPlay();
|
||||
await CommonUtils.getInstance().sleep(300);
|
||||
await CommonUtils.getInstance().audioPlay();
|
||||
await CommonUtils.getInstance().sleep(300);
|
||||
await this.commonUtils.audioPlay();
|
||||
await this.commonUtils.sleep(300);
|
||||
await this.commonUtils.audioPlay();
|
||||
await this.commonUtils.sleep(300);
|
||||
await this.commonUtils.audioPlay();
|
||||
await this.commonUtils.sleep(300);
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
@ -327,19 +339,19 @@ export default class AttackHelper extends WuhuBase {
|
||||
if (watchSwitch.getInput().checked) {
|
||||
new DialogMsgBox('检测玩家状态,当目标状态变成(海外)落地、出院或出狱时通知并播放声音提醒,后可搭配光速刷新食用<br/>确定开启?', {
|
||||
callback: () => {
|
||||
if (CommonUtils.getInstance().getTravelStage() === TRAVEL_STATE.FLYING) {
|
||||
if (this.commonUtils.getTravelStage() === TRAVEL_STATE.FLYING) {
|
||||
new Alert('失败!已取消');
|
||||
watchSwitch.getInput().checked = false;
|
||||
return;
|
||||
}
|
||||
Log.info('盯梢开启, 目标id' + targetId);
|
||||
loop.start(parseInt(WuhuConfig.get('WatchTargetFreq')));
|
||||
this.logger.info('盯梢开启, 目标id' + targetId);
|
||||
loop.start(this.localConfigWrapper.config.WatchTargetFreq | 0);
|
||||
},
|
||||
cancel: () => watchSwitch.getInput().checked = false
|
||||
});
|
||||
} else {
|
||||
loop.stop();
|
||||
Log.info('盯梢关闭');
|
||||
this.logger.info('盯梢关闭');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import Log from "../Log";
|
||||
import InfoUtils from "../utils/InfoUtils";
|
||||
@ -8,27 +7,36 @@ import NOTIFY_HTML from "../../../static/html/buyBeer/notify.html";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import Popup from "../utils/Popup";
|
||||
import ResponseInject from "../../interface/ResponseInject";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop, ResponseInject {
|
||||
className = 'BuyBeerHelper';
|
||||
@ClassName('BuyBeerHelper')
|
||||
@Injectable()
|
||||
export default class BuyBeerHelper implements BeerMonitorLoop, ResponseInject {
|
||||
|
||||
private isNotifying = false;
|
||||
private loopId: number = null;
|
||||
private time: number;
|
||||
private readonly notifyHtml: string = NOTIFY_HTML.replace('{{}}', MathUtils.getInstance().getRandomInt(0, 99).toString());
|
||||
private readonly notifyHtml: string = NOTIFY_HTML.replace('{{}}', this.mathUtils.getRandomInt(0, 99).toString());
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
this.time = WuhuConfig.get('_15AlarmTime') || 30;
|
||||
public constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly infoUtils: InfoUtils,
|
||||
private readonly mathUtils: MathUtils,
|
||||
) {
|
||||
this.time = this.localConfigWrapper.config._15AlarmTime || 30;
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
if (this.loopId) {
|
||||
Log.info('啤酒助手已在运行');
|
||||
} else {
|
||||
Log.info('啤酒助手启动');
|
||||
this.loopId = window.setInterval(async () => {
|
||||
// 海外取消提醒
|
||||
let { isTravelling, isAbroad } = await InfoUtils.getInstance().getUserState();
|
||||
let { isTravelling, isAbroad } = await this.infoUtils.getUserState();
|
||||
if (isTravelling || isAbroad) {
|
||||
this.stop();
|
||||
return;
|
||||
@ -36,7 +44,7 @@ export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop,
|
||||
let dt = new Date();
|
||||
// 已选当天不提醒
|
||||
const now = [dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate()];
|
||||
const ignore_date = WuhuConfig.get('_15_alarm_ignore') || '{}';
|
||||
const ignore_date = this.localConfigWrapper.config._15_alarm_ignore || '{}';
|
||||
if (JSON.stringify(now) === JSON.stringify(ignore_date)) return;
|
||||
// 正常提醒
|
||||
let m = 14 - (dt.getMinutes() % 15);
|
||||
@ -62,10 +70,15 @@ export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop,
|
||||
notify.close();
|
||||
}
|
||||
});
|
||||
let audioPlay = CommonUtils.getInstance().audioPlay;
|
||||
window.setTimeout(audioPlay, 800);
|
||||
window.setTimeout(audioPlay, 800 * 2);
|
||||
window.setTimeout(audioPlay, 800 * 3);
|
||||
// 声音提醒
|
||||
{
|
||||
let loop = 3;
|
||||
let id = window.setInterval(async () => {
|
||||
await this.commonUtils.audioPlay();
|
||||
loop--;
|
||||
if (!loop) window.clearInterval(id);
|
||||
}, 800);
|
||||
}
|
||||
} else {
|
||||
this.isNotifying = false;
|
||||
}
|
||||
@ -96,29 +109,29 @@ export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop,
|
||||
const date = new Date();
|
||||
WuhuConfig.set('_15_alarm_ignore', [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()], false);
|
||||
// 通知
|
||||
const notify = new Alert(`明早8点前将不再提醒 <button id="wh-rd-btn-${ MathUtils.getInstance().getRandomInt(0, 100) }">取消</button>`);
|
||||
const notify = new Alert(`明早8点前将不再提醒 <button id="wh-rd-btn-${ this.mathUtils.getRandomInt(0, 100) }">取消</button>`);
|
||||
// 通知中的取消按钮
|
||||
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => WuhuConfig.set('_15_alarm_ignore', undefined, true));
|
||||
}
|
||||
|
||||
public setTimeHandler(): void {
|
||||
let popup = new Popup(`<label>提前提醒时间(秒):<input type="number" value="${ WuhuConfig.get('_15AlarmTime') }" /></label><p>区间为 1 ~ 60,默认 50</p>`, '啤酒提醒时间设定');
|
||||
let popup = new Popup(`<label>提前提醒时间(秒):<input type="number" value="${ this.localConfigWrapper.config._15AlarmTime }" /></label><p>区间为 1 ~ 60,默认 50</p>`, '啤酒提醒时间设定');
|
||||
let confirm = document.createElement('button');
|
||||
confirm.innerHTML = '确定';
|
||||
confirm.style.float = 'right';
|
||||
confirm.addEventListener('click', () => {
|
||||
let input: HTMLInputElement = popup.getElement().querySelector('input');
|
||||
let input: HTMLInputElement = popup.element.querySelector('input');
|
||||
let num = (input.value as any) | 0;
|
||||
if (num === WuhuConfig.get('_15AlarmTime')) return;
|
||||
if (num === this.localConfigWrapper.config._15AlarmTime) return;
|
||||
if (num < 1 || num > 60) num = 50;
|
||||
input.value = num.toString();
|
||||
WuhuConfig.set('_15AlarmTime', num);
|
||||
this.localConfigWrapper.config._15AlarmTime = num;
|
||||
this.set_time(num);
|
||||
// 之前的运行状态
|
||||
if (this.is_running()) this.start();
|
||||
popup.close();
|
||||
});
|
||||
popup.getElement().appendChild(confirm);
|
||||
popup.element.appendChild(confirm);
|
||||
}
|
||||
|
||||
public responseHandler(url: string, body: { json: unknown; text: string; isModified: boolean }, opt: { method: "GET" | "POST"; requestBody: string }) {
|
||||
@ -126,7 +139,7 @@ export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop,
|
||||
let req = opt.requestBody;
|
||||
if (req && req.includes('step=buyShopItem') && req.includes('ID=180') && body.json && body.json['success']) {
|
||||
new Alert('检测到已成功购买啤酒');
|
||||
BuyBeerHelper.getInstance().skip_today();
|
||||
this.skip_today();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +1,38 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import Log from "../Log";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import FetchUtils from "../utils/FetchUtils";
|
||||
import InfoUtils from "../utils/InfoUtils";
|
||||
import Alert from "../utils/Alert";
|
||||
import TRAVEL_STATE from "../../enum/TravelState";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import Logger from "../Logger";
|
||||
|
||||
/**
|
||||
* 公司助手
|
||||
*/
|
||||
export default class CompanyHelper extends WuhuBase {
|
||||
@Injectable()
|
||||
@ClassName('CompanyHelper')
|
||||
export default class CompanyHelper {
|
||||
className = 'CompanyHelper';
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
WuhuConfig.get('CHTrainsDetectSwitch') && this.trainsDetect().then();
|
||||
public constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
private readonly logger: Logger,
|
||||
private readonly infoUtils: InfoUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public detectNow(): void {
|
||||
this.trainsDetect(true).then();
|
||||
init(): void {
|
||||
this.localConfigWrapper.config.CHTrainsDetectSwitch && this.trainsDetect().then();
|
||||
}
|
||||
|
||||
// public detectNow(): void {
|
||||
// this.trainsDetect(true).then();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 火车检测
|
||||
* 每日判断一次,非公司老板跳过检测
|
||||
@ -29,24 +40,24 @@ export default class CompanyHelper extends WuhuBase {
|
||||
*/
|
||||
private async trainsDetect(test: boolean = false): Promise<null> {
|
||||
// 通过用户的icon判断公司老板
|
||||
if ((await InfoUtils.getInstance().getSessionData()).statusIcons.icons.company.iconID !== 'icon73') {
|
||||
Log.info('火车检测跳过:非公司老板');
|
||||
if ((await this.infoUtils.getSessionData()).statusIcons.icons.company.iconID !== 'icon73') {
|
||||
this.logger.info('火车检测跳过:非公司老板');
|
||||
return;
|
||||
}
|
||||
// 上次检测时间戳
|
||||
let lastDetect: number = WuhuConfig.get('CHTrainsDetect') || 0;
|
||||
let lastDetect: number = this.localConfigWrapper.config.CHTrainsDetect || 0;
|
||||
// 检测是否过了一天
|
||||
if (test || CommonUtils.getInstance().isNewDay(lastDetect, -6)) {
|
||||
let travelStage = CommonUtils.getInstance().getTravelStage(),
|
||||
userStatus = (await InfoUtils.getInstance().getUserState()).status;
|
||||
test && Log.info({ travelStage, userStatus });
|
||||
if (test || this.commonUtils.isNewDay(lastDetect, -6)) {
|
||||
let travelStage = this.commonUtils.getTravelStage(),
|
||||
userStatus = (await this.infoUtils.getUserState()).status;
|
||||
test && this.logger.info({ travelStage, userStatus });
|
||||
if (travelStage === TRAVEL_STATE.IN_TORN && userStatus === 'ok')
|
||||
FetchUtils.getInstance().fetchText('/companies.php')
|
||||
this.fetchUtils.fetchText('/companies.php')
|
||||
.then(res => {
|
||||
let tmp: HTMLElement = document.createElement('div');
|
||||
let bodyTagStart = CommonUtils.getInstance().matchOne(res, /<body.+>/);
|
||||
let bodyTagStart = this.commonUtils.matchOne(res, /<body.+>/);
|
||||
if (!bodyTagStart) {
|
||||
Log.warn('火车检测: 无法获取数据');
|
||||
this.logger.warn('火车检测: 无法获取数据');
|
||||
throw new Error('火车检测: 无法获取数据');
|
||||
}
|
||||
tmp.innerHTML = res.split(bodyTagStart)[1].split('</body>')[0].trim()
|
||||
@ -55,14 +66,15 @@ export default class CompanyHelper extends WuhuBase {
|
||||
.replaceAll('type="text/javascript"', 'type="application/json"');
|
||||
let trainsNode = tmp.querySelector('span.trains');
|
||||
if (!trainsNode) {
|
||||
Log.error('火车检测出错: 无法获取火车数');
|
||||
this.logger.error('火车检测出错: 无法获取火车数');
|
||||
throw new Error('火车检测出错: 无法获取火车数');
|
||||
}
|
||||
let trains: number = parseInt(trainsNode.innerText);
|
||||
let stars: number = tmp.querySelectorAll('.company-rating .active').length / 2 || 1;
|
||||
WuhuConfig.set('CHTrainsDetect', Date.now());
|
||||
Log.info('火车检测: 火车/星级: ' + trains + '/' + stars);
|
||||
Log.info({ tmp });
|
||||
// WuhuConfig.set('CHTrainsDetect', Date.now());
|
||||
this.localConfigWrapper.config.CHTrainsDetect = Date.now();
|
||||
this.logger.info('火车检测: 火车/星级: ' + trains + '/' + stars);
|
||||
this.logger.info({ tmp });
|
||||
if (trains + stars > 20) {
|
||||
new Alert(`公司助手<br/><br/>火车检测:火车明日将溢出!${ trains }/20火车`, {
|
||||
timeout: 15,
|
||||
@ -74,11 +86,11 @@ export default class CompanyHelper extends WuhuBase {
|
||||
tmp = null;
|
||||
})
|
||||
.catch(error => {
|
||||
Log.error('火车检测出错', error);
|
||||
this.logger.error('火车检测出错', error);
|
||||
});
|
||||
else Log.warn('[火车检测] 用户状态错误,跳过火车检测', { travelStage, userStatus });
|
||||
else this.logger.warn('[火车检测] 用户状态错误,跳过火车检测', { travelStage, userStatus });
|
||||
} else {
|
||||
Log.info('火车检测:今日已提醒,跳过');
|
||||
this.logger.info('火车检测:今日已提醒,跳过');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,26 @@
|
||||
import { MiniProfile } from "../../interface/responseType/MiniProfile";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import Provider from "../provider/Provider";
|
||||
import ResponseInject from "../../interface/ResponseInject";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
|
||||
/**
|
||||
* fetch 事件监听回调
|
||||
*/
|
||||
@Injectable()
|
||||
@ClassName("FetchEventCallback")
|
||||
export default class FetchEventCallback extends Provider implements ResponseInject {
|
||||
className = "FetchEventCallback";
|
||||
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch 返回后处理
|
||||
* @param url
|
||||
@ -17,12 +28,12 @@ export default class FetchEventCallback extends Provider implements ResponseInje
|
||||
*/
|
||||
public responseHandler(url: string, response) {
|
||||
// mini profile 中添加上次动作
|
||||
if (url.includes('profiles.php?step=getUserNameContextMenu') && WuhuConfig.get('ShowMiniProfLastAct')) {
|
||||
if (url.includes('profiles.php?step=getUserNameContextMenu') && this.localConfigWrapper.config.ShowMiniProfLastAct) {
|
||||
window.setTimeout(async () => {
|
||||
let cont = CommonUtils.querySelector('[class*=profile-mini-_userProfileWrapper___]');
|
||||
let resp: MiniProfile = response.json as MiniProfile;
|
||||
let newNode = document.createElement('div');
|
||||
let formatted = CommonUtils.getInstance().secondsFormat(resp.user.lastAction.seconds);
|
||||
let formatted = this.commonUtils.secondsFormat(resp.user.lastAction.seconds);
|
||||
|
||||
newNode.innerText = '上次动作: ' + formatted;
|
||||
(await cont).append(newNode);
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Log from "../Log";
|
||||
import InfoUtils from "../utils/InfoUtils";
|
||||
import MathUtils from "../utils/MathUtils";
|
||||
@ -6,12 +5,15 @@ import CommonUtils from "../utils/CommonUtils";
|
||||
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||
import Timer from "../utils/Timer";
|
||||
import FetchUtils from "../utils/FetchUtils";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
|
||||
/**
|
||||
* 彩票助手
|
||||
*/
|
||||
export default class LotteryHelper extends WuhuBase {
|
||||
className = 'LotteryHelper';
|
||||
@Injectable()
|
||||
@ClassName('LotteryHelper')
|
||||
export default class LotteryHelper {
|
||||
private loopFlag = true;
|
||||
|
||||
private radioDaily: HTMLInputElement = null;
|
||||
@ -24,7 +26,13 @@ export default class LotteryHelper extends WuhuBase {
|
||||
private status: HTMLElement = null;
|
||||
private desc: HTMLElement = null;
|
||||
|
||||
private readonly mathUtils = MathUtils.getInstance();
|
||||
constructor(
|
||||
private readonly mathUtils: MathUtils,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
private readonly infoUtils: InfoUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public init() {
|
||||
let startTime = new Timer();
|
||||
@ -118,7 +126,7 @@ export default class LotteryHelper extends WuhuBase {
|
||||
if (inputNumber > 0) {
|
||||
let msg = document.querySelector('.info-msg-wrap .msg').innerText.trim().split(' ');
|
||||
let current = {
|
||||
money: (await InfoUtils.getInstance().getSessionData()).user.money.value,
|
||||
money: (await this.infoUtils.getSessionData()).user.money.value,
|
||||
token: parseInt(msg[4])
|
||||
};
|
||||
let lotteryType = 1;
|
||||
@ -136,12 +144,12 @@ export default class LotteryHelper extends WuhuBase {
|
||||
rsMsg = `终止操作,已完成${ i }/${ inputNumber }`;
|
||||
break;
|
||||
}
|
||||
await FetchUtils.getInstance().ajaxFetch({
|
||||
await this.fetchUtils.ajaxFetch({
|
||||
url: window.addRFC('https://www.torn.com/loader.php?sid=lotteryPlay&step=buyTicket&lotteryID=' + lotteryType),
|
||||
method: 'GET',
|
||||
referrer: '/loader.php?sid=lottery',
|
||||
});
|
||||
await CommonUtils.getInstance().sleep(this.mathUtils.getRandomInt(20, 50));
|
||||
await this.commonUtils.sleep(this.mathUtils.getRandomInt(20, 50));
|
||||
i++;
|
||||
this.desc.innerHTML = `已买${ i }张彩票`;
|
||||
this.status.innerHTML = `${ i }/${ inputNumber }`;
|
||||
|
||||
@ -1,16 +1,19 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import Alert from "../utils/Alert";
|
||||
import TornStyleSwitch from "../utils/TornStyleSwitch";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
|
||||
export default class PTHelper extends WuhuBase {
|
||||
className = 'PTHelper';
|
||||
@Injectable()
|
||||
@ClassName('PTHelper')
|
||||
export default class PTHelper {
|
||||
private readonly observer;
|
||||
private readonly usersPointSell;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
) {
|
||||
this.observer = new MutationObserver(e => {
|
||||
for (const t of e) {
|
||||
t.addedNodes.forEach(e => 'LI' === (e as HTMLElement).tagName && this.removeConfirm(e))
|
||||
@ -22,7 +25,7 @@ export default class PTHelper extends WuhuBase {
|
||||
let switcher = new TornStyleSwitch('开启');
|
||||
block.append(switcher.getBase());
|
||||
let toggle = switcher.getInput();
|
||||
toggle.checked = WuhuConfig.get('ptQuickBuy');
|
||||
toggle.checked = this.localConfigWrapper.config.ptQuickBuy;
|
||||
if (toggle.checked) {
|
||||
new Alert('一键购买已开启');
|
||||
for (const index in this.usersPointSell.children) {
|
||||
@ -31,7 +34,7 @@ export default class PTHelper extends WuhuBase {
|
||||
this.observer.observe(this.usersPointSell, { childList: true })
|
||||
}
|
||||
toggle.addEventListener('change', () => {
|
||||
WuhuConfig.set('ptQuickBuy', toggle.checked, false);
|
||||
this.localConfigWrapper.config.ptQuickBuy = toggle.checked;
|
||||
if (toggle.checked) {
|
||||
for (const index in this.usersPointSell.children) {
|
||||
'LI' === this.usersPointSell.children[index].tagName && this.removeConfirm(this.usersPointSell.children[index])
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Log from "../Log";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||
@ -7,37 +5,45 @@ import TornStyleSwitch from "../utils/TornStyleSwitch";
|
||||
import ResponseInject from "../../interface/ResponseInject";
|
||||
import globVars from "../../globVars";
|
||||
import IUserProfileData from "../../interface/IUserProfileData";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
import Logger from "../Logger";
|
||||
|
||||
export default class ProfileHelper extends WuhuBase implements ResponseInject {
|
||||
className = 'ProfileHelper';
|
||||
@ClassName('ProfileHelper')
|
||||
@Injectable()
|
||||
export default class ProfileHelper implements ResponseInject {
|
||||
|
||||
private readonly block;
|
||||
|
||||
// 曾用名已检测过标记
|
||||
private task = true;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
CommonUtils.addStyle('body.wh-hide_profile_img .profile-image a.profile-image-wrapper .img-wrap img{display:none;}');
|
||||
// let id = document.querySelector('link[rel="canonical"]').getAttribute('href').split('=')[1];
|
||||
let id = (new URL(window.location.href)).searchParams.get('XID');
|
||||
// id获取格式判断
|
||||
if (!CommonUtils.getInstance().isValidUid(id)) {
|
||||
Log.error('[ProfileHelper] id格式错误');
|
||||
if (!this.commonUtils.isValidUid(id)) {
|
||||
this.logger.error('[ProfileHelper] id格式错误');
|
||||
}
|
||||
if (WuhuConfig.get('HideProfileImg')) {
|
||||
Log.info('[ProfileHelper] 隐藏头像');
|
||||
if (this.localConfigWrapper.config.HideProfileImg) {
|
||||
this.logger.info('[ProfileHelper] 隐藏头像');
|
||||
document.body.classList.toggle('wh-hide_profile_img');
|
||||
}
|
||||
this.block = new TornStyleBlock('芜湖助手').insert2Dom();
|
||||
// 隐藏头像
|
||||
let hideImgSwitch = new TornStyleSwitch('隐藏头像', WuhuConfig.get('HideProfileImg'));
|
||||
let hideImgSwitch = new TornStyleSwitch('隐藏头像', this.localConfigWrapper.config.HideProfileImg);
|
||||
this.block.append(hideImgSwitch.getBase());
|
||||
hideImgSwitch.getInput().addEventListener('change', () => {
|
||||
document.body.classList.toggle('wh-hide_profile_img');
|
||||
WuhuConfig.set('HideProfileImg', hideImgSwitch.getInput().checked, true);
|
||||
});
|
||||
if (WuhuConfig.get('ShowNameHistory')) {
|
||||
if (this.localConfigWrapper.config.ShowNameHistory) {
|
||||
globVars.responseHandlers.push((url, body) => this.responseHandler(url, body));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||
import TornStyleSwitch from "../utils/TornStyleSwitch";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
|
||||
export default class SearchHelper extends WuhuBase {
|
||||
className = 'SearchHelper';
|
||||
@ClassName('SearchHelper')
|
||||
@Injectable()
|
||||
export default class SearchHelper {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
) {
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
@ -16,7 +19,7 @@ export default class SearchHelper extends WuhuBase {
|
||||
let placeholderSwitch = new TornStyleSwitch('底部空白占位区');
|
||||
block.append(placeholderSwitch.getBase()).insert2Dom();
|
||||
CommonUtils.addStyle('body.WHSearchPagePlaceholder .content.logged-in {margin-bottom: 340px;}');
|
||||
let config = WuhuConfig.get('SearchPagePlaceholder');
|
||||
let config = this.localConfigWrapper.config.SearchPagePlaceholder;
|
||||
placeholderSwitch.getInput().checked = config || false;
|
||||
config ? this.enable() : this.disable();
|
||||
placeholderSwitch.getInput().addEventListener('change', () => {
|
||||
@ -26,11 +29,11 @@ export default class SearchHelper extends WuhuBase {
|
||||
|
||||
private enable(): void {
|
||||
document.body.classList.add('WHSearchPagePlaceholder');
|
||||
WuhuConfig.set('SearchPagePlaceholder', true);
|
||||
this.localConfigWrapper.config.SearchPagePlaceholder = true;
|
||||
}
|
||||
|
||||
private disable(): void {
|
||||
document.body.classList.remove('WHSearchPagePlaceholder');
|
||||
WuhuConfig.set('SearchPagePlaceholder', false);
|
||||
this.localConfigWrapper.config.SearchPagePlaceholder = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +1,34 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import Global from "../Global";
|
||||
import Device from "../../enum/Device";
|
||||
import Log from "../Log";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
|
||||
/**
|
||||
* ### 边栏助手
|
||||
* - 隐藏按钮
|
||||
* - 4条转跳
|
||||
*/
|
||||
export default class SidebarHelper extends WuhuBase {
|
||||
className = 'SidebarHelper';
|
||||
@ClassName('SidebarHelper')
|
||||
@Injectable()
|
||||
export default class SidebarHelper {
|
||||
|
||||
private readonly sidebarRootNode: HTMLElement;
|
||||
private readonly toggleBtn: HTMLButtonElement;
|
||||
private isHide: boolean;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly global: Global,
|
||||
) {
|
||||
this.sidebarRootNode = document.querySelector('#sidebarroot');
|
||||
this.toggleBtn = document.createElement('button');
|
||||
this.isHide = !!WuhuConfig.get('HideSidebar');
|
||||
}
|
||||
|
||||
init(): void {
|
||||
this.isHide = !!this.localConfigWrapper.config.HideSidebar;
|
||||
|
||||
if (!document.body.classList.contains('without-sidebar') || window.location.href.includes('christmas_town.php')) {
|
||||
this.initToggleBtn();
|
||||
@ -33,7 +40,7 @@ export default class SidebarHelper extends WuhuBase {
|
||||
|
||||
// 初始化隐藏按钮
|
||||
private initToggleBtn(): void {
|
||||
if (Global.getInstance().device === Device.PC && this.sidebarRootNode && WuhuConfig.get('HideSidebarBtn')) {
|
||||
if (this.global.device === Device.PC && this.sidebarRootNode && this.localConfigWrapper.config.HideSidebarBtn) {
|
||||
this.isHide ? this.hideHandler() : this.showHandler();
|
||||
let container = document.createElement('div');
|
||||
container.append(this.toggleBtn);
|
||||
@ -50,19 +57,21 @@ export default class SidebarHelper extends WuhuBase {
|
||||
|
||||
private hideHandler(): void {
|
||||
this.sidebarRootNode.classList.add('wh-hide');
|
||||
this.isHide = WuhuConfig.set('HideSidebar', true);
|
||||
this.localConfigWrapper.config.HideSidebar = true;
|
||||
this.isHide = true;
|
||||
this.toggleBtn.innerHTML = '>>';
|
||||
}
|
||||
|
||||
private showHandler(): void {
|
||||
this.sidebarRootNode.classList.remove('wh-hide');
|
||||
this.isHide = WuhuConfig.set('HideSidebar', false);
|
||||
this.localConfigWrapper.config.HideSidebar = false;
|
||||
this.isHide = false;
|
||||
this.toggleBtn.innerHTML = '<<';
|
||||
}
|
||||
|
||||
// 4条转跳
|
||||
private barRedirect(): void {
|
||||
if (WuhuConfig.get('barsRedirect')) {
|
||||
if (this.localConfigWrapper.config.barsRedirect) {
|
||||
const eb = document.getElementById('barEnergy') as HTMLAnchorElement;
|
||||
const nb = document.getElementById('barNerve') as HTMLAnchorElement;
|
||||
const hb = document.getElementById('barHappy') as HTMLAnchorElement;
|
||||
|
||||
@ -1,16 +1,26 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||
import InfoUtils from "../utils/InfoUtils";
|
||||
import Log from "../Log";
|
||||
import FetchUtils from "../utils/FetchUtils";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import MathUtils from "../utils/MathUtils";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
/**
|
||||
* 老虎机批量购买助手
|
||||
*/
|
||||
export default class SlotsHelper extends WuhuBase {
|
||||
className = "SlotsHelper";
|
||||
@ClassName("SlotsHelper")
|
||||
@Injectable()
|
||||
export default class SlotsHelper {
|
||||
|
||||
constructor(
|
||||
private readonly mathUtils: MathUtils,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
private readonly infoUtils: InfoUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
private block = new TornStyleBlock("芜湖助手");
|
||||
|
||||
@ -68,7 +78,7 @@ export default class SlotsHelper extends WuhuBase {
|
||||
private async goBtnHandler(ev: MouseEvent, nodes: SlotsHelperNodes) {
|
||||
let { counterInput, select, msgBox } = nodes;
|
||||
// 现金
|
||||
let cash = (await InfoUtils.getInstance().getSessionData())?.user?.money?.value;
|
||||
let cash = (await this.infoUtils.getSessionData())?.user?.money?.value;
|
||||
msgBox.innerText = '等待加载中';
|
||||
// 代币
|
||||
let tokens: number = parseInt((await CommonUtils.querySelector('.player-info-cont #tokens')).innerText);
|
||||
@ -89,7 +99,7 @@ export default class SlotsHelper extends WuhuBase {
|
||||
// 实际购买数量
|
||||
let i: number;
|
||||
for (i = 0; i < count; i++) {
|
||||
let res: SlotsResponse = await (await FetchUtils.getInstance().ajaxFetch({
|
||||
let res: SlotsResponse = await (await this.fetchUtils.ajaxFetch({
|
||||
url: window.addRFC("https://www.torn.com/loader.php?sid=slotsInterface&step=play&stake=" + price),
|
||||
referrer: "/loader.php?sid=slots",
|
||||
method: "GET"
|
||||
@ -100,7 +110,7 @@ export default class SlotsHelper extends WuhuBase {
|
||||
msgBox.innerHTML += '<br/>代币不足';
|
||||
break;
|
||||
}
|
||||
await CommonUtils.getInstance().sleep(MathUtils.getInstance().getRandomInt(1800, 2400));
|
||||
await this.commonUtils.sleep(this.mathUtils.getRandomInt(1800, 2400));
|
||||
}
|
||||
// 利润
|
||||
let profit = wonTotal - i * price;
|
||||
|
||||
@ -1,17 +1,21 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import TornStyleSwitch from "../utils/TornStyleSwitch";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
|
||||
export default class StackHelper extends WuhuBase {
|
||||
className = 'StackHelper';
|
||||
constructor() {
|
||||
super();
|
||||
@Injectable()
|
||||
@ClassName('StackHelper')
|
||||
export default class StackHelper {
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
) {
|
||||
let block = new TornStyleBlock('叠E保护').insert2Dom();
|
||||
let switcher = new TornStyleSwitch('启用');
|
||||
let input = switcher.getInput();
|
||||
block.append(switcher.getBase());
|
||||
input.checked = WuhuConfig.get('SEProtect');
|
||||
input.checked = this.localConfigWrapper.config.SEProtect;
|
||||
if (input.checked) document.body.classList.add('wh-gym-stack');
|
||||
// 绑定点击事件
|
||||
input.onchange = e => {
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import { chatDict, eventsDict, headerDict, propertyDict, sidebarDict } from "../../dictionary/translation";
|
||||
import Log from "../Log";
|
||||
import Timer from "../utils/Timer";
|
||||
|
||||
export default class Translate extends WuhuBase {
|
||||
className = 'Translate';
|
||||
/**
|
||||
* @deprecated 使用TranslateNew替代
|
||||
*/
|
||||
export default class Translate {
|
||||
|
||||
public translateVer: string = '1.0';
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
Log.info('翻译开始');
|
||||
let start = new Timer();
|
||||
// 时分秒转换
|
||||
|
||||
@ -1,18 +1,29 @@
|
||||
import ResponseInject from "../../interface/ResponseInject";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import { Button, MiniProfile } from "../../interface/responseType/MiniProfile";
|
||||
import Log from "../Log";
|
||||
import Sidebar from "../../interface/responseType/Sidebar";
|
||||
import InventoryItemInfo from "../../interface/responseType/InventoryItemInfo";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import { itemNameDict, itemPageDict } from "../../dictionary/translation";
|
||||
import Provider from "../provider/Provider";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
import Logger from "../Logger";
|
||||
|
||||
/**
|
||||
* 翻译重构
|
||||
*/
|
||||
@ClassName('TranslateNew')
|
||||
@Injectable()
|
||||
export default class TranslateNew extends Provider implements ResponseInject {
|
||||
className = 'TranslateNew';
|
||||
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly logger: Logger,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch xhr 返回数据的翻译处理
|
||||
@ -20,8 +31,12 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
* @param body
|
||||
* @param opt
|
||||
*/
|
||||
public responseHandler(url: string, body: { json: unknown, text: string, isModified: boolean }, opt: { method: 'GET' | 'POST', requestBody: string }): void {
|
||||
if (!WuhuConfig.get('transNew')) return;
|
||||
public responseHandler(
|
||||
url: string,
|
||||
body: { json: unknown, text: string, isModified: boolean },
|
||||
opt: { method: 'GET' | 'POST', requestBody: string }
|
||||
): void {
|
||||
if (!this.localConfigWrapper.config.transNew) return;
|
||||
// TODO 字典抽取
|
||||
let map = {
|
||||
iconMap: {
|
||||
@ -66,7 +81,7 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
'Attacked': '攻击',
|
||||
'Defeated': '击败',
|
||||
},
|
||||
{ 'someone': '某人' },
|
||||
{ 'someone': '某人2' },
|
||||
{ '<br><i>Early discharge available</i>': '<br><i>提前出院(ED)可用</i>' },
|
||||
],
|
||||
}
|
||||
@ -206,7 +221,7 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
// Mini Profile
|
||||
if (url.includes('profiles.php?step=getUserNameContextMenu')) {
|
||||
let jsonObj: MiniProfile = body.json as MiniProfile;
|
||||
Log.info('翻译mini profile返回内容');
|
||||
this.logger.info('翻译mini profile返回内容');
|
||||
// 状态图标
|
||||
jsonObj.icons.forEach(icon => {
|
||||
let iconMap = map.iconMap;
|
||||
@ -223,7 +238,7 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
if (desc.attachedMap) {
|
||||
desc.attachedMap.forEach((item, index) => {
|
||||
let factor = oriDesc.replace(new RegExp(desc.replace[0]), '$' + (index + 1));
|
||||
Log.info({ factor });
|
||||
this.logger.info({ factor });
|
||||
let cn = item[factor];
|
||||
cn && (icon.description = icon.description.replace(factor, cn));
|
||||
});
|
||||
@ -282,7 +297,7 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
}
|
||||
body.isModified = true;
|
||||
|
||||
Log.info({ 'localized': jsonObj });
|
||||
this.logger.info({ 'localized': jsonObj });
|
||||
}
|
||||
// TODO 边栏
|
||||
else if (url.includes('sidebarAjaxAction.php?q=sync')) {
|
||||
@ -306,7 +321,7 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
// 物品详情
|
||||
else if ((url.includes('inventory.php?step=info')) || (url.includes('inventory.php') && opt?.method === 'POST' &&
|
||||
typeof opt?.requestBody === 'string' && opt?.requestBody.includes('step=info'))) {
|
||||
Log.info('responseHandler');
|
||||
this.logger.info('responseHandler');
|
||||
let resp = body.json as InventoryItemInfo;
|
||||
// TODO 维护通用物品数据(对应名称、描述、类型)缓存
|
||||
let map: { [k: string]: Partial<InventoryItemInfo> } = {
|
||||
@ -322,7 +337,7 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
},
|
||||
};
|
||||
let idMap = { 816: 'Glass of Beer' };
|
||||
let itemInfo = CommonUtils.getInstance().getItemByIdOrName(resp.itemName, idMap, map);
|
||||
let itemInfo = this.commonUtils.getItemByIdOrName(resp.itemName, idMap, map);
|
||||
if (itemInfo) {
|
||||
body.isModified = true;
|
||||
resp.itemInfo = itemInfo.itemInfo;
|
||||
@ -349,7 +364,7 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
if (resp.html) {
|
||||
let tmp = document.createElement('div');
|
||||
tmp.innerHTML = resp.html;
|
||||
Log.info(tmp);
|
||||
this.logger.info(tmp);
|
||||
tmp.childNodes.forEach(li => {
|
||||
if (li.nodeType === 1) {
|
||||
let elem = li as Element;
|
||||
@ -380,7 +395,7 @@ export default class TranslateNew extends Provider implements ResponseInject {
|
||||
typeof opt?.requestBody === 'string' && opt?.requestBody.includes('step=getList')) {
|
||||
}
|
||||
} catch (e) {
|
||||
Log.error('responseHandler', e.stack || e.message);
|
||||
this.logger.error('responseHandler', e.stack || e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import Log from "../Log";
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import UserScriptEngine from "../../enum/UserScriptEngine";
|
||||
import Popup from "../utils/Popup";
|
||||
import STOCK_IMG_HTML from "../../../static/html/stock_img.html";
|
||||
@ -8,27 +6,38 @@ import * as FILTER from "../../../static/json/for_stock_item_filter.json";
|
||||
import WindowActiveState from "./WindowActiveState";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import Logger from "../Logger";
|
||||
|
||||
@Injectable()
|
||||
@ClassName('TravelItem')
|
||||
export default class TravelItem extends WuhuBase {
|
||||
className = 'TravelItem';
|
||||
export default class TravelItem {
|
||||
private readonly apiUrl: string = 'https://yata.yt/api/v1/travel/export/';
|
||||
private foreignStockInfo: any = null;
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
public constructor(
|
||||
private readonly windowActiveState: WindowActiveState,
|
||||
private readonly logger: Logger,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public init() {
|
||||
|
||||
window.setInterval(async () => {
|
||||
if (!WindowActiveState.getInstance().get()) return;
|
||||
Log.info('COFetch ', this.apiUrl);
|
||||
if (!this.windowActiveState.get()) return;
|
||||
this.logger.info('COFetch ', this.apiUrl);
|
||||
try {
|
||||
this.foreignStockInfo = JSON.parse(await CommonUtils.COFetch(this.apiUrl));
|
||||
Log.info({ info: 'TravelItem 跨域返回', 'returned': this.foreignStockInfo });
|
||||
} catch (e) {
|
||||
this.logger.error('解析错误', e.stack || e.message || e);
|
||||
}
|
||||
this.logger.info({ info: 'TravelItem 跨域返回', 'returned': this.foreignStockInfo });
|
||||
}, 30 * 1000);
|
||||
}
|
||||
|
||||
// 呈现内容
|
||||
public async clickHandler(): Promise<void> {
|
||||
if (CommonUtils.getScriptEngine() === UserScriptEngine.RAW) {
|
||||
if (this.commonUtils.getScriptEngine() === UserScriptEngine.RAW) {
|
||||
new Popup(STOCK_IMG_HTML.replace('{{}}', performance.now().toString()), '飞花库存');
|
||||
} else {
|
||||
const popup = new Popup("请稍后 " + CommonUtils.loading_gif_html(), '飞花库存');
|
||||
@ -36,7 +45,7 @@ export default class TravelItem extends WuhuBase {
|
||||
const dest = FILTER.default;
|
||||
const now = new Date();
|
||||
const res = await this.get();
|
||||
Log.info({ res })
|
||||
this.logger.info({ res })
|
||||
if (!res || !res.stocks) return;
|
||||
dest.forEach(el => {
|
||||
const update = (now.getTime() - new Date(res.stocks[el.name]['update'] * 1000).getTime()) / 1000 | 0
|
||||
@ -60,6 +69,11 @@ export default class TravelItem extends WuhuBase {
|
||||
}
|
||||
|
||||
private async get() {
|
||||
try {
|
||||
return this.foreignStockInfo ||= JSON.parse(await CommonUtils.COFetch(this.apiUrl));
|
||||
} catch (e) {
|
||||
this.logger.error('解析出错', e.stack || e.message || e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
import uuidv4 from "../../func/utils/uuidv4";
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
export default class WindowActiveState extends WuhuBase {
|
||||
className = 'WindowActiveState';
|
||||
isFocus = false;
|
||||
uuid = uuidv4();
|
||||
@ClassName('WindowActiveState')
|
||||
@Injectable()
|
||||
export default class WindowActiveState {
|
||||
private isFocus = false;
|
||||
private uuid = uuidv4();
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
if (self !== top) return null;
|
||||
localStorage.setItem('whuuid', this.uuid);
|
||||
document.addEventListener('visibilitychange',
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import XUNZHAOMUZHUANG_HTML from "../../../static/html/xunzhaomuzhuang/index.html";
|
||||
import * as MUZHUANG_ID_LIST_JSON from "../../../static/json/muzhuang_id_list.json";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
@ -6,12 +5,16 @@ import XUNZHAOMUZHUANG_CSS from "../../../static/css/xunzhaomuzhuang.css";
|
||||
import TornStyleBlock from "../utils/TornStyleBlock";
|
||||
import MathUtils from "../utils/MathUtils";
|
||||
import FetchUtils from "../utils/FetchUtils";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
/**
|
||||
* 寻找木桩
|
||||
* /item.php?temp=4#xunzhaomuzhuang
|
||||
*/
|
||||
export default class XZMZ extends WuhuBase {
|
||||
@ClassName('XZMZ')
|
||||
@Injectable()
|
||||
export default class XZMZ {
|
||||
className = 'XZMZ';
|
||||
private mainRoleContainer: HTMLElement;
|
||||
private IDList: number[];
|
||||
@ -21,8 +24,11 @@ export default class XZMZ extends WuhuBase {
|
||||
private tips: HTMLElement;
|
||||
private counter: number;
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
public constructor(
|
||||
private readonly mathUtils: MathUtils,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public init() {
|
||||
@ -65,7 +71,7 @@ export default class XZMZ extends WuhuBase {
|
||||
}
|
||||
|
||||
private async SearchDeadman(id) {
|
||||
FetchUtils.getInstance().getProfile(id).then((res) => {
|
||||
this.fetchUtils.getProfile(id).then((res) => {
|
||||
if (res.userStatus.status.type === 'ok') {
|
||||
this.addRow({
|
||||
player_id: res.user.userID,
|
||||
@ -74,7 +80,7 @@ export default class XZMZ extends WuhuBase {
|
||||
});
|
||||
}
|
||||
});
|
||||
await CommonUtils.getInstance().sleep(MathUtils.getInstance().getRandomInt(100, 200));
|
||||
await this.commonUtils.sleep(this.mathUtils.getRandomInt(100, 200));
|
||||
}
|
||||
|
||||
private addRow(data) {
|
||||
|
||||
@ -16,6 +16,10 @@ const defaultConfig = {
|
||||
trvAlarm: true,
|
||||
// 啤酒提醒
|
||||
_15Alarm: true,
|
||||
// 啤酒提醒时间
|
||||
_15AlarmTime: 50,
|
||||
// 啤酒提醒忽略当天
|
||||
_15_alarm_ignore: '',
|
||||
// 捡垃圾助手
|
||||
cityFinder: false,
|
||||
// 叠E保护
|
||||
@ -34,8 +38,6 @@ const defaultConfig = {
|
||||
priceWatcher: { xan: -1, pt: -1 },
|
||||
// 开发者模式
|
||||
isDev: false,
|
||||
// 啤酒提醒时间
|
||||
_15AlarmTime: 50,
|
||||
// 4条转跳
|
||||
barsRedirect: true,
|
||||
// 浮动存钱框
|
||||
@ -69,7 +71,7 @@ const defaultConfig = {
|
||||
// 解决一直转圈(加载中)的问题
|
||||
SolveGoogleScriptPendingIssue: false,
|
||||
// 图标坐标
|
||||
IconPosition: {},
|
||||
IconPosition: {} as { x: number, y: number },
|
||||
// 记住图标位置
|
||||
SaveIconPosition: false,
|
||||
// 现金变动提醒
|
||||
@ -80,7 +82,101 @@ const defaultConfig = {
|
||||
ShowMiniProfLastAct: true,
|
||||
// 自定义css
|
||||
CustomCss: '',
|
||||
|
||||
/** @deprecated */
|
||||
attRelocate: false,
|
||||
};
|
||||
// } as const;
|
||||
|
||||
export default defaultConfig;
|
||||
// export default defaultConfig;
|
||||
|
||||
class DefaultConfigType {
|
||||
// 开启翻译
|
||||
transEnable = false;
|
||||
transNew = true;
|
||||
// 快速犯罪
|
||||
quickCrime = true;
|
||||
// 任务助手
|
||||
missionHint = true;
|
||||
// 小镇攻略
|
||||
xmasTownWT = true;
|
||||
// 小镇提醒
|
||||
xmasTownNotify = true;
|
||||
// 起飞爆e
|
||||
energyAlert = true;
|
||||
// 飞行闹钟
|
||||
trvAlarm = true;
|
||||
// 啤酒提醒
|
||||
_15Alarm = true;
|
||||
_15_alarm_ignore = false;
|
||||
// 啤酒提醒时间
|
||||
_15AlarmTime = 50;
|
||||
// 捡垃圾助手
|
||||
cityFinder = false;
|
||||
// 叠E保护
|
||||
SEProtect = false;
|
||||
// PT一键购买
|
||||
ptQuickBuy = false;
|
||||
// 光速拔刀 6-关闭
|
||||
quickAttIndex = 2;
|
||||
// 光速跑路 0-leave 1-mug 2-hos 3-关闭
|
||||
quickFinishAtt = 3;
|
||||
// 自动开打和结束
|
||||
autoStartFinish = false;
|
||||
// 攻击自刷新 0-无间隔 1-5s 6-关闭
|
||||
attReload = 6;
|
||||
/** @deprecated */
|
||||
attRelocate = false;
|
||||
// 价格监视
|
||||
priceWatcher = { xan: -1, pt: -1 };
|
||||
// 开发者模式
|
||||
isDev = false;
|
||||
// 4条转跳
|
||||
barsRedirect = true;
|
||||
// 浮动存钱框
|
||||
floatDepo = true;
|
||||
// 公司转跳存钱
|
||||
companyRedirect = true;
|
||||
// 收起公司冰蛙效率表
|
||||
companyBWCollapse = true;
|
||||
// 海外警告
|
||||
abroadWarning = true;
|
||||
// 落地转跳
|
||||
landedRedirect = '';
|
||||
// 任何位置一键存钱
|
||||
companyDepositAnywhere = false;
|
||||
// 火车提醒时间
|
||||
CHTrainsDetect = 0;
|
||||
// 火车提醒开关
|
||||
CHTrainsDetectSwitch = true;
|
||||
// 隐藏个人资料头像
|
||||
HideProfileImg = false;
|
||||
// 显示曾用名
|
||||
ShowNameHistory = true;
|
||||
// 盯梢模式强度 0-550 1-950 2-1450 ms
|
||||
WatchTargetFreq = 1;
|
||||
// 隐藏侧边栏
|
||||
HideSidebar = false;
|
||||
// 添加隐藏边栏按钮
|
||||
HideSidebarBtn = true;
|
||||
// 搜索页占位区
|
||||
SearchPagePlaceholder = true;
|
||||
// 解决一直转圈(加载中)的问题
|
||||
SolveGoogleScriptPendingIssue = false;
|
||||
// 图标坐标
|
||||
IconPosition: Partial<{ x: number, y: number }> = {};
|
||||
// 记住图标位置
|
||||
SaveIconPosition = false;
|
||||
// 现金变动提醒
|
||||
CashChangeAlert = false;
|
||||
// 收集数据以改进翻译质量
|
||||
CollectPlayerData = true;
|
||||
// 迷你资料卡显示上次行动时间
|
||||
ShowMiniProfLastAct = true;
|
||||
// 自定义css
|
||||
CustomCss = '';
|
||||
}
|
||||
|
||||
|
||||
export type Config = DefaultConfigType;
|
||||
export default new DefaultConfigType() as Readonly<Config>;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Popup from "../utils/Popup";
|
||||
import Alert from "../utils/Alert";
|
||||
import DialogMsgBox from "../utils/DialogMsgBox";
|
||||
@ -6,9 +5,18 @@ import CommonUtils from "../utils/CommonUtils";
|
||||
import { MenuItemConfig } from "../ZhongIcon";
|
||||
import IFrameCrimeHandler from "./IFrameCrimeHandler";
|
||||
import loadGS from "../../func/module/loadGS";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
export default class AdditionalSettingsHandler extends WuhuBase {
|
||||
className = 'AdditionalSettingsHandler';
|
||||
@ClassName('AdditionalSettingsHandler')
|
||||
@Injectable()
|
||||
export default class AdditionalSettingsHandler {
|
||||
|
||||
constructor(
|
||||
private readonly commonUtils: CommonUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public show(): void {
|
||||
let pop = new Popup('', '更多设定');
|
||||
@ -59,7 +67,7 @@ export default class AdditionalSettingsHandler extends WuhuBase {
|
||||
},
|
||||
{
|
||||
domType: 'button', domId: '', domText: '小窗犯罪', clickFunc() {
|
||||
IFrameCrimeHandler.getInstance().handle()
|
||||
Container.factory(IFrameCrimeHandler).handle()
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -67,11 +75,11 @@ export default class AdditionalSettingsHandler extends WuhuBase {
|
||||
domId: '',
|
||||
domText: '飞贼小助手',
|
||||
tip: '加载从PC端移植的伞佬的油猴版飞贼小助手',
|
||||
clickFunc() {
|
||||
loadGS(CommonUtils.getScriptEngine())
|
||||
clickFunc: () => {
|
||||
loadGS(this.commonUtils.getScriptEngine())
|
||||
}
|
||||
},
|
||||
];
|
||||
menuList.forEach(i => pop.getElement().append(CommonUtils.getInstance().elemGenerator(i, pop.getElement())));
|
||||
menuList.forEach(i => pop.element.append(this.commonUtils.elemGenerator(i, pop.element)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,15 +4,24 @@ import MDUtils from "../utils/MDUtils";
|
||||
import Log from "../Log";
|
||||
import { MENU_ITEM_TYPE } from "../../interface/MenuItem";
|
||||
import Provider from "../provider/Provider";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
@ClassName('ChangeLogHandler')
|
||||
@Injectable()
|
||||
class ChangeLogHandler extends Provider {
|
||||
className = 'ChangeLogHandler';
|
||||
constructor(
|
||||
private readonly mdUtils: MDUtils,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public show(): void {
|
||||
let popup = new Popup(
|
||||
'更新历史:<br/><a target="_blank" href="https://gitlab.com/JJins/wuhu-torn-helper/-/blob/dev/CHANGELOG.md">https://gitlab.com/JJins/wuhu-torn-helper/-/blob/dev/CHANGELOG.md</a><br/>',
|
||||
'更新历史'
|
||||
).getElement();
|
||||
).element;
|
||||
popup.classList.add('wh-changeLog');
|
||||
let progressBar = document.createElement('div');
|
||||
progressBar.style.height = '2px';
|
||||
@ -31,7 +40,7 @@ class ChangeLogHandler extends Provider {
|
||||
.then(update => {
|
||||
progressBar.style.width = '60%';
|
||||
progressText.innerText = '解析中……';
|
||||
let md = MDUtils.getInstance().parse(update);
|
||||
let md = this.mdUtils.parse(update);
|
||||
popup.append(md);
|
||||
progressBar.style.width = '100%';
|
||||
progressText.innerText = '加载完成';
|
||||
@ -53,5 +62,5 @@ class ChangeLogHandler extends Provider {
|
||||
export default {
|
||||
domType: MENU_ITEM_TYPE.BUTTON,
|
||||
domText: '🐞 更新历史',
|
||||
clickFunc: () => ChangeLogHandler.getInstance().show()
|
||||
clickFunc: () => Container.factory(ChangeLogHandler).show()
|
||||
};
|
||||
|
||||
@ -1,19 +1,23 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Popup from "../utils/Popup";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
|
||||
export default class CustomCssHandler extends WuhuBase {
|
||||
className = 'CustomCssHandler';
|
||||
@ClassName('CustomCssHandler')
|
||||
@Injectable()
|
||||
export default class CustomCssHandler {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
) {
|
||||
}
|
||||
|
||||
public handle(): void {
|
||||
let pop = new Popup('<div><textarea></textarea><button class="torn-btn">保存</button><style>#wh-popup textarea{display: block;}</style></div>', '自定义CSS');
|
||||
let textarea = pop.getElement().querySelector('textarea');
|
||||
let button = pop.getElement().querySelector('button');
|
||||
textarea.value = WuhuConfig.get('CustomCss') || '';
|
||||
let textarea = pop.element.querySelector('textarea');
|
||||
let button = pop.element.querySelector('button');
|
||||
textarea.value = this.localConfigWrapper.config.CustomCss || '';
|
||||
button.addEventListener('click', () => {
|
||||
WuhuConfig.set('CustomCss', textarea.value || '', true);
|
||||
});
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import Popup from "../utils/Popup";
|
||||
import QUICK_CRIMES_HTML from "../../../static/html/quick_crimes.html";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
export default class IFrameCrimeHandler extends WuhuBase {
|
||||
className = 'IFrameCrimeHandler';
|
||||
@ClassName('IFrameCrimeHandler')
|
||||
@Injectable()
|
||||
export default class IFrameCrimeHandler {
|
||||
|
||||
public handle(): void {
|
||||
// 弹出小窗口
|
||||
|
||||
@ -1,26 +1,35 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import PRICE_WATCHER_HTML from "../../../static/html/price_watcher.html";
|
||||
import Popup from "../utils/Popup";
|
||||
import Global from "../Global";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
import TornPDAUtils from "../utils/TornPDAUtils";
|
||||
|
||||
export default class ItemPriceWatcherHandler extends WuhuBase {
|
||||
className = 'ItemPriceWatcherHandler';
|
||||
@Injectable()
|
||||
@ClassName('ItemPriceWatcherHandler')
|
||||
export default class ItemPriceWatcherHandler {
|
||||
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly tornPDAUtils: TornPDAUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public handle(): void {
|
||||
const watcher_conf = WuhuConfig.get('priceWatcher');
|
||||
const watcher_conf = this.localConfigWrapper.config.priceWatcher;
|
||||
const pre_str = JSON.stringify(watcher_conf);
|
||||
const html = PRICE_WATCHER_HTML
|
||||
.replace('{{}}', localStorage.getItem('APIKey') || '不可用')
|
||||
.replace('{{}}', Global.getInstance().isPDA ? Global.getInstance().PDA_APIKey : '不可用')
|
||||
.replace('{{}}', watcher_conf['pt'] || -1)
|
||||
.replace('{{}}', watcher_conf['xan'] || -1);
|
||||
.replace('{{}}', this.tornPDAUtils.isPDA() ? this.tornPDAUtils.APIKey : '不可用')
|
||||
.replace('{{}}', (watcher_conf['pt'] || -1).toString())
|
||||
.replace('{{}}', (watcher_conf['xan'] || -1).toString());
|
||||
const popup = new Popup(html, '价格监视设置');
|
||||
popup.getElement().querySelector('button').onclick = () => {
|
||||
const [pt_node, xan_node] = Array.from(<NodeListOf<HTMLInputElement>>popup.getElement().querySelectorAll('input[type="number"]'));
|
||||
watcher_conf.pt = (pt_node.value as any) | 0;
|
||||
watcher_conf.xan = (xan_node.value as any) | 0;
|
||||
if (JSON.stringify(watcher_conf) !== pre_str) WuhuConfig.set('priceWatcher', watcher_conf);
|
||||
if (JSON.stringify(watcher_conf) !== pre_str)
|
||||
this.localConfigWrapper.config.priceWatcher = watcher_conf;
|
||||
popup.close();
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Popup from "../utils/Popup";
|
||||
import Elem from "../provider/Elem";
|
||||
|
||||
/**
|
||||
* 快速查价
|
||||
*/
|
||||
export default class ItemValueQueryHandler extends WuhuBase {
|
||||
className = "ItemValueQueryHandler";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public show() {
|
||||
let pop = new Popup('', '快速查价');
|
||||
pop.getElement().append(
|
||||
new Elem('div').html('<p>test</p>').class('wh-test').el()
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,24 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import NNB_INFO_HTML from "../../../static/html/nnb_info.html";
|
||||
import Popup from "../utils/Popup";
|
||||
import Global from "../Global";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import TornPDAUtils from "../utils/TornPDAUtils";
|
||||
|
||||
export default class NNB extends WuhuBase {
|
||||
@ClassName('NNB')
|
||||
@Injectable()
|
||||
export default class NNB {
|
||||
className = 'NNB';
|
||||
|
||||
constructor(
|
||||
private readonly tornPDAUtils: TornPDAUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public handle(): void {
|
||||
let { isPDA, PDA_APIKey } = Global.getInstance();
|
||||
const insert = NNB_INFO_HTML
|
||||
.replace('{{}}', localStorage.getItem('APIKey') || '不可用')
|
||||
.replace('{{}}', isPDA ? PDA_APIKey : '不可用');
|
||||
const popup = new Popup(insert, '查看NNB').getElement();
|
||||
.replace('{{}}', this.tornPDAUtils.isPDA() ? this.tornPDAUtils.APIKey : '不可用');
|
||||
const popup = new Popup(insert, '查看NNB').element;
|
||||
const select = popup.querySelector('input');
|
||||
const node = popup.querySelector('p');
|
||||
popup.querySelector('button').addEventListener('click', ev => {
|
||||
@ -20,7 +27,7 @@ export default class NNB extends WuhuBase {
|
||||
node.innerHTML = '加载中';
|
||||
// API 计算
|
||||
if (select.checked) {
|
||||
const api_key = isPDA ? PDA_APIKey : window.localStorage.getItem('APIKey');
|
||||
const api_key = this.tornPDAUtils.isPDA() ? this.tornPDAUtils.APIKey : window.localStorage.getItem('APIKey');
|
||||
window.fetch(`https://api.torn.com/user/?selections=bars,perks&key=${ api_key }`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
|
||||
@ -1,16 +1,26 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import QUICK_FLY_CSS from "../../../static/css/quick_fly.css";
|
||||
import QUICK_FLY_HTML from "../../../static/html/quick_fly.html";
|
||||
import Alert from "../utils/Alert";
|
||||
import TravelItem from "../action/TravelItem";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import Logger from "../Logger";
|
||||
|
||||
export default class QuickFlyBtnHandler extends WuhuBase {
|
||||
@ClassName('QuickFlyBtnHandler')
|
||||
@Injectable()
|
||||
export default class QuickFlyBtnHandler {
|
||||
className = 'QuickFlyBtnHandler';
|
||||
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
private readonly travelItem: TravelItem,
|
||||
) {
|
||||
}
|
||||
|
||||
public static doQuickFly(): void {
|
||||
// [id: dest, _type: (1...4), ts: timestamp]
|
||||
const [_id, _type, ts] = sessionStorage['wh-quick-fly'].trim().split(' ');
|
||||
const [_id, _type, ts] = window.sessionStorage['wh-quick-fly'].trim().split(' ');
|
||||
if (new Date().getTime() - ts > 20000) {
|
||||
new Alert('超时,一键起飞计划已取消');
|
||||
return;
|
||||
@ -69,8 +79,7 @@ export default class QuickFlyBtnHandler extends WuhuBase {
|
||||
});
|
||||
node.querySelector('a').addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
// forStock();
|
||||
TravelItem.getInstance().clickHandler();
|
||||
this.travelItem.clickHandler().then();
|
||||
});
|
||||
node.querySelector('input').addEventListener('click', (e) => {
|
||||
node.classList.toggle('wh-quick-fly-opt-hide');
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import QUICK_LINK_CSS from "../../../static/css/quick_link.css";
|
||||
import Popup from "../utils/Popup";
|
||||
|
||||
export default class QuickLinksHandler extends WuhuBase {
|
||||
className = 'QuickLinksHandler';
|
||||
export default class QuickLinksHandler {
|
||||
|
||||
private styleAdded: boolean = false;
|
||||
private list = [];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
let list = this.list;
|
||||
// 生存手册
|
||||
list.push({
|
||||
@ -82,8 +79,8 @@ export default class QuickLinksHandler extends WuhuBase {
|
||||
});
|
||||
insert += '</p>'
|
||||
let popup = new Popup(insert, '常用链接');
|
||||
popup.getElement().classList.add('wh-link-collection-cont');
|
||||
popup.getElement().addEventListener('click', ev => {
|
||||
popup.element.classList.add('wh-link-collection-cont');
|
||||
popup.element.addEventListener('click', ev => {
|
||||
let target = ev.target as HTMLElement;
|
||||
if (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'span') {
|
||||
popup.close();
|
||||
|
||||
@ -12,13 +12,25 @@ import CommonUtils from "../utils/CommonUtils";
|
||||
import CustomCssHandler from "./CustomCssHandler";
|
||||
import Provider from "../provider/Provider";
|
||||
import { MENU_ITEM_TYPE } from "../../interface/MenuItem";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
@ClassName('SettingsHandler')
|
||||
@Injectable()
|
||||
class SettingsHandler extends Provider {
|
||||
className = 'SettingsHandler';
|
||||
|
||||
private list: MenuItemConfig[] = [];
|
||||
|
||||
constructor() {
|
||||
constructor(
|
||||
private readonly buyBeerHelper: BuyBeerHelper,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly updateTranslateDict: UpdateTranslateDict,
|
||||
private readonly customCssHandler: CustomCssHandler,
|
||||
private readonly viewLogsHandler: ViewLogsHandler,
|
||||
private readonly additionalSettingsHandler: AdditionalSettingsHandler,
|
||||
) {
|
||||
super();
|
||||
this.constructWuhuSettingList();
|
||||
}
|
||||
@ -30,10 +42,10 @@ class SettingsHandler extends Provider {
|
||||
window.setTimeout(() => {
|
||||
let tmp = document.createElement('div');
|
||||
tmp.classList.add('gSetting');
|
||||
this.list.forEach(set => CommonUtils.getInstance().elemGenerator(set, tmp));
|
||||
this.list.forEach(set => this.commonUtils.elemGenerator(set, tmp));
|
||||
// 本日不提醒
|
||||
tmp.querySelector('#wh-qua-alarm-check-btn')
|
||||
.addEventListener('click', () => BuyBeerHelper.getInstance().skip_today());
|
||||
.addEventListener('click', () => this.buyBeerHelper.skip_today());
|
||||
pop.getElement().innerHTML = '';
|
||||
pop.getElement().appendChild(tmp);
|
||||
(window.initializeTooltip) && (window.initializeTooltip('#wh-popup-cont', 'white-tooltip'));
|
||||
@ -47,7 +59,7 @@ class SettingsHandler extends Provider {
|
||||
Log.info('构造设置列表开始');
|
||||
const date = new Date();
|
||||
|
||||
let beer = BuyBeerHelper.getInstance();
|
||||
let beer = this.buyBeerHelper;
|
||||
|
||||
let list = this.list;
|
||||
|
||||
@ -103,7 +115,7 @@ class SettingsHandler extends Provider {
|
||||
domId: '',
|
||||
domText: '更新翻译词库',
|
||||
isTornBtn: true,
|
||||
clickFunc: () => UpdateTranslateDict.getInstance().handle()
|
||||
clickFunc: () => this.updateTranslateDict.handle()
|
||||
});
|
||||
// 收集数据以改进翻译质量
|
||||
list.push({
|
||||
@ -384,7 +396,7 @@ class SettingsHandler extends Provider {
|
||||
domText: '啤酒提醒时间设定',
|
||||
isTornBtn: true,
|
||||
// tip: '通知提前时间',
|
||||
clickFunc: () => BuyBeerHelper.getInstance().setTimeHandler()
|
||||
clickFunc: () => this.buyBeerHelper.setTimeHandler()
|
||||
});
|
||||
|
||||
// 个人资料
|
||||
@ -537,13 +549,13 @@ class SettingsHandler extends Provider {
|
||||
dictName: 'isDev',
|
||||
isHide: true,
|
||||
});
|
||||
// 查看logs
|
||||
// 自定义CSS
|
||||
list.push({
|
||||
domType: 'button',
|
||||
domId: null,
|
||||
domText: '自定义CSS',
|
||||
isTornBtn: true,
|
||||
clickFunc: () => CustomCssHandler.getInstance().handle()
|
||||
clickFunc: () => this.customCssHandler.handle()
|
||||
});
|
||||
// 查看logs
|
||||
list.push({
|
||||
@ -551,13 +563,13 @@ class SettingsHandler extends Provider {
|
||||
domId: null,
|
||||
domText: '查看日志',
|
||||
isTornBtn: true,
|
||||
clickFunc: () => ViewLogsHandler.getInstance().handle()
|
||||
clickFunc: () => this.viewLogsHandler.handle()
|
||||
});
|
||||
// 更多设定
|
||||
list.push({
|
||||
domType: 'button', domId: 'wh-otherBtn', domText: '更多设定',
|
||||
isTornBtn: true,
|
||||
clickFunc: () => AdditionalSettingsHandler.getInstance().show()
|
||||
clickFunc: () => this.additionalSettingsHandler.show()
|
||||
});
|
||||
|
||||
Log.info('构造设置列表结束' + timer.getTimeMs());
|
||||
@ -568,5 +580,5 @@ class SettingsHandler extends Provider {
|
||||
export default {
|
||||
domType: MENU_ITEM_TYPE.BUTTON,
|
||||
domText: '⚙️ 助手设置',
|
||||
clickFunc: () => SettingsHandler.getInstance().show()
|
||||
clickFunc: () => Container.factory(SettingsHandler).show()
|
||||
};
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Alert from "../utils/Alert";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
export default class UpdateTranslateDict extends WuhuBase {
|
||||
className = 'UpdateTranslateDict';
|
||||
@ClassName('UpdateTranslateDict')
|
||||
@Injectable()
|
||||
export default class UpdateTranslateDict {
|
||||
|
||||
public handle(): void {
|
||||
new Alert('计划中');
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Log from "../Log";
|
||||
import Popup from "../utils/Popup";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import VIEW_LOGS_HANDLER_HTML from "../../../static/html/view_logs_handler.html";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
export default class ViewLogsHandler extends WuhuBase {
|
||||
className = 'ViewLogsHandler';
|
||||
@ClassName('ViewLogsHandler')
|
||||
@Injectable()
|
||||
export default class ViewLogsHandler {
|
||||
|
||||
constructor(
|
||||
private readonly commonUtils: CommonUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
public handle(): void {
|
||||
let logCounter = Log.getCounter();
|
||||
@ -14,7 +21,7 @@ export default class ViewLogsHandler extends WuhuBase {
|
||||
.replace('{{}}', logCounter.warning.toString())
|
||||
.replace('{{}}', logCounter.error.toString()), '查看日志');
|
||||
window.setTimeout(() => {
|
||||
let container = pop.getElement().querySelector('div');
|
||||
let container = pop.element.querySelector('div');
|
||||
let text = document.createElement('div');
|
||||
let logs = Log.getLogs().split('\r\n');
|
||||
logs.forEach(log => {
|
||||
@ -27,9 +34,8 @@ export default class ViewLogsHandler extends WuhuBase {
|
||||
}
|
||||
text.append(p);
|
||||
});
|
||||
pop.getElement().querySelector('button').addEventListener('click', () => window.setTimeout(() => {
|
||||
CommonUtils.getInstance()
|
||||
.exportTextFile(
|
||||
pop.element.querySelector('button').addEventListener('click', () => window.setTimeout(() => {
|
||||
this.commonUtils.exportTextFile(
|
||||
'wuhu_log_' + Log.getTime()
|
||||
.replace('[', '')
|
||||
.replace(']', '')
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import Log from "../Log";
|
||||
import { GetClassName } from "../../container/ClassName";
|
||||
import Logger from "../Logger";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
/**
|
||||
* 方法装饰器
|
||||
@ -7,21 +9,37 @@ import Log from "../Log";
|
||||
* @param descriptor
|
||||
*/
|
||||
export default function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
const logger: Logger = Container.factory(Logger);
|
||||
|
||||
const original = descriptor.value;
|
||||
|
||||
descriptor.value = function (...args) {
|
||||
Log.info('[debug] 参数 ', JSON.stringify({
|
||||
class: target.className || target.name,
|
||||
method: propertyKey,
|
||||
args
|
||||
}));
|
||||
// Log.info('[debug] 参数 ', JSON.stringify({
|
||||
// class: target.className || target.name,
|
||||
// method: propertyKey,
|
||||
// args
|
||||
// }));
|
||||
|
||||
let result;
|
||||
try {
|
||||
result = original.call(this, ...args) || null;
|
||||
} catch (err) {
|
||||
Log.error('[debug] 异常 ', err.stack || err.message || err);
|
||||
logger.error('[debug]', err.stack || err.message || err, '参数' + JSON.stringify({
|
||||
class: GetClassName(target) ?? target.name,
|
||||
method: propertyKey,
|
||||
args
|
||||
}));
|
||||
}
|
||||
result && Log.info('[debug] 结果 ', { result });
|
||||
logger.info(
|
||||
'[debug]',
|
||||
'参数' + JSON.stringify({
|
||||
class: GetClassName(target) ?? target.name,
|
||||
method: propertyKey,
|
||||
args
|
||||
}),
|
||||
'结果',
|
||||
{ result }
|
||||
);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,21 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Log from "../Log";
|
||||
import ZhongIcon from "../ZhongIcon";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import Logger from "../Logger";
|
||||
|
||||
export default class ActionButtonUtils extends WuhuBase {
|
||||
className = 'ActionButtonUtils';
|
||||
@ClassName('ActionButtonUtils')
|
||||
@Injectable()
|
||||
export default class ActionButtonUtils {
|
||||
private hasAdded: boolean = false;
|
||||
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
}
|
||||
|
||||
public add(txt: string, func: (ev: Event) => void = () => null): void {
|
||||
if (!this.hasAdded) this.handle(txt, func);
|
||||
else Log.warn('ActionButton已存在');
|
||||
else this.logger.warn('ActionButton已存在');
|
||||
}
|
||||
|
||||
private handle(txt, func): void {
|
||||
@ -20,6 +27,6 @@ export default class ActionButtonUtils extends WuhuBase {
|
||||
btn.addEventListener('click', func);
|
||||
ZhongIcon.ZhongNode.querySelector('button').after(btn);
|
||||
this.hasAdded = true;
|
||||
Log.info('ActionButton已添加', { txt, func, btn });
|
||||
this.logger.info('ActionButton已添加', { txt, func, btn });
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,14 @@
|
||||
import Log from "../Log";
|
||||
import IWHNotify from "../../interface/IWHNotify";
|
||||
import NotificationUtils from "./NotificationUtils";
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import MathUtils from "./MathUtils";
|
||||
import NOTIFY_HTML from "../../../static/html/notify.html";
|
||||
import WindowActiveState from "../action/WindowActiveState";
|
||||
import { Container } from "../../container/Container";
|
||||
import Logger from "../Logger";
|
||||
import ClassName from "../../container/ClassName";
|
||||
|
||||
export default class Alert extends WuhuBase {
|
||||
className = 'Alert';
|
||||
@ClassName('Alert')
|
||||
export default class Alert {
|
||||
private static container: HTMLElement = null;
|
||||
private static totalCounter: number = 0;
|
||||
|
||||
@ -15,35 +16,41 @@ export default class Alert extends WuhuBase {
|
||||
private intervalID = -1;
|
||||
private readonly callback: Function;
|
||||
|
||||
public constructor(msg: string, options: IWHNotify = {}) {
|
||||
super();
|
||||
public constructor(
|
||||
msg: string,
|
||||
options: IWHNotify = {},
|
||||
private readonly mathUtils: MathUtils = Container.factory(MathUtils),
|
||||
private readonly windowActiveState: WindowActiveState = Container.factory(WindowActiveState),
|
||||
private readonly notificationUtils: NotificationUtils = Container.factory(NotificationUtils),
|
||||
private readonly logger: Logger = Container.factory(Logger),
|
||||
) {
|
||||
|
||||
let { timeout, callback, sysNotify, force } = options;
|
||||
|
||||
// 后台窗口、iframe内判断
|
||||
if (!WindowActiveState.getInstance().get() || (self !== top)) {
|
||||
if (!this.windowActiveState.get() || (self !== top)) {
|
||||
if (!force) {
|
||||
Log.warn('后台通知已被屏蔽');
|
||||
this.logger.warn('后台通知已被屏蔽');
|
||||
return null;
|
||||
} else {
|
||||
Log.info('强制后台通知');
|
||||
this.logger.info('强制后台通知');
|
||||
}
|
||||
}
|
||||
|
||||
// 通知的容器
|
||||
Log.info('通知的容器', Alert.container);
|
||||
this.logger.info('通知的容器', Alert.container);
|
||||
if (!Alert.container || !document.contains(Alert.container)) Alert.initContainer();
|
||||
|
||||
this.callback = callback || (() => null);
|
||||
Alert.create(this, msg, timeout || 3);
|
||||
Alert.totalCounter++;
|
||||
Log.info('创建新通知:', this, msg);
|
||||
if (sysNotify) NotificationUtils.getInstance().push(msg, options);
|
||||
this.logger.info('创建新通知:', this, msg);
|
||||
if (sysNotify) this.notificationUtils.push(msg, options);
|
||||
}
|
||||
|
||||
private static create(that: Alert, msg, timeout): void {
|
||||
// 通知的唯一id
|
||||
const uid = '' + MathUtils.getInstance().getRandomInt(1000, 9999);
|
||||
const uid = '' + that.mathUtils.getRandomInt(1000, 9999);
|
||||
// 每条通知
|
||||
const element: MyHTMLElement = document.createElement('div');
|
||||
element.id = `wh-notify-${ uid }`;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import UserScriptEngine from "../../enum/UserScriptEngine";
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Log from "../Log";
|
||||
import Device from "../../enum/Device";
|
||||
import LOADING_IMG_HTML from "../../../static/html/loading_img.html";
|
||||
@ -12,19 +11,36 @@ import TRAVEL_STATE from "../../enum/TravelState";
|
||||
import InventoryItemInfo from "../../interface/responseType/InventoryItemInfo";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import LocalConfigWrapper from "../LocalConfigWrapper";
|
||||
import Logger from "../Logger";
|
||||
import Global from "../Global";
|
||||
import { Container } from "../../container/Container";
|
||||
import TornPDAUtils from "./TornPDAUtils";
|
||||
|
||||
@Injectable()
|
||||
@ClassName('CommonUtils')
|
||||
export default class CommonUtils extends WuhuBase {
|
||||
className = 'CommonUtils';
|
||||
export default class CommonUtils {
|
||||
|
||||
constructor(
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
private readonly logger: Logger,
|
||||
private readonly global: Global,
|
||||
private readonly tornPDAUtils: TornPDAUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
static getScriptEngine() {
|
||||
let glob = CommonUtils.glob;
|
||||
return glob.GM_xmlhttpRequest ? UserScriptEngine.GM : glob.isPDA
|
||||
let glob = Container.factory(Global);
|
||||
let tornPDAUtils = Container.factory(TornPDAUtils);
|
||||
return glob.GM_xmlhttpRequest ? UserScriptEngine.GM : tornPDAUtils.isPDA()
|
||||
? UserScriptEngine.PDA : UserScriptEngine.RAW;
|
||||
}
|
||||
|
||||
static COFetch(url: URL | string, method: 'get' | 'post' = 'get', body: any = null): Promise<string> {
|
||||
static COFetch(url: URL | string, method: 'get' | 'post' | string = 'get', body: any = null): Promise<string> {
|
||||
let start = new Timer();
|
||||
const engine = this.getScriptEngine();
|
||||
Log.info('跨域获取数据开始, 脚本引擎: ' + engine);
|
||||
@ -69,7 +85,7 @@ export default class CommonUtils extends WuhuBase {
|
||||
break;
|
||||
}
|
||||
case UserScriptEngine.GM: {
|
||||
let { GM_xmlhttpRequest } = CommonUtils.glob;
|
||||
let { GM_xmlhttpRequest } = Container.factory(Global);
|
||||
if (typeof GM_xmlhttpRequest !== 'function') {
|
||||
Log.error('COFetch网络错误:用户脚本扩展API错误');
|
||||
reject('错误:用户脚本扩展API错误');
|
||||
@ -91,6 +107,13 @@ export default class CommonUtils extends WuhuBase {
|
||||
});
|
||||
}
|
||||
|
||||
getScriptEngine() {
|
||||
// let glob = Container.factory(Global);
|
||||
// let tornPDAUtils = Container.factory(TornPDAUtils);
|
||||
return this.global.GM_xmlhttpRequest ? UserScriptEngine.GM : this.tornPDAUtils.isPDA()
|
||||
? UserScriptEngine.PDA : UserScriptEngine.RAW;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 返回玩家信息的对象 { playername: string, userID: number }
|
||||
// * @return {PlayerInfo} rs
|
||||
@ -210,12 +233,19 @@ export default class CommonUtils extends WuhuBase {
|
||||
* @param {string} url 播放的音频URL
|
||||
* @returns {undefined}
|
||||
*/
|
||||
public audioPlay(url: string = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3') {
|
||||
public audioPlay(url: string = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3'): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const audio = new Audio(url);
|
||||
audio.addEventListener("canplaythrough", () => {
|
||||
audio.play()
|
||||
.catch(err => Log.error('播放音频出错', err.message, err.stack))
|
||||
.then();
|
||||
.catch(err => {
|
||||
this.logger.error('播放音频出错', err.message, err.stack);
|
||||
reject();
|
||||
})
|
||||
.then(
|
||||
() => resolve()
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -233,11 +263,11 @@ export default class CommonUtils extends WuhuBase {
|
||||
}
|
||||
|
||||
public jQueryReady(): Promise<null> {
|
||||
Log.info('等待jQuery加载中...');
|
||||
FetchUtils.getInstance().fetchText('/js/script/lib/jquery-1.8.2.js?v=f9128651g')
|
||||
this.logger.info('等待jQuery加载中...');
|
||||
this.fetchUtils.fetchText('/js/script/lib/jquery-1.8.2.js?v=f9128651g')
|
||||
.then(res => window.eval(res));
|
||||
let intervalId = window.setInterval(() => {
|
||||
Log.info('仍在等待jQuery加载中...');
|
||||
this.logger.info('仍在等待jQuery加载中...');
|
||||
}, 1000);
|
||||
return new Promise(async resolve => {
|
||||
while (true) {
|
||||
@ -245,7 +275,7 @@ export default class CommonUtils extends WuhuBase {
|
||||
await this.sleep(100);
|
||||
}
|
||||
window.clearInterval(intervalId);
|
||||
Log.info('jQuery已加载');
|
||||
this.logger.info('jQuery已加载');
|
||||
resolve(null);
|
||||
});
|
||||
}
|
||||
@ -272,7 +302,7 @@ export default class CommonUtils extends WuhuBase {
|
||||
let _input = switcher.getInput();
|
||||
switcher.getBase().id = domId;
|
||||
(tip) && (switcher.getBase().setAttribute('title', tip));
|
||||
_input.checked = WuhuConfig.get(dictName);
|
||||
_input.checked = this.localConfigWrapper.config[dictName];
|
||||
_input.onchange = e => {
|
||||
WuhuConfig.set(dictName, _input.checked, true);
|
||||
if (changeEv) changeEv(e);
|
||||
@ -305,7 +335,7 @@ export default class CommonUtils extends WuhuBase {
|
||||
let option = document.createElement('option');
|
||||
option.value = domVal;
|
||||
option.innerHTML = domText;
|
||||
option.selected = i === WuhuConfig.get(dictName);
|
||||
option.selected = i === this.localConfigWrapper.config[dictName];
|
||||
option.innerHTML = domText;
|
||||
select.appendChild(option);
|
||||
});
|
||||
@ -345,7 +375,7 @@ export default class CommonUtils extends WuhuBase {
|
||||
}
|
||||
|
||||
public getTravelStage(): TRAVEL_STATE {
|
||||
let global = CommonUtils.glob;
|
||||
let global = Container.factory(Global);
|
||||
if (global.bodyAttrs["data-abroad"] === 'false') {
|
||||
return TRAVEL_STATE.IN_TORN;
|
||||
}
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Log from "../Log";
|
||||
import AjaxFetchOption from "../../interface/AjaxFetchOption";
|
||||
import IUserProfileData from "../../interface/IUserProfileData";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import Logger from "../Logger";
|
||||
|
||||
export default class FetchUtils extends WuhuBase {
|
||||
className = 'FetchUtils';
|
||||
@ClassName('FetchUtils')
|
||||
@Injectable()
|
||||
export default class FetchUtils {
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 包装jquery ajax 异步返回string
|
||||
@ -55,7 +61,7 @@ export default class FetchUtils extends WuhuBase {
|
||||
.then(res => res.text())
|
||||
.then(t => resolve(t))
|
||||
.catch(err => {
|
||||
Log.error('fetchText出错了', err);
|
||||
this.logger.error('fetchText出错了', err);
|
||||
reject(err);
|
||||
})
|
||||
);
|
||||
@ -70,11 +76,11 @@ export default class FetchUtils extends WuhuBase {
|
||||
o.json().then((res) => {
|
||||
resolve(res);
|
||||
}).catch(e => {
|
||||
Log.error('[ProfileHelper] JSON解析错误: ', e.message, '错误堆栈: ', e.stack);
|
||||
this.logger.error('[ProfileHelper] JSON解析错误: ', e.message, '错误堆栈: ', e.stack);
|
||||
reject(e);
|
||||
});
|
||||
}).catch(e => {
|
||||
Log.error('[ProfileHelper] 网络错误: ', e.message, '错误堆栈: ', e.stack);
|
||||
this.logger.error('[ProfileHelper] 网络错误: ', e.message, '错误堆栈: ', e.stack);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,12 +1,22 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Alert from "./Alert";
|
||||
import ISidebarData from "../../interface/ISidebarData";
|
||||
import Log from "../Log";
|
||||
import CommonUtils from "./CommonUtils";
|
||||
import FetchUtils from "./FetchUtils";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import Logger from "../Logger";
|
||||
|
||||
export default class InfoUtils extends WuhuBase {
|
||||
className = 'InfoUtils';
|
||||
@ClassName('InfoUtils')
|
||||
@Injectable()
|
||||
export default class InfoUtils {
|
||||
|
||||
constructor(
|
||||
// TODO 循环依赖
|
||||
// private readonly commonUtils: CommonUtils,
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回玩家信息的对象 { playername: string, userID: number }
|
||||
@ -20,7 +30,7 @@ export default class InfoUtils extends WuhuBase {
|
||||
userID: parseInt(node.getAttribute('uid')),
|
||||
}
|
||||
} else {
|
||||
new Alert('严重错误:芜湖助手无法获取用户数据,已退出');
|
||||
(() => new Alert('严重错误:芜湖助手无法获取用户数据,已退出'))();
|
||||
throw '芜湖助手无法获取用户数据';
|
||||
}
|
||||
}
|
||||
@ -35,19 +45,30 @@ export default class InfoUtils extends WuhuBase {
|
||||
let c = 0;
|
||||
while (!sessionStorage.getItem(field) && c < 50) {
|
||||
c++;
|
||||
await CommonUtils.getInstance().sleep(10);
|
||||
// await (async () => await this.commonUtils.sleep(10))();
|
||||
await (async () => window.setTimeout(() => Promise.resolve(), 10))();
|
||||
}
|
||||
if (sessionStorage.getItem(field)) {
|
||||
try {
|
||||
ret = JSON.parse(sessionStorage.getItem(field));
|
||||
} catch (e) {
|
||||
this.logger.error('解析出错', e.stack || e.message || e);
|
||||
ret = {};
|
||||
}
|
||||
} else {
|
||||
Log.info('无法从sessionStorage获取数据')
|
||||
ret = await (await FetchUtils.getInstance().ajaxFetch({
|
||||
ret = await (await this.fetchUtils.ajaxFetch({
|
||||
url: window.addRFC('/sidebarAjaxAction.php?q=getSidebarData'),
|
||||
method: 'POST',
|
||||
})).json();
|
||||
sessionStorage.setItem(field, JSON.stringify(ret));
|
||||
}
|
||||
try {
|
||||
ret.headerData = JSON.parse(sessionStorage.getItem('headerData'));
|
||||
} catch (e) {
|
||||
this.logger.error('解析出错', e.stack || e.message || e);
|
||||
ret.headerData = null;
|
||||
}
|
||||
resolve(ret);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,13 +1,20 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import InventoryItemInfo from "../../interface/responseType/InventoryItemInfo";
|
||||
import FetchUtils from "./FetchUtils";
|
||||
import CommonUtils from "./CommonUtils";
|
||||
import Log from "../Log";
|
||||
import PriceData from "../../interface/PriceData";
|
||||
import Asyncable from "../../interface/Asyncable";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
export default class ItemHelper extends WuhuBase {
|
||||
className = "ItemHelper";
|
||||
@ClassName('ItemHelper')
|
||||
@Injectable()
|
||||
export default class ItemHelper {
|
||||
|
||||
constructor(
|
||||
private readonly fetchUtils: FetchUtils,
|
||||
) {
|
||||
}
|
||||
|
||||
/** 保存物品名-ID对应关系 */
|
||||
private itemNameMap: { [name: string]: number } = null;
|
||||
@ -32,11 +39,6 @@ export default class ItemHelper extends WuhuBase {
|
||||
// 缓存过期时间 分钟
|
||||
private readonly priceTimeout = 720;
|
||||
|
||||
// TODO 定时
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/** TODO 通过 name 查询 */
|
||||
public async getItemData(idOrName: string): Promise<Partial<InventoryItemInfo>> {
|
||||
let _itemId: number = null;
|
||||
@ -50,7 +52,7 @@ export default class ItemHelper extends WuhuBase {
|
||||
} else {
|
||||
itemId = (await this.getItemNameMap().promise)[idOrName];
|
||||
}
|
||||
return await (await FetchUtils.getInstance().ajaxFetch({
|
||||
return await (await this.fetchUtils.ajaxFetch({
|
||||
url: '/inventory.php',
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
export default class MDUtils extends WuhuBase {
|
||||
className = 'MDUtils';
|
||||
@ClassName('MDUtils')
|
||||
@Injectable()
|
||||
export default class MDUtils {
|
||||
/**
|
||||
* 解析 Markdown 内容
|
||||
* @param {String} from
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
export default class MathUtils extends WuhuBase {
|
||||
@ClassName('MathUtils')
|
||||
@Injectable()
|
||||
export default class MathUtils {
|
||||
className = 'MathUtils';
|
||||
|
||||
// 得到一个两数之间的随机整数
|
||||
public getRandomInt(min: number, max: number): number {
|
||||
min = Math.ceil(min);
|
||||
|
||||
@ -1,13 +1,21 @@
|
||||
import IWHNotify from "../../interface/IWHNotify";
|
||||
import Log from "../Log";
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
@ClassName('NotificationUtils')
|
||||
@Injectable()
|
||||
export default class NotificationUtils {
|
||||
constructor(
|
||||
// TODO 循环依赖
|
||||
// private readonly global: Global,
|
||||
) {
|
||||
}
|
||||
|
||||
export default class NotificationUtils extends WuhuBase {
|
||||
className = 'NotificationUtils';
|
||||
private permission: boolean = window.Notification && window.Notification.permission === 'granted';
|
||||
|
||||
public push(msg: string, options: IWHNotify = {}): void {
|
||||
let { notifies } = NotificationUtils.glob;
|
||||
// let { notifies } = this.global;
|
||||
|
||||
if (options.sysNotify && this.permission) {
|
||||
let tmpNode = document.createElement('p');
|
||||
@ -18,14 +26,14 @@ export default class NotificationUtils extends WuhuBase {
|
||||
// renotify: true,
|
||||
// tag: '芜湖助手' + Utils.getRandomInt(0, 99),
|
||||
});
|
||||
let id = notifies.count++;
|
||||
notifies[id] = notify;
|
||||
notify.addEventListener(
|
||||
'close',
|
||||
() => {
|
||||
notifies[id] = null;
|
||||
}
|
||||
);
|
||||
// let id = notifies.count++;
|
||||
// notifies[id] = notify;
|
||||
// notify.addEventListener(
|
||||
// 'close',
|
||||
// () => {
|
||||
// notifies[id] = null;
|
||||
// }
|
||||
// );
|
||||
notify.addEventListener(
|
||||
'click',
|
||||
() => {
|
||||
@ -33,13 +41,13 @@ export default class NotificationUtils extends WuhuBase {
|
||||
window.focus();
|
||||
}
|
||||
);
|
||||
notify.addEventListener(
|
||||
'show',
|
||||
() => {
|
||||
// setTimeout(() => notify.close(), (options.timeout || 3) * 1000);
|
||||
Log.info('通知id: ', id)
|
||||
}
|
||||
);
|
||||
// notify.addEventListener(
|
||||
// 'show',
|
||||
// () => {
|
||||
// // setTimeout(() => notify.close(), (options.timeout || 3) * 1000);
|
||||
// Log.info('通知id: ', id)
|
||||
// }
|
||||
// );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,13 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import POPUP_HTML from "../../../static/html/popup.html";
|
||||
import Log from "../Log";
|
||||
import { Container } from "../../container/Container";
|
||||
import Global from "../Global";
|
||||
import Logger from "../Logger";
|
||||
import globVars from "../../globVars";
|
||||
|
||||
/**
|
||||
* 弹窗
|
||||
*/
|
||||
export default class Popup extends WuhuBase {
|
||||
className = 'Popup';
|
||||
export default class Popup {
|
||||
private readonly container: HTMLElement = null;
|
||||
private readonly node: HTMLElement = null;
|
||||
private onClosing: () => unknown;
|
||||
@ -16,16 +17,23 @@ export default class Popup extends WuhuBase {
|
||||
* @param innerHTML
|
||||
* @param title
|
||||
* @param onClosing
|
||||
* @param global
|
||||
* @param logger
|
||||
*/
|
||||
constructor(innerHTML: string, title: string = '芜湖助手', onClosing: () => unknown = () => {
|
||||
}) {
|
||||
super();
|
||||
constructor(
|
||||
innerHTML: string,
|
||||
title: string = '芜湖助手',
|
||||
onClosing: () => unknown = () => {
|
||||
},
|
||||
private readonly global: Global = Container.factory(Global),
|
||||
private readonly logger: Logger = Container.factory(Logger),
|
||||
) {
|
||||
this.onClosing = onClosing;
|
||||
if (Popup.glob.popup_node) {
|
||||
Log.info('关闭前一个弹窗');
|
||||
Popup.glob.popup_node.close();
|
||||
if (globVars.popup_node) {
|
||||
this.logger.info('关闭前一个弹窗');
|
||||
globVars.popup_node.close();
|
||||
}
|
||||
Log.info('新建弹窗', { innerHTML, title });
|
||||
this.logger.info('新建弹窗', { innerHTML, title });
|
||||
const popup = document.createElement('div');
|
||||
popup.id = 'wh-popup';
|
||||
popup.innerHTML = POPUP_HTML.replace('{{}}', title).replace('{{}}', innerHTML);
|
||||
@ -37,7 +45,7 @@ export default class Popup extends WuhuBase {
|
||||
this.container = popup;
|
||||
this.node = popup.querySelector('#wh-popup-cont');
|
||||
this.hideChat();
|
||||
Popup.glob.popup_node = this;
|
||||
globVars.popup_node = this;
|
||||
}
|
||||
|
||||
public close() {
|
||||
@ -53,6 +61,7 @@ export default class Popup extends WuhuBase {
|
||||
/**
|
||||
* @return {HTMLElement} id=wh-popup-cont
|
||||
* @deprecated
|
||||
* 使用element替代
|
||||
*/
|
||||
public getElement(): HTMLElement {
|
||||
return this.node;
|
||||
|
||||
16
src/ts/class/utils/TornPDAUtils.ts
Normal file
16
src/ts/class/utils/TornPDAUtils.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
|
||||
@ClassName('TornPDAUtils')
|
||||
@Injectable()
|
||||
export default class TornPDAUtils {
|
||||
private readonly _APIKey: string = '###PDA-APIKEY###';
|
||||
|
||||
public get APIKey(): string {
|
||||
return this._APIKey;
|
||||
}
|
||||
|
||||
public isPDA(): boolean {
|
||||
return !this._APIKey.startsWith('#');
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,16 @@
|
||||
import Log from "../Log";
|
||||
import MathUtils from "./MathUtils";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
export default class TornStyleBlock {
|
||||
private readonly baseElement: HTMLElement;
|
||||
private readonly headElement: HTMLElement;
|
||||
private readonly elem: HTMLElement;
|
||||
|
||||
public constructor(title: string) {
|
||||
public constructor(
|
||||
private readonly title: string,
|
||||
private readonly mathUtils: MathUtils = Container.factory(MathUtils),
|
||||
) {
|
||||
this.baseElement = document.createElement('div');
|
||||
this.headElement = document.createElement('div');
|
||||
this.elem = document.createElement('div');
|
||||
@ -19,7 +23,7 @@ export default class TornStyleBlock {
|
||||
// hr.classList.add('delimiter-999', 'm-top10', 'm-bottom10');
|
||||
|
||||
this.baseElement.append(this.headElement, this.elem);
|
||||
this.baseElement.id = 'WHTornStyleBlock' + MathUtils.getInstance().getRandomInt(0, 100);
|
||||
this.baseElement.id = 'WHTornStyleBlock' + mathUtils.getRandomInt(0, 100);
|
||||
this.baseElement.insertAdjacentHTML('beforeend', '<hr class="delimiter-999 m-top10 m-bottom10" />');
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,17 @@
|
||||
import MathUtils from "./MathUtils";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
export default class TornStyleSwitch {
|
||||
private readonly baseElement;
|
||||
private readonly randomId;
|
||||
private readonly input;
|
||||
|
||||
constructor(label: string, checked: boolean = false) {
|
||||
this.randomId = MathUtils.getInstance().getRandomInt(100, 2000);
|
||||
constructor(
|
||||
private readonly label: string,
|
||||
private readonly checked: boolean = false,
|
||||
private readonly mathUtils: MathUtils = Container.factory(MathUtils),
|
||||
) {
|
||||
this.randomId = mathUtils.getRandomInt(100, 2000);
|
||||
this.baseElement = document.createElement('span');
|
||||
this.baseElement.id = 'WHSwitch' + this.randomId;
|
||||
this.baseElement.innerHTML = `<input class="checkbox-css" type="checkbox" id="WHCheck${ this.randomId }" ${ checked ? 'checked' : '' }/>
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
|
||||
/**
|
||||
* 收集数据上传
|
||||
*/
|
||||
export default class Uploader extends WuhuBase {
|
||||
className = "Uploader";
|
||||
export default class Uploader {
|
||||
|
||||
/**
|
||||
* 上传数据
|
||||
@ -12,7 +9,8 @@ export default class Uploader extends WuhuBase {
|
||||
* @param uname 玩家昵称 可选
|
||||
* @param meta_data 上传数据json格式
|
||||
*/
|
||||
upload(uid:string, uname:string, meta_data:string) {}
|
||||
upload(uid: string, uname: string, meta_data: string) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务端的数据
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
/**
|
||||
* 记录类名、避免打包后丢失原类名
|
||||
*/
|
||||
|
||||
const CLASSNAME_METADATA_KEY = Symbol("CLASSNAME_KEY");
|
||||
|
||||
/**
|
||||
* 记录类名,避免打包后丢失原类名
|
||||
*/
|
||||
export default function ClassName(className?: string): ClassDecorator {
|
||||
return function <TFunction extends Function>(target: TFunction): TFunction {
|
||||
Reflect.defineMetadata(CLASSNAME_METADATA_KEY, className || target.name, target);
|
||||
|
||||
@ -2,27 +2,27 @@ import { assertInjectable } from "./Injectable";
|
||||
import { GetClassName } from "./ClassName";
|
||||
|
||||
/**
|
||||
* 一个简单的类注入容器
|
||||
* 一个简单的类容器
|
||||
*/
|
||||
export class Container {
|
||||
static _container = new Map();
|
||||
private static logger;
|
||||
|
||||
static set(k: any, v: any): void {
|
||||
if (Container._container.has(k)) {
|
||||
Container._container.set(k, v);
|
||||
if (!this._container.has(k)) {
|
||||
this._container.set(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
static get(k: any): any {
|
||||
return Container._container.get(k);
|
||||
return this._container.get(k);
|
||||
}
|
||||
|
||||
static factory<T>(target: Constructor<T>): T {
|
||||
assertInjectable(target);
|
||||
if (Container.get(target))
|
||||
return Container.get(target);
|
||||
return Container.initParam(target);
|
||||
// if (Container.get(target))
|
||||
// return Container.get(target);
|
||||
return this.get(target) || this.initParam(target);
|
||||
}
|
||||
|
||||
static setLogger(logger: { info(...o: any[]), error(...o: any[]), warn(...o: any[]) }): void {
|
||||
@ -32,22 +32,17 @@ export class Container {
|
||||
private static initParam<T>(target: Constructor<T>): T {
|
||||
// 获取所有注入的服务
|
||||
const providers = Reflect.getMetadata('design:paramtypes', target);
|
||||
// this.logger.info({providers})
|
||||
// this.logger.info('原型名'+Object.getPrototypeOf(target).constructor.name)
|
||||
// this.logger.info('直接名'+target.name)
|
||||
const args = providers ? providers.map((provider: Constructor) => {
|
||||
assertInjectable(provider);
|
||||
let inject;
|
||||
if (Container.get(provider)) {
|
||||
inject = Container.get(provider)
|
||||
} else {
|
||||
inject = Container.initParam(provider);
|
||||
Container.set(provider, inject)
|
||||
}
|
||||
return inject;
|
||||
return this.factory(provider);
|
||||
}) : [];
|
||||
let _target = new target(...args);
|
||||
this.logger?.info(
|
||||
`[${ GetClassName(target) || target.name }] 实例化`
|
||||
);
|
||||
Container.set(target, _target);
|
||||
this.set(target, _target);
|
||||
return _target;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ export function Injectable(injectMode: INJECT_MODE = INJECT_MODE.Singleton): Cla
|
||||
export function assertInjectable(target: any) {
|
||||
if (!Reflect.getMetadata(INJECTABLE_METADATA_KEY, target)) {
|
||||
throw new TypeError(
|
||||
`[${ GetClassName(target) || target.constructor?.name || target.name }] not injectable`
|
||||
`[${ GetClassName(target) || target.name }] not injectable`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1002,7 +1002,7 @@ export const awDict = {
|
||||
'This upgrade will give you a 5% boost in money that you mug from opponents. Perfect for experienced muggers, looking for some extra cash.':
|
||||
'这个升级将使你从对手那里抢来的钱增加5%。非常适合有经验的抢劫者,赚些额外的钱钱。',
|
||||
"This upgrade will make you more likely to stay stealthed when beating an opponent by increasing your stealth level by 0.2 per increment. When you're stealthed, your name will be listed as 'Someone' so your enemy will not know who hit them.":
|
||||
'这个升级将提升 0.2 隐身级别,使你在击败对手时更有可能保持隐身状态。当你处于隐身状态时,你的名字将被列为“某人”,所以你的敌人不会知道是谁攻击了他们。',
|
||||
'这个升级将提升 0.2 隐身级别,使你在击败对手时更有可能保持隐身状态。当你处于隐身状态时,你的名字将被列为「某人」,所以你的敌人不会知道是谁攻击了他们。',
|
||||
"This upgrade will increase the amount of time you hospitalize someone by 5%. Make sure they feel the burn with 50% extra hospital time when fully upgraded.":
|
||||
'这项升级将使你增加 5% 被强制住院玩家的住院时间。完全升级后,确保他们感受到50%的额外住院时间。',
|
||||
"This upgrade will reduce the negative effects addiction causes towards your battle stats, employee effectiveness, and education / gym access.":
|
||||
@ -1185,7 +1185,7 @@ export const profileDict = {
|
||||
}
|
||||
export const sendCashDict = {
|
||||
'Some players may be out to part you from your money, using any means necessary. Use the secure trade feature if you want to protect an exchange and check the contents very carefully.':
|
||||
'有些玩家可能会利用任何必要的手段来骗走你的钱。如果你想保护交易,请使用更安全的“交易”功能,并仔细检查交易的内容。',
|
||||
'有些玩家可能会利用任何必要的手段来骗走你的钱。如果你想保护交易,请使用更安全的「交易」功能,并仔细检查交易的内容。',
|
||||
'Do not fall for scams!': '切勿上当受骗!',
|
||||
'For more info please visit here.': '欲了解更多信息,请点击访问。',
|
||||
'SEND': '发送',
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import WuhuConfig from "../../class/WuhuConfig";
|
||||
import WT_HTML from "../../../static/html/xmasTown/wt.html";
|
||||
import WT_XMAS_TOWN_HTML from "../../../static/html/xmasTown/wt_xmas_town.html";
|
||||
import WT_MALTESE_SNOW_GLOBE_HTML from "../../../static/html/xmasTown/wt_maltese_snow_globe.html";
|
||||
@ -13,10 +12,15 @@ import WT_DOGGOQUEST_HTML from "../../../static/html/xmasTown/wt_doggoQuest.html
|
||||
import WT_POKEMON_CT_HTML from "../../../static/html/xmasTown/wt_pokemon_ct.html";
|
||||
import WT_WINTER_IN_GATLIN_HTML from "../../../static/html/xmasTown/wt_winter_in_gatlin.html";
|
||||
import XMAS_TOWN_NOTIFY_HTML from "../../../static/html/xmasTown/xmas_town_notify.html";
|
||||
import { Container } from "../../container/Container";
|
||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
||||
|
||||
export default function christmasTownHelper() {
|
||||
const localConfigWrapper = Container.factory(LocalConfigWrapper);
|
||||
|
||||
let $root = document.querySelector('#christmastownroot');
|
||||
const [xmasTownWT, xmasTownNotify] = WuhuConfig.get(['xmasTownWT', 'xmasTownNotify']);
|
||||
const xmasTownWT = localConfigWrapper.config.xmasTownWT;
|
||||
const xmasTownNotify = localConfigWrapper.config.xmasTownNotify;
|
||||
// 解密攻略
|
||||
if (xmasTownWT) {
|
||||
const insert_html = WT_HTML;
|
||||
|
||||
@ -3,6 +3,7 @@ import CommonUtils from "../../class/utils/CommonUtils";
|
||||
import CITY_FINDER_CSS from "../../../static/css/city_finder.css";
|
||||
import TornStyleBlock from "../../class/utils/TornStyleBlock";
|
||||
import ItemHelper from "../../class/utils/ItemHelper";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
/**
|
||||
* 2023-02-22 修改物品价格查询逻辑,缓存优先
|
||||
@ -39,7 +40,7 @@ export default function cityFinder(_base: TornStyleBlock): void {
|
||||
// Log.error(err);
|
||||
// items = undefined
|
||||
// });
|
||||
let itemHelper = ItemHelper.getInstance();
|
||||
let itemHelper = Container.factory(ItemHelper);
|
||||
CommonUtils.elementReady('div.leaflet-marker-pane').then(elem => {
|
||||
// document.querySelector('.content-wrapper').prepend(base);
|
||||
|
||||
|
||||
@ -1,23 +1,26 @@
|
||||
import WuhuBase from "../../class/WuhuBase";
|
||||
import CommonUtils from "../../class/utils/CommonUtils";
|
||||
import Log from "../../class/Log";
|
||||
import Alert from "../../class/utils/Alert";
|
||||
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
|
||||
import WuhuConfig from "../../class/WuhuConfig";
|
||||
import FetchUtils from "../../class/utils/FetchUtils";
|
||||
import DEPO_CSS from "../../../static/css/depo.css";
|
||||
import TornStyleBlock from "../../class/utils/TornStyleBlock";
|
||||
import { Container } from "../../container/Container";
|
||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
||||
|
||||
const fetchUtils = Container.factory(FetchUtils);
|
||||
|
||||
export default function depoHelper() {
|
||||
let actionButtonUtils: ActionButtonUtils = ActionButtonUtils.getInstance();
|
||||
let { href } = WuhuBase.glob;
|
||||
let actionButtonUtils: ActionButtonUtils = Container.factory(ActionButtonUtils);
|
||||
let localConfigWrapper: LocalConfigWrapper = Container.factory(LocalConfigWrapper);
|
||||
let href = window.location.href;
|
||||
let channel: 'CMPY' | 'FAC';
|
||||
const selector = { 'CMPY': "div#funds div.deposit", 'FAC': "div#armoury-donate div.cash" };
|
||||
// 公司
|
||||
if (href.includes('companies.php')) {
|
||||
channel = "CMPY";
|
||||
// 公司转跳存钱
|
||||
if (!href.includes('funds') && WuhuConfig.get('companyRedirect')) {
|
||||
if (!href.includes('funds') && localConfigWrapper.config.companyRedirect) {
|
||||
const btn = document.getElementById('ui-id-9');
|
||||
if (btn) {
|
||||
btn.click();
|
||||
@ -25,7 +28,7 @@ export default function depoHelper() {
|
||||
}
|
||||
}
|
||||
// 收起冰蛙表格
|
||||
if (WuhuConfig.get('companyBWCollapse')) {
|
||||
if (localConfigWrapper.config.companyBWCollapse) {
|
||||
CommonUtils.elementReady('#effectiveness-wrap').then(BWTable_node => {
|
||||
document.body.classList.add('wh-bwtable-ctrl');
|
||||
CommonUtils.addStyle(`.wh-bwtable-ctrl #effectiveness-wrap {display:none !important;}`);
|
||||
@ -48,7 +51,7 @@ export default function depoHelper() {
|
||||
actionButtonUtils.add('一键存钱', factionDeposit);
|
||||
}
|
||||
// 存钱框浮动
|
||||
if (WuhuConfig.get('floatDepo') && channel) {
|
||||
if (localConfigWrapper.config.floatDepo && channel) {
|
||||
document.body.classList.add('wh-depo-helper');
|
||||
CommonUtils.addStyle(DEPO_CSS);
|
||||
CommonUtils.elementReady(selector[channel]).then(node => {
|
||||
@ -89,7 +92,7 @@ export default function depoHelper() {
|
||||
let getTraceMoney = async () => {
|
||||
if (typeof addRFC === 'function') {
|
||||
let url = addRFC('/trade.php?step=getFullMoney&ID=' + traceId);
|
||||
return (await FetchUtils.getInstance().ajaxFetch({
|
||||
return (await fetchUtils.ajaxFetch({
|
||||
url: url,
|
||||
method: 'GET',
|
||||
referrer: 'trade.php'
|
||||
@ -152,7 +155,7 @@ export default function depoHelper() {
|
||||
new Alert('无法定额取钱,原因:数不对');
|
||||
return;
|
||||
}
|
||||
await FetchUtils.getInstance().ajaxFetch({
|
||||
await fetchUtils.ajaxFetch({
|
||||
url: addRFC('/trade.php'),
|
||||
method: 'POST',
|
||||
referrer: 'trade.php',
|
||||
@ -164,7 +167,7 @@ export default function depoHelper() {
|
||||
buttonDepositAll.addEventListener('click', async () => {
|
||||
let money = await getTraceMoney();
|
||||
if (money === '0') return;
|
||||
await FetchUtils.getInstance().ajaxFetch({
|
||||
await fetchUtils.ajaxFetch({
|
||||
url: addRFC('/trade.php'),
|
||||
method: 'POST',
|
||||
referrer: 'trade.php',
|
||||
@ -174,7 +177,7 @@ export default function depoHelper() {
|
||||
});
|
||||
// 全取
|
||||
buttonWithdrawAll.addEventListener('click', async () => {
|
||||
await FetchUtils.getInstance().ajaxFetch({
|
||||
await fetchUtils.ajaxFetch({
|
||||
url: addRFC('/trade.php'),
|
||||
method: 'POST',
|
||||
referrer: 'trade.php',
|
||||
@ -199,14 +202,14 @@ export default function depoHelper() {
|
||||
}
|
||||
|
||||
// 任何位置公司一键存钱
|
||||
if (WuhuConfig.get('companyDepositAnywhere')) {
|
||||
actionButtonUtils.add('公司存钱', companyDepositAnywhere);
|
||||
if (localConfigWrapper.config.companyDepositAnywhere) {
|
||||
actionButtonUtils.add('公司存钱', () => companyDepositAnywhere());
|
||||
}
|
||||
}
|
||||
|
||||
// 公司一键存钱
|
||||
async function companyDeposit() {
|
||||
let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||
// let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||
if (!location.href.contains('option=funds')) {
|
||||
new Alert('请先打开公司金库');
|
||||
return;
|
||||
@ -228,7 +231,7 @@ async function companyDeposit() {
|
||||
|
||||
// 帮派一键存钱
|
||||
async function factionDeposit() {
|
||||
let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||
// let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||
let form = document.querySelector('#armoury-donate form');
|
||||
if (!location.hash.includes('tab=armoury') || !form) {
|
||||
new Alert('请先打开金库');
|
||||
@ -258,7 +261,7 @@ async function factionDeposit() {
|
||||
|
||||
// 所有页面公司一键存钱
|
||||
async function companyDepositAnywhere() {
|
||||
let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||
// let fetchUtils: FetchUtils = FetchUtils.getInstance();
|
||||
let { addRFC } = window;
|
||||
if (typeof addRFC !== 'function') return;
|
||||
let url = addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction');
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
import WuhuConfig from "../../class/WuhuConfig";
|
||||
import Popup from "../../class/utils/Popup";
|
||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
// 落地转跳设置
|
||||
export default function landedRedirect() {
|
||||
let localConfigWrapper: LocalConfigWrapper = Container.factory(LocalConfigWrapper);
|
||||
|
||||
let p = document.createElement('p');
|
||||
let input = document.createElement('input');
|
||||
let buttonSave = document.createElement('button');
|
||||
@ -13,7 +17,7 @@ export default function landedRedirect() {
|
||||
|
||||
p.innerHTML = '飞机落地后转跳的页面,关闭功能请置空:';
|
||||
input.placeholder = 'URL';
|
||||
input.value = WuhuConfig.get('landedRedirect') || '';
|
||||
input.value = localConfigWrapper.config.landedRedirect ?? '';
|
||||
input.style.display = 'block';
|
||||
input.style.textAlign = 'left';
|
||||
input.style.width = '100%';
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import UserScriptEngine from "../../enum/UserScriptEngine";
|
||||
import addStyle from "../utils/@deprecated/addStyle";
|
||||
import log from "../utils/@deprecated/log";
|
||||
import CommonUtils from "../../class/utils/CommonUtils";
|
||||
import Alert from "../../class/utils/Alert";
|
||||
import { Container } from "../../container/Container";
|
||||
import Logger from "../../class/Logger";
|
||||
|
||||
// gs loader
|
||||
export default function loadGS(use) {
|
||||
let logger = Container.factory(Logger);
|
||||
if (use === UserScriptEngine.PDA) {
|
||||
let ifr: HTMLIFrameElement = document.querySelector('#wh-gs-loader-ifr');
|
||||
if (ifr) {
|
||||
@ -19,7 +20,7 @@ export default function loadGS(use) {
|
||||
ifr.src = 'https://www.torn.com/crimes.php';
|
||||
container.append(ifr);
|
||||
document.body.append(container);
|
||||
addStyle(`
|
||||
CommonUtils.addStyle(`
|
||||
#wh-gs-loader {
|
||||
position:fixed;
|
||||
top:0;
|
||||
@ -75,7 +76,7 @@ z-index:100001;
|
||||
};
|
||||
new MutationObserver(thisRun).observe(gsp, { childList: true, subtree: true });
|
||||
thisRun();
|
||||
if (log.debug()) _window.GM_setValue("gsp_showContent", true)
|
||||
if (logger.debug()) _window.GM_setValue("gsp_showContent", true)
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -103,7 +104,7 @@ z-index:100001;
|
||||
CommonUtils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`)
|
||||
.then(GSJS => {
|
||||
window.eval(GSJS);
|
||||
if (log.debug()) window.GM_setValue("gsp_showContent", true);
|
||||
if (logger.debug()) window.GM_setValue("gsp_showContent", true);
|
||||
notify.close();
|
||||
notify = new Alert('已载入飞贼助手');
|
||||
})
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import toThousands from "../utils/toThousands";
|
||||
import Log from "../../class/Log";
|
||||
import Alert from "../../class/utils/Alert";
|
||||
import WuhuConfig from "../../class/WuhuConfig";
|
||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
// 价格监视handle
|
||||
export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) {
|
||||
let localConfigWrapper: LocalConfigWrapper = Container.factory(LocalConfigWrapper);
|
||||
|
||||
let priceTemp = {};
|
||||
let intervalId = window.setInterval(() => {
|
||||
const price_conf = WuhuConfig.get('priceWatcher');
|
||||
const price_conf = localConfigWrapper.config.priceWatcher;
|
||||
const apikey = isPDA ? PDA_APIKey : localStorage.getItem('APIKey');
|
||||
if (!apikey || (price_conf['pt'] === -1 && price_conf['xan'] === -1)) {
|
||||
Log.warn('价格监视关闭,无apikey或设置未打开');
|
||||
|
||||
@ -2,9 +2,12 @@ import Alert from "../../class/utils/Alert";
|
||||
import InfoUtils from "../../class/utils/InfoUtils";
|
||||
import Log from "../../class/Log";
|
||||
import Popup from "../../class/utils/Popup";
|
||||
import { Container } from "../../container/Container";
|
||||
|
||||
// 守望者
|
||||
export default function safeKeeper() {
|
||||
let infoUtils = Container.factory(InfoUtils);
|
||||
|
||||
let url = `https://www.torn.com/loader.php?sid=attackData&mode=json&step=poll&user2ID=`;
|
||||
let popup = new Popup('<p>监测目标ID玩家的防御状态,找出隐身攻击者</p>', '守望者 (测试中)');
|
||||
let p = document.createElement('p');
|
||||
@ -118,5 +121,5 @@ export default function safeKeeper() {
|
||||
loop_id = null;
|
||||
p.innerHTML = '状态:已关 ❎';
|
||||
});
|
||||
self_target.addEventListener('click', () => uid.value = (InfoUtils.getInstance().getPlayerInfo()['userID']) + '');
|
||||
self_target.addEventListener('click', () => uid.value = (infoUtils.getPlayerInfo()['userID']) + '');
|
||||
}
|
||||
@ -1,26 +1,79 @@
|
||||
import titleTrans from "../translate/titleTrans";
|
||||
import contentTitleLinksTrans from "../translate/contentTitleLinksTrans";
|
||||
import Device from "../../enum/Device";
|
||||
import WuhuBase from "../../class/WuhuBase";
|
||||
import Alert from "../../class/utils/Alert";
|
||||
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
|
||||
import WuhuConfig from "../../class/WuhuConfig";
|
||||
import CommonUtils from "../../class/utils/CommonUtils";
|
||||
import TRAVEL_ALARM_CSS from "../../../static/css/travel_alarm.css";
|
||||
import TRAVEL_ALARM_HTML from "../../../static/html/travel_alarm.html";
|
||||
import TornStyleBlock from "../../class/utils/TornStyleBlock";
|
||||
import QuickFlyBtnHandler from "../../class/handler/QuickFlyBtnHandler";
|
||||
import TRAVEL_STATE from "../../enum/TravelState";
|
||||
import Global from "../../class/Global";
|
||||
import ClassName from "../../container/ClassName";
|
||||
import { Injectable } from "../../container/Injectable";
|
||||
import LocalConfigWrapper from "../../class/LocalConfigWrapper";
|
||||
|
||||
export default async function travelHelper(): Promise<void> {
|
||||
let { href, bodyAttrs, device } = WuhuBase.glob;
|
||||
// async function travelHelper(): Promise<void> {
|
||||
// let global = Container.factory(Global);
|
||||
// let commonUtils = Container.factory(CommonUtils);
|
||||
// }
|
||||
|
||||
// async function travelBack(): Promise<null> {
|
||||
// if (typeof window['getAction'] !== 'function') return;
|
||||
// let backHomeAction = function (): Promise<string> {
|
||||
// return new Promise(resolve => {
|
||||
// window.getAction({
|
||||
// type: "post",
|
||||
// action: 'travelagency.php',
|
||||
// data: {
|
||||
// step: 'backHomeAction'
|
||||
// },
|
||||
// success: function (msg) {
|
||||
// resolve(msg);
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// };
|
||||
// let res = await backHomeAction();
|
||||
// new Alert(res);
|
||||
// if (!res.includes('error')) {
|
||||
// new Alert('成功,即将刷新');
|
||||
// window.setTimeout(() => location.reload(), 3000);
|
||||
// } else {
|
||||
// new Alert('出错了');
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 飞行助手
|
||||
* - 飞行闹钟
|
||||
* - 一键回城
|
||||
* - 解毒提醒
|
||||
* - 落地转跳
|
||||
* - 海外警告
|
||||
*/
|
||||
@ClassName('TravelHelper')
|
||||
@Injectable()
|
||||
export default class TravelHelper {
|
||||
constructor(
|
||||
private readonly global: Global,
|
||||
private readonly commonUtils: CommonUtils,
|
||||
private readonly actionButtonUtils: ActionButtonUtils,
|
||||
private readonly localConfigWrapper: LocalConfigWrapper,
|
||||
) {
|
||||
}
|
||||
|
||||
init() {
|
||||
let { bodyAttrs, device } = this.global;
|
||||
let href = window.location.href;
|
||||
|
||||
if (href.includes('index.php')) {
|
||||
switch (CommonUtils.getInstance().getTravelStage()) {
|
||||
switch (this.commonUtils.getTravelStage()) {
|
||||
// 飞行中
|
||||
case TRAVEL_STATE.FLYING: {
|
||||
// 飞行闹钟
|
||||
if (device === Device.PC && WuhuConfig.get('trvAlarm')) {
|
||||
if (device === Device.PC && this.localConfigWrapper.config.trvAlarm) {
|
||||
// 获取目的地
|
||||
let dest_cn;
|
||||
let country = document.body.getAttribute('data-country');
|
||||
@ -192,9 +245,9 @@ export default async function travelHelper(): Promise<void> {
|
||||
}
|
||||
|
||||
// 落地转跳 落地前事件
|
||||
if (WuhuConfig.get('landedRedirect') && document.querySelector('#tcLogo[title]') === null) {
|
||||
if (this.localConfigWrapper.config.landedRedirect && document.querySelector('#tcLogo[title]') === null) {
|
||||
window.addEventListener('beforeunload', () => {
|
||||
let obj = { url: WuhuConfig.get('landedRedirect'), timestamp: Date.now() };
|
||||
let obj = { url: this.localConfigWrapper.config.landedRedirect, timestamp: Date.now() };
|
||||
sessionStorage['wh-landed-redirect'] = JSON.stringify(obj);
|
||||
});
|
||||
}
|
||||
@ -203,9 +256,9 @@ export default async function travelHelper(): Promise<void> {
|
||||
// 海外落地
|
||||
case TRAVEL_STATE.ABROAD: {
|
||||
// 一键回城
|
||||
ActionButtonUtils.getInstance().add('直接回城', travelBack);
|
||||
this.actionButtonUtils.add('直接回城', () => this.doTravelBack());
|
||||
// 海外警告
|
||||
if (WuhuConfig.get('abroadWarning')) {
|
||||
if (this.localConfigWrapper.config.abroadWarning) {
|
||||
let c = 1;
|
||||
setInterval(() => new Alert(`警告:您已海外落地${ c++ * 30 }秒`, {
|
||||
timeout: 30,
|
||||
@ -237,7 +290,7 @@ export default async function travelHelper(): Promise<void> {
|
||||
// 起飞页面
|
||||
else if (href.contains(/travelagency\.php/)) {
|
||||
// 起飞提醒 TODO 去除jquery mutation
|
||||
if (WuhuConfig.get('energyAlert')) {
|
||||
if (this.localConfigWrapper.config.energyAlert) {
|
||||
const contentWrapper = document.querySelector('.content-wrapper');
|
||||
const OB = new MutationObserver(() => {
|
||||
OB.disconnect();
|
||||
@ -285,13 +338,17 @@ export default async function travelHelper(): Promise<void> {
|
||||
});
|
||||
}
|
||||
// 一键起飞
|
||||
if (sessionStorage['wh-quick-fly']) {
|
||||
if (window.sessionStorage['wh-quick-fly']) {
|
||||
QuickFlyBtnHandler.doQuickFly();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function travelBack(): Promise<null> {
|
||||
/** TODO */
|
||||
inTravelPage() {
|
||||
}
|
||||
|
||||
async doTravelBack(): Promise<void> {
|
||||
if (typeof window['getAction'] !== 'function') return;
|
||||
let backHomeAction = function (): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
@ -315,4 +372,5 @@ async function travelBack(): Promise<null> {
|
||||
} else {
|
||||
new Alert('出错了');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
import { eventsDict, gymList, ocList } from "../../dictionary/translation";
|
||||
import log from "../utils/@deprecated/log";
|
||||
|
||||
let log = { info: (args) => null };
|
||||
|
||||
export default function eventsTrans(events: JQuery = $('span.mail-link')) {
|
||||
const index = window.location.href.indexOf('events.php#/step=received') >= 0 ? 1 : 0;
|
||||
@ -553,9 +554,9 @@ export default function eventsTrans(events: JQuery = $('span.mail-link')) {
|
||||
const num = spl[3] === 'a' ? '1' : spl[3];
|
||||
const price = reasonSpl[0].split(' ').slice(-1)[0];
|
||||
const reason = reasonSpl[1] ? reasonSpl[1] : null;
|
||||
const trans = `${ someone ? '某人' : ' ' }对你进行了 ${ num } 次赏金为 ${ price } 的悬赏${ reason ? ',原因:' + reason : '' }`;
|
||||
const trans = `${ someone ?? '某人1' }对你进行了 ${ num } 次赏金为 ${ price } 的悬赏${ reason ? ',原因:' + reason : '' }`;
|
||||
// 匿名悬赏
|
||||
if (someone) {
|
||||
if (!!someone) {
|
||||
$(e).text(trans);
|
||||
}
|
||||
// 实名悬赏
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import log from "../utils/@deprecated/log";
|
||||
let log = { info: (args) => null };
|
||||
|
||||
/**
|
||||
* observe 包装
|
||||
|
||||
@ -34,11 +34,12 @@ import initOB from "./initOB";
|
||||
import titleTrans from "./titleTrans";
|
||||
import contentTitleLinksTrans from "./contentTitleLinksTrans";
|
||||
import showItemInfoTrans from "./showItemInfoTrans";
|
||||
import log from "../utils/@deprecated/log";
|
||||
import contentTitleLinksTransReact from "./contentTitleLinksTransReact";
|
||||
import titleTransReact from "./titleTransReact";
|
||||
import Log from "../../class/Log";
|
||||
|
||||
let log = { info: (args) => null };
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param href
|
||||
@ -1112,7 +1113,7 @@ export default function translateMain(href: string): void {
|
||||
}
|
||||
} else {
|
||||
if ($('.wh-translated').length <= 0) {
|
||||
log.info(`未找到翻译: “${ action_desc.text().trim() }”`);
|
||||
log.info(`未找到翻译: 「${ action_desc.text().trim() }」`);
|
||||
}
|
||||
}
|
||||
// 添加敌人或朋友的界面
|
||||
|
||||
@ -1,98 +0,0 @@
|
||||
import audioPlay from "./audioPlay";
|
||||
import MathUtils from "../../../class/utils/MathUtils";
|
||||
import Alert from "../../../class/utils/Alert";
|
||||
import InfoUtils from "../../../class/utils/InfoUtils";
|
||||
import WuhuConfig from "../../../class/WuhuConfig";
|
||||
import Log from "../../../class/Log";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function BuyBeer() {
|
||||
// 正在通知
|
||||
let is_notified = false;
|
||||
let time: number = WuhuConfig.get('_15AlarmTime') || 30;
|
||||
let loop: BeerMonitorLoop = {};
|
||||
// 循环id
|
||||
let started = null;
|
||||
loop.start = () => {
|
||||
if (started) {
|
||||
Log.info('啤酒助手已在运行');
|
||||
return;
|
||||
}
|
||||
started = setInterval(async () => {
|
||||
// 海外取消提醒
|
||||
let { isTravelling, isAbroad } = await InfoUtils.getInstance().getUserState();
|
||||
if (isTravelling || isAbroad) {
|
||||
loop.stop();
|
||||
return;
|
||||
}
|
||||
let dt = new Date();
|
||||
// 已选当天不提醒
|
||||
const now = [dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate()];
|
||||
const ignore_date = WuhuConfig.get('_15_alarm_ignore') || '{}';
|
||||
if (JSON.stringify(now) === JSON.stringify(ignore_date)) return;
|
||||
// 正常提醒
|
||||
let m = 14 - (dt.getMinutes() % 15);
|
||||
let s = 60 - dt.getSeconds();
|
||||
if (m === 0 && s < time) {
|
||||
// 如从通知点开,则本次通知跳过
|
||||
if (location.href.includes('#clickfromnotify')) {
|
||||
is_notified = true;
|
||||
location.hash = '';
|
||||
return;
|
||||
}
|
||||
// 本次已通知
|
||||
if (is_notified) return;
|
||||
is_notified = true;
|
||||
// 发送通知
|
||||
const notify = new Alert(notify_html, {
|
||||
timeout: 30,
|
||||
sysNotify: true,
|
||||
});
|
||||
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => loop.skip_today);
|
||||
notify.getElement().addEventListener('click', ev => {
|
||||
if ((ev.target as HTMLElement).tagName.toLowerCase() === 'a') {
|
||||
// notify.sys_notify.close();
|
||||
notify.close();
|
||||
}
|
||||
});
|
||||
window.setTimeout(audioPlay, 800);
|
||||
window.setTimeout(audioPlay, 800 * 2);
|
||||
window.setTimeout(audioPlay, 800 * 3);
|
||||
} else {
|
||||
is_notified = false;
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
loop.stop = () => {
|
||||
if (started) {
|
||||
clearInterval(started);
|
||||
started = null;
|
||||
}
|
||||
};
|
||||
loop.set_time = (t) => time = t;
|
||||
loop.status = () => started ? '已启动' : '未启动';
|
||||
loop.is_running = () => !!started;
|
||||
|
||||
let mathUtils: MathUtils = MathUtils.getInstance();
|
||||
let notify_html = `<span style="background-color:green;color:white;border-radius:3px;font-size:14px;line-height:21px;padding:2px 4px;">啤酒小助手</span><br/>提醒您:还有不到 50 秒 NPC 的商品就要刷新了,啤酒血包要抢的可以准备咯。<button id="wh-rd-btn-${ mathUtils.getRandomInt(0, 100) }">【今日不再提醒】</button><br/><a href="/shops.php?step=bitsnbobs#clickfromnotify" target="_blank">【啤酒店】</a> <a href="/shops.php?step=pharmacy#clickfromnotify" target="_blank">【血包店】</a>`
|
||||
loop.skip_today = () => {
|
||||
const date = new Date();
|
||||
WuhuConfig.set('_15_alarm_ignore', [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()], false);
|
||||
// 通知
|
||||
const notify = new Alert(`明早8点前将不再提醒 <button id="wh-rd-btn-${ mathUtils.getRandomInt(0, 100) }">取消</button>`);
|
||||
// 通知中的取消按钮
|
||||
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => WuhuConfig.set('_15_alarm_ignore', undefined));
|
||||
};
|
||||
return loop;
|
||||
}
|
||||
|
||||
export interface BeerMonitorLoop {
|
||||
start?: Function;
|
||||
stop?: Function;
|
||||
set_time?: Function;
|
||||
status?: Function;
|
||||
is_running?: Function;
|
||||
skip_today?: Function;
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
import UserScriptEngine from "../../../enum/UserScriptEngine";
|
||||
import getScriptEngine from "./getScriptEngine";
|
||||
import Log from "../../../class/Log";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function COFetch(url: URL | string, method: 'get' | 'post' = 'get', body: any = null): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const engine = getScriptEngine();
|
||||
switch (engine) {
|
||||
case UserScriptEngine.RAW: {
|
||||
console.error(`[wh] 跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
|
||||
reject(`错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
|
||||
break;
|
||||
}
|
||||
case UserScriptEngine.PDA: {
|
||||
const { PDA_httpGet, PDA_httpPost } = window;
|
||||
// get
|
||||
if (method === 'get') {
|
||||
if (typeof PDA_httpGet !== 'function') {
|
||||
Log.error('COFetch网络错误:PDA版本不支持');
|
||||
reject('COFetch网络错误:PDA版本不支持');
|
||||
}
|
||||
PDA_httpGet(url)
|
||||
.then(res => resolve(res.responseText))
|
||||
.catch(e => {
|
||||
Log.error('COFetch网络错误', e);
|
||||
reject(`COFetch网络错误 ${ e }`);
|
||||
})
|
||||
}
|
||||
// post
|
||||
else {
|
||||
if (typeof PDA_httpPost !== 'function') {
|
||||
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);
|
||||
reject(`COFetch网络错误 ${ e }`);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UserScriptEngine.GM: {
|
||||
let { GM_xmlhttpRequest } = window;
|
||||
if (typeof GM_xmlhttpRequest !== 'function') {
|
||||
Log.error('COFetch网络错误:用户脚本扩展API错误');
|
||||
reject('错误:用户脚本扩展API错误');
|
||||
}
|
||||
GM_xmlhttpRequest({
|
||||
method: method,
|
||||
url: url,
|
||||
data: method === 'get' ? null : body,
|
||||
headers: method === 'get' ? null : { 'content-type': 'application/json' },
|
||||
onload: res => resolve(res.response),
|
||||
onerror: res => reject(`连接错误 ${ JSON.stringify(res) }`),
|
||||
ontimeout: res => reject(`连接超时 ${ JSON.stringify(res) }`),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* 解析 Markdown 内容
|
||||
* @param {String} from
|
||||
* @param {Number} max_line 最大行数,默认500
|
||||
* @returns {HTMLDivElement}
|
||||
* @deprecated
|
||||
*/
|
||||
export default function mdParse(from: string, max_line?: number): HTMLElement {
|
||||
max_line = max_line || 500;
|
||||
const base = document.createElement('div');
|
||||
let lines = from.split('\n');
|
||||
if (lines.length > max_line) {
|
||||
lines = lines.slice(0, max_line);
|
||||
lines.push("...");
|
||||
}
|
||||
|
||||
let prev = '';
|
||||
let child_cont;
|
||||
lines.forEach(line => {
|
||||
if (line.trim() === '') return;
|
||||
let node;
|
||||
let spl = line.split(' ');
|
||||
let md_flag = spl[0];
|
||||
|
||||
switch (md_flag) {
|
||||
// 标题
|
||||
case '#':
|
||||
case '##':
|
||||
case '###':
|
||||
if (prev === 'li') {
|
||||
child_cont = null;
|
||||
}
|
||||
prev = 'h' + (md_flag.length + 1);
|
||||
node = document.createElement(prev);
|
||||
node.innerText = line.slice(md_flag.length + 1);
|
||||
base.append(node);
|
||||
return;
|
||||
// 列表
|
||||
case '-':
|
||||
if (prev !== 'li') {
|
||||
child_cont = document.createElement('ul');
|
||||
if (!base.contains(child_cont)) base.append(child_cont);
|
||||
}
|
||||
prev = 'li';
|
||||
node = document.createElement(prev);
|
||||
node.innerText = line.slice(2);
|
||||
child_cont.append(node);
|
||||
return;
|
||||
}
|
||||
prev = 'p';
|
||||
node = document.createElement(prev);
|
||||
node.innerText = line.trim();
|
||||
base.append(node);
|
||||
})
|
||||
return base;
|
||||
}
|
||||
@ -1,151 +0,0 @@
|
||||
import addStyle from "./addStyle";
|
||||
import WuhuBase from "../../../class/WuhuBase";
|
||||
import MathUtils from "../../../class/utils/MathUtils";
|
||||
import WindowActiveState from "../../../class/action/WindowActiveState";
|
||||
|
||||
/**
|
||||
* 通知方法
|
||||
* @param {string} msg - 通知内容
|
||||
* @param {Object} [options] - 通知选项
|
||||
* @param {number} [options.timeout] - 通知超时时间
|
||||
* @param {function} [options.callback] - 通知回调
|
||||
* @param {boolean} [options.sysNotify] - 是否开启系统通知
|
||||
* @param {string} [options.sysNotifyTag] - 系统通知标记
|
||||
* @param {function} [options.sysNotifyClick] - 系统通知点击事件
|
||||
* @return {HTMLElement}
|
||||
* @deprecated
|
||||
*/
|
||||
export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTMLElement {
|
||||
let { notifies } = WuhuBase.glob;
|
||||
let mathUtils: MathUtils = MathUtils.getInstance();
|
||||
|
||||
let {
|
||||
timeout = 3,
|
||||
callback = function () {
|
||||
},
|
||||
sysNotify = false,
|
||||
sysNotifyTag = '芜湖助手',
|
||||
sysNotifyClick = () => window.focus()
|
||||
} = options;
|
||||
|
||||
if (!WindowActiveState.getInstance().get() || (self !== top)) return null;
|
||||
const date = new Date();
|
||||
// 通知的唯一id
|
||||
const uid = `${ date.getHours() }${ date.getSeconds() }${ date.getMilliseconds() }${ mathUtils.getRandomInt(1000, 9999) }`;
|
||||
// 通知容器id
|
||||
// 通知的容器
|
||||
let notify_contain: MyHTMLElement = document.querySelector(`#wh-notify`);
|
||||
// 添加通知到容器
|
||||
const add_notify = () => {
|
||||
// 每条通知
|
||||
const new_node: MyHTMLElement = document.createElement('div');
|
||||
new_node.id = `wh-notify-${ uid }`;
|
||||
new_node.classList.add('wh-notify-item');
|
||||
new_node.innerHTML = `<div class="wh-notify-bar"></div>
|
||||
<div class="wh-notify-cont">
|
||||
<div class="wh-notify-close"></div>
|
||||
<div class="wh-notify-msg"><p>${ msg }</p></div>
|
||||
</div>`;
|
||||
notify_contain.append(new_node);
|
||||
notify_contain['msgInnerText'] = new_node.querySelector('.wh-notify-msg').innerText;
|
||||
// 进度条node
|
||||
const progressBar: HTMLElement = new_node.querySelector('.wh-notify-bar');
|
||||
// 是否hover
|
||||
let mouse_enter = false;
|
||||
new_node.addEventListener('mouseenter', () => mouse_enter = true, true);
|
||||
new_node.addEventListener('mouseleave', () => mouse_enter = false);
|
||||
// 通知进度条
|
||||
let progressCount = 101;
|
||||
// 删除通知
|
||||
new_node.close = () => {
|
||||
clearInterval(intervalID);
|
||||
new_node.remove();
|
||||
callback();
|
||||
};
|
||||
// 计时器
|
||||
let intervalID = window.setInterval(() => {
|
||||
if (mouse_enter) {
|
||||
progressCount = 101;
|
||||
progressBar.style.width = '100%';
|
||||
return;
|
||||
}
|
||||
progressCount--;
|
||||
progressBar.style.width = `${ progressCount }%`;
|
||||
if (progressCount === 0) new_node.remove();
|
||||
}, timeout * 1000 / 100);
|
||||
new_node.querySelector('.wh-notify-close').addEventListener('click', new_node.close);
|
||||
return new_node;
|
||||
};
|
||||
// 不存在容器 创建
|
||||
if (!notify_contain) {
|
||||
notify_contain = document.createElement('div');
|
||||
notify_contain.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(notify_contain);
|
||||
}
|
||||
const notify_obj = add_notify();
|
||||
// 浏览器通知
|
||||
if (window.Notification && Notification.permission === 'granted' && sysNotify) {
|
||||
const date_local_string = `[${ date.getHours() }:${ date.getMinutes() }:${ date.getSeconds() }]\r`;
|
||||
notify_obj.sys_notify = new Notification('芜湖助手', {
|
||||
body: date_local_string + notify_contain.msgInnerText,
|
||||
requireInteraction: true,
|
||||
renotify: true,
|
||||
tag: sysNotifyTag + mathUtils.getRandomInt(0, 99),
|
||||
});
|
||||
notify_obj.sys_notify.addEventListener('close', () => sysNotifyClick());
|
||||
notify_obj.sys_notify.onshow = () => setTimeout(() => notify_obj.sys_notify.close(), timeout * 1000);
|
||||
notify_obj.sys_notify.id = notifies.count++;
|
||||
notifies[notify_obj.sys_notify.id] = notify_obj.sys_notify;
|
||||
notify_obj.sys_notify.addEventListener('close', () => notifies[notify_obj.sys_notify.id] = null);
|
||||
}
|
||||
return notify_obj;
|
||||
}
|
||||
|
||||
interface WHNotifyOpt {
|
||||
timeout?: number;
|
||||
callback?: Function;
|
||||
sysNotify?: boolean;
|
||||
sysNotifyTag?: string;
|
||||
sysNotifyClick?: Function;
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
import Log from "../../../class/Log";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function addActionBtn(txt: string, func: (ev: Event) => void, mainBtnNode: Element): void {
|
||||
addActionBtn.proxy(txt, func, mainBtnNode);
|
||||
}
|
||||
|
||||
addActionBtn.proxy = (txt: string, func: (ev: Event) => void, mainBtnNode: Element) => {
|
||||
if (mainBtnNode.querySelector('#wh-trans-icon-btn').nextSibling !== null) return;
|
||||
let btn = document.createElement('button');
|
||||
btn.style.padding = '8px 13px 8px 0';
|
||||
btn.style.verticalAlign = 'bottom';
|
||||
btn.style.color = '#4CAF50';
|
||||
btn.innerHTML = txt;
|
||||
btn.addEventListener('click', func);
|
||||
mainBtnNode.querySelector('button').after(btn);
|
||||
addActionBtn.proxy = () => {
|
||||
Log.error('错误:附加按钮已存在')
|
||||
};
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
import log from "./log";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function addStyle(css: string) {
|
||||
let wh_gStyle = document.querySelector('style#wh-trans-gStyle');
|
||||
if (wh_gStyle) {
|
||||
wh_gStyle.innerHTML += css;
|
||||
} else {
|
||||
wh_gStyle = document.createElement("style");
|
||||
wh_gStyle.id = 'wh-trans-gStyle';
|
||||
wh_gStyle.innerHTML = css;
|
||||
document.head.append(wh_gStyle);
|
||||
}
|
||||
log.info('CSS规则已添加', wh_gStyle);
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function ajaxFetch(opt) {
|
||||
let { url, referrer, method, body = null } = opt;
|
||||
let req_params: AjaxFetchOpt = {
|
||||
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
||||
referrer,
|
||||
method,
|
||||
};
|
||||
if (method === 'POST') {
|
||||
req_params.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
req_params.body = body;
|
||||
}
|
||||
return window.fetch(url, req_params);
|
||||
}
|
||||
|
||||
interface AjaxFetchOpt {
|
||||
headers: { 'X-Requested-With'?: string, 'Content-Type'?: string };
|
||||
referrer: string;
|
||||
method: string;
|
||||
body?: any;
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
// import CommonUtils from "../../../class/utils/CommonUtils";
|
||||
// import WindowActiveState from "../../../class/action/WindowActiveState";
|
||||
//
|
||||
// /**
|
||||
// * @deprecated
|
||||
// */
|
||||
// function autoFetchJSON(dest, time = 30) {
|
||||
// let obj;
|
||||
// const res = CommonUtils.COFetch(dest);
|
||||
// setInterval(async () => {
|
||||
// if (!WindowActiveState.getInstance().get()) return;
|
||||
// const res = await CommonUtils.COFetch(dest);
|
||||
// obj = JSON.parse(res);
|
||||
// }, time * 1000);
|
||||
// return {
|
||||
// get: async function () {
|
||||
// if (!obj) {
|
||||
// const str = await res
|
||||
// return obj = JSON.parse(str);
|
||||
// }
|
||||
// return obj;
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
@ -1,11 +0,0 @@
|
||||
import UserScriptEngine from "../../../enum/UserScriptEngine";
|
||||
import WuhuBase from "../../../class/WuhuBase";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function getScriptEngine() {
|
||||
let glob = WuhuBase.glob;
|
||||
return glob.unsafeWindow ? UserScriptEngine.GM : glob.isPDA
|
||||
? UserScriptEngine.PDA : UserScriptEngine.RAW;
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
import CommonUtils from "../../../class/utils/CommonUtils";
|
||||
import Log from "../../../class/Log";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default async function getSidebarData() {
|
||||
let ret = {};
|
||||
let sidebar_id = null;
|
||||
|
||||
let sessionKeys = Object.keys(sessionStorage);
|
||||
if (sessionKeys.length < 2) {
|
||||
// dom获取
|
||||
let sidebar_menu_list = document.querySelectorAll('#sidebar a span[class*="linkName___"]');
|
||||
Log.info({ sidebar_menu_list })
|
||||
if (sidebar_menu_list.length === 0) {
|
||||
await CommonUtils.elementReady('#sidebar a span[class*="linkName___"]');
|
||||
sidebar_menu_list = document.querySelectorAll('#sidebar a span[class*="linkName___"]');
|
||||
}
|
||||
sidebar_menu_list.forEach(node => ret[node.innerHTML.trim().toLowerCase().replaceAll(' ', '_')] = true);
|
||||
} else {
|
||||
// session storage获取
|
||||
for (let key of sessionKeys) {
|
||||
if (key.startsWith('sidebarData')) {
|
||||
sidebar_id = JSON.parse(sessionStorage.getItem(key));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sidebar_id !== null) {
|
||||
for (let area of Object.keys(sidebar_id['areas'])) {
|
||||
ret[area] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.info({ ret, sidebar_id, sessionKeys })
|
||||
if (Object.keys(ret).length === 0) {
|
||||
Log.error('无法获取数据,建议刷新重试');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function getUserState(): {} | any {
|
||||
let obj = {};
|
||||
let hdd = sessionStorage['headerData'];
|
||||
if (hdd) obj = JSON.parse(hdd)['user']['state'];
|
||||
return obj;
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function getWhSettingObj(): WHSettings {
|
||||
return JSON.parse(localStorage.getItem('wh_trans_settings')) || {}
|
||||
}
|
||||
|
||||
interface WHSettings {
|
||||
// TODO 补全
|
||||
[key: string]: any;
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
import getWhSettingObj from "./getWhSettingObj";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
function debug() {
|
||||
try {
|
||||
return getWhSettingObj()['isDev'] || false;
|
||||
} catch (e) {
|
||||
console.error(`[wh] dev状态错误 ${ e }`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
const log = {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
error: (...o) => (debug()) && (console.error('[WH]', ...o)),
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
info: (...o) => (debug()) && (console.log('[WH]', ...o)),
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
debug,
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default log
|
||||
@ -1,29 +0,0 @@
|
||||
import WuhuBase from "../../../class/WuhuBase";
|
||||
|
||||
/**
|
||||
* @deprecated 使用new Popup()
|
||||
*/
|
||||
export default function popupMsg(innerHTML, title = '芜湖助手') {
|
||||
let glob = WuhuBase.glob;
|
||||
if (glob.popup_node) glob.popup_node.close();
|
||||
const chatRoot = document.querySelector('#chatRoot');
|
||||
chatRoot.classList.add('wh-hide');
|
||||
const popup = document.createElement('div');
|
||||
popup.id = 'wh-popup';
|
||||
popup.innerHTML = `<div id="wh-popup-container">
|
||||
<div id="wh-popup-title"><p>${ title }</p></div>
|
||||
<div id="wh-popup-cont">${ innerHTML }</div>
|
||||
</div>`;
|
||||
document.body.append(popup);
|
||||
const rt: MyHTMLElement = popup.querySelector('#wh-popup-cont');
|
||||
rt.close = function () {
|
||||
popup.remove();
|
||||
chatRoot.classList.remove('wh-hide');
|
||||
}
|
||||
popup.addEventListener('click', e => {
|
||||
e.stopImmediatePropagation();
|
||||
if (e.target === popup) rt.close();
|
||||
});
|
||||
glob.popup_node = rt;
|
||||
return rt;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
import getWhSettingObj from "./getWhSettingObj";
|
||||
import Alert from "../../../class/utils/Alert";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default function setWhSetting(key: string, value: any, notify: boolean = true) {
|
||||
const obj = getWhSettingObj()
|
||||
obj[key] = value
|
||||
localStorage.setItem('wh_trans_settings', JSON.stringify(obj))
|
||||
|
||||
// 通知
|
||||
if (notify) new Alert('已保存设置')
|
||||
}
|
||||
@ -1,15 +1,33 @@
|
||||
import Popup from "./class/utils/Popup";
|
||||
|
||||
// export default {
|
||||
// // 监听到的fetch数据
|
||||
// WH_NET_LOG: [],
|
||||
// map: {},
|
||||
// responseHandlers: [],
|
||||
// version: '$$WUHU_DEV_VERSION$$',
|
||||
// } as IGlobVars;
|
||||
//
|
||||
// interface IGlobVars {
|
||||
// WH_NET_LOG: unknown[],
|
||||
// map: { [key: string]: unknown },
|
||||
// responseHandlers: ((url: string, responseBody: { json: unknown, text: string, isModified: boolean }, opt: { method: string, requestBody: unknown }) => void)[],
|
||||
// version: string,
|
||||
// }
|
||||
|
||||
|
||||
type ResponseHandlers = ((url: string, responseBody: { json: unknown, text: string, isModified: boolean }, opt: { method: string, requestBody: unknown }) => void)[];
|
||||
|
||||
/**
|
||||
* 通用全局参数
|
||||
*/
|
||||
export default {
|
||||
class GlobVars {
|
||||
// 监听到的fetch数据
|
||||
WH_NET_LOG: [],
|
||||
map: {},
|
||||
responseHandlers: [],
|
||||
} as IGlobVars;
|
||||
|
||||
interface IGlobVars {
|
||||
WH_NET_LOG: unknown[],
|
||||
map: { [key: string]: unknown },
|
||||
responseHandlers: ((url: string, responseBody: { json: unknown, text: string, isModified: boolean }, opt: { method: string, requestBody: unknown }) => void)[],
|
||||
WH_NET_LOG: unknown[] = [];
|
||||
map: { [key: string]: unknown } = {};
|
||||
responseHandlers: ResponseHandlers = [];
|
||||
version = '$$WUHU_DEV_VERSION$$';
|
||||
popup_node: MyHTMLElement | Popup = null;
|
||||
}
|
||||
|
||||
export default new GlobVars();
|
||||
|
||||
@ -1,51 +1,13 @@
|
||||
import WuhuBase from "./class/WuhuBase";
|
||||
import WuHuTornHelper from "./class/WuhuTornHelper";
|
||||
import ZhongIcon from "./class/ZhongIcon";
|
||||
import { Common } from "./class/Common";
|
||||
import UrlPattern from "./class/UrlMatch";
|
||||
import WuhuConfig from "./class/WuhuConfig";
|
||||
import translateMain from "./func/translate/translateMain";
|
||||
import CommonUtils from "./class/utils/CommonUtils";
|
||||
import EntryPoint from "./class/provider/EntryPoint";
|
||||
import { Container } from "./container/Container";
|
||||
import Log from "./class/Log";
|
||||
import LocalConfigWrapper from "./class/LocalConfigWrapper";
|
||||
import App from "./App";
|
||||
import Logger from "./class/Logger";
|
||||
import EntryPoint from "./class/provider/EntryPoint";
|
||||
import "reflect-metadata";
|
||||
|
||||
@EntryPoint
|
||||
export default class Application {
|
||||
|
||||
public static main(): void {
|
||||
Container.setLogger(Log);
|
||||
WuhuBase.conditionInterrupt();
|
||||
|
||||
// 初始化
|
||||
Container.factory(WuHuTornHelper).init();
|
||||
|
||||
// 插件设置默认值
|
||||
WuhuConfig.setDefaults();
|
||||
|
||||
// 插件图标和设置菜单
|
||||
Container.factory(ZhongIcon).init();
|
||||
|
||||
let tmp = () => {
|
||||
// 所有页面通用
|
||||
try {
|
||||
Container.factory(Common).resolve(Application.main);
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
// URL匹配
|
||||
Container.factory(UrlPattern).resolve();
|
||||
|
||||
// 翻译
|
||||
if (Container.factory(LocalConfigWrapper).config.transEnable)
|
||||
translateMain(window.location.href);
|
||||
};
|
||||
// TODO 临时检测jquery
|
||||
if (typeof $ === "function") {
|
||||
tmp();
|
||||
} else {
|
||||
CommonUtils.getInstance().jQueryReady().then(() => tmp());
|
||||
}
|
||||
class _ {
|
||||
static main() {
|
||||
Container.setLogger(new Logger());
|
||||
Container.factory(App).run();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { MenuItemConfig } from "../class/ZhongIcon";
|
||||
import { InjectionKey } from "vue";
|
||||
|
||||
export default interface MenuItem extends MenuItemConfig {
|
||||
domType: MENU_ITEM_TYPE
|
||||
@ -10,3 +11,6 @@ export enum MENU_ITEM_TYPE {
|
||||
CHECKBOX = 'checkbox',
|
||||
SELECT = 'select',
|
||||
}
|
||||
|
||||
// export
|
||||
export const menuItemList = Symbol() as InjectionKey<MenuItem[]>;
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import Log from "../class/Log";
|
||||
import CompanyHelper from "../class/action/CompanyHelper";
|
||||
import { MENU_ITEM_TYPE } from "../interface/MenuItem";
|
||||
import ClassName from "../container/ClassName";
|
||||
import Debug from "../class/provider/Debug";
|
||||
import "reflect-metadata"
|
||||
import "reflect-metadata";
|
||||
import { Injectable } from "../container/Injectable";
|
||||
import { ButtonHandler } from "../class/provider/ButtonHandler";
|
||||
import { Container } from "../container/Container";
|
||||
@ -52,7 +51,6 @@ class Test {
|
||||
}
|
||||
|
||||
private async case3() {
|
||||
CompanyHelper.getInstance().detectNow();
|
||||
}
|
||||
|
||||
private case4() {
|
||||
@ -65,63 +63,3 @@ export default {
|
||||
domText: '🐞 测试2',
|
||||
clickFunc: () => Container.factory(Test).show(),
|
||||
}
|
||||
|
||||
// const Injectable = (): ClassDecorator => target => {
|
||||
// };
|
||||
|
||||
@Injectable()
|
||||
class OtherServiceC {
|
||||
c = 3;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class OtherServiceB {
|
||||
b = 2;
|
||||
|
||||
constructor(private otherServiceC: OtherServiceC) {
|
||||
}
|
||||
|
||||
printC() {
|
||||
Log.info(this.otherServiceC.c)
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class OtherService {
|
||||
a = 1;
|
||||
|
||||
constructor(private otherServiceB: OtherServiceB) {
|
||||
}
|
||||
|
||||
testB() {
|
||||
Log.info(this.otherServiceB.b);
|
||||
this.otherServiceB.printC();
|
||||
}
|
||||
}
|
||||
|
||||
// // @Injectable(INJECT_MODE.Multi)
|
||||
// @Injectable()
|
||||
// class Logger {
|
||||
// constructor(private readonly targetClass: string) {
|
||||
// }
|
||||
//
|
||||
// info(str = 'test') {
|
||||
// Log.info(str)
|
||||
// }
|
||||
// }
|
||||
|
||||
@Injectable()
|
||||
@ClassName('TestService')
|
||||
class TestService {
|
||||
constructor(
|
||||
public readonly otherService: OtherService,
|
||||
) {
|
||||
}
|
||||
|
||||
testMethod() {
|
||||
Log.info(this.otherService.a);
|
||||
this.otherService.testB();
|
||||
// this.logger.info()
|
||||
// Log.info(this.test);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,15 @@
|
||||
<script lang="ts" setup>
|
||||
import { inject } from 'vue';
|
||||
import { LoggerKey, MenuItemListKey } from "../ts/class/IconHelper";
|
||||
import globVars from "../ts/globVars";
|
||||
|
||||
const logger = inject(LoggerKey);
|
||||
const menuItemList = inject(MenuItemListKey);
|
||||
const version = globVars.version;
|
||||
|
||||
const itemHandle = (id) => logger.info(id);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<button @click=""></button>
|
||||
@ -13,7 +25,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<p>当前版本: {{ version }}
|
||||
<button id="wh-update-btn">更新</button>
|
||||
<button @click="">更新</button>
|
||||
</p>
|
||||
</div>
|
||||
<div><p>最新版本: <span id="wh-latest-version"></span></p></div>
|
||||
@ -23,25 +35,65 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import MenuItem from "../ts/interface/MenuItem"
|
||||
import Global from "../ts/class/Global";
|
||||
import Log from "../ts/class/Log";
|
||||
import { defineComponent } from "vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "Hello",
|
||||
data() {
|
||||
return {
|
||||
version: Global.getInstance().version,
|
||||
menuItemList: <MenuItem[]>[],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
itemHandle(id: string) {
|
||||
Log.info(id);
|
||||
}
|
||||
}
|
||||
})
|
||||
// import "reflect-metadata";
|
||||
// import Global from "../ts/class/Global";
|
||||
// import { defineComponent, inject } from "vue";
|
||||
// import Logger from "../ts/class/Logger";
|
||||
// import MenuItem, { menuItemList } from "../ts/interface/MenuItem";
|
||||
// import { global, logger } from "../ts/class/IconHelper";
|
||||
// import { Component, Inject, Vue } from "vue-facing-decorator";
|
||||
//
|
||||
// // export default defineComponent({
|
||||
// // export default {
|
||||
// // // inject: ['_logger', '_global', '_menuItemList'],
|
||||
// // inject: {
|
||||
// // // _logger: {
|
||||
// // // from: logger,
|
||||
// // // default: {},
|
||||
// // // },
|
||||
// // // global: {
|
||||
// // // from: global,
|
||||
// // // },
|
||||
// // _menuItemList: {
|
||||
// // from: menuItemList,
|
||||
// // }
|
||||
// // },
|
||||
// // name: "FloatMenu",
|
||||
// // setup(props) {
|
||||
// // },
|
||||
// // data() {
|
||||
// // return {
|
||||
// // // @ts-ignore
|
||||
// // // logger: this._logger,
|
||||
// // // global: this._global as unknown as Global,
|
||||
// // // menuItemList: this.menuItemList,
|
||||
// // menuItemList: this._menuItemList,
|
||||
// // // version: this.inject.global.version,
|
||||
// // }
|
||||
// // },
|
||||
// // methods: {
|
||||
// // itemHandle(id: string) {
|
||||
// // // this.logger.info(id);
|
||||
// // }
|
||||
// // },
|
||||
// // mounted() {
|
||||
// // // @ts-ignore
|
||||
// // console.warn('123123123', this.menuItemList)
|
||||
// // console.warn('123123123', this._menuItemList)
|
||||
// // }
|
||||
// // }
|
||||
// @Component({})
|
||||
// export default class A extends Vue{
|
||||
// @Inject
|
||||
// readonly logger!:Logger;
|
||||
// @Inject
|
||||
// readonly menuItemList!:MenuItem[];
|
||||
// @Inject
|
||||
// readonly global!:Global;
|
||||
//
|
||||
// version = this.global.version;
|
||||
// }
|
||||
export default {};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user