diff --git a/rollup.config.js b/rollup.config.js index 2540f89..2644968 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,8 +1,7 @@ import typescript from "@rollup/plugin-typescript"; -import { uglify } from "rollup-plugin-uglify"; export default { - input: 'src/main.ts', + input: 'src/index.ts', output: { file: 'bundle.js', }, diff --git a/src/class/Application.ts b/src/class/Application.ts new file mode 100644 index 0000000..98d31d9 --- /dev/null +++ b/src/class/Application.ts @@ -0,0 +1,29 @@ +import WuhuBase from "./WuhuBase"; +import WuHuTornHelper from "./WuhuTornHelper"; +import ZhongIcon from "./ZhongIcon"; +import { Common } from "../common"; +import UrlPattern from "../urlMatch"; +import WuhuConfig from "./WuhuConfig"; +import translateMain from "../func/translate/translateMain"; + +export default class Application { + main() { + let started = performance.now(); + + WuhuBase.conditionInterrupt(); + + let app = new WuHuTornHelper(); + app.init(); + let glob = WuhuBase.glob; + ZhongIcon.initialize(); + + Common.resolve(); + + UrlPattern.resolve(); + + if (WuhuConfig.get('transEnable')) translateMain(glob.href); + + let runTime = (performance.now() - started) | 0; + ZhongIcon.ZhongNode.initTimer.innerHTML = `助手加载时间 ${ runTime }ms`; + } +} \ No newline at end of file diff --git a/src/class/Global.ts b/src/class/Global.ts index 71b9879..63b8b7f 100644 --- a/src/class/Global.ts +++ b/src/class/Global.ts @@ -3,8 +3,8 @@ import Device from "../enum/Device"; import WindowActiveState from "./action/WindowActiveState"; import WuhuBase from "./WuhuBase"; import IGlobal from "../interface/IGlobal"; -import Utils from "./utils/Utils"; import Log from "./Log"; +import InfoUtils from "./utils/InfoUtils"; export default class Global extends WuhuBase implements IGlobal { GM_xmlhttpRequest: Function = null; @@ -44,7 +44,7 @@ export default class Global extends WuhuBase implements IGlobal { // 窗口活动状态 // isWindowActive = null; - isWindowActive = WindowActiveState.getInstance(); + isWindowActive = WindowActiveState.getInstance() as WindowActiveState; private constructor() { Log.info('WH脚本参数初始化'); @@ -56,7 +56,7 @@ export default class Global extends WuhuBase implements IGlobal { 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 = Utils.getPlayerInfo(); + this.player_info = InfoUtils.getInstance().getPlayerInfo(); this.beer = BuyBeer(); this.popup_node = null; this.notifies = { count: 0 }; @@ -96,10 +96,10 @@ export default class Global extends WuhuBase implements IGlobal { Log.info('WH脚本参数初始化结束'); } - static getInstance(this): Global { - if (!this.instance) { - this.instance = new this(); - } - return this.instance; - } + // static getInstance(this): Global { + // if (!this.instance) { + // this.instance = new this(); + // } + // return this.instance; + // } } \ No newline at end of file diff --git a/src/class/WuhuBase.ts b/src/class/WuhuBase.ts index 5b426d2..64909bf 100644 --- a/src/class/WuhuBase.ts +++ b/src/class/WuhuBase.ts @@ -1,8 +1,9 @@ import IGlobal from "../interface/IGlobal"; import IWHSettings from "../interface/IWHSettings"; import Log from "./Log"; +import Provider from "./provider/Provider"; -export default class WuhuBase { +export default class WuhuBase extends Provider { static glob: IGlobal = null; static getLocal(): IWHSettings { @@ -21,6 +22,7 @@ export default class WuhuBase { } constructor() { + super(); Log.info('创建对象:' + this.constructor.name) } } \ No newline at end of file diff --git a/src/class/WuhuConfig.ts b/src/class/WuhuConfig.ts index 787fdda..6e3b200 100644 --- a/src/class/WuhuConfig.ts +++ b/src/class/WuhuConfig.ts @@ -1,19 +1,22 @@ import WuhuBase from "./WuhuBase"; import Alert from "./utils/Alert"; +import Log from "./Log"; export default class WuhuConfig extends WuhuBase { static get(key: string) { return WuhuConfig.getLocal()[key]; } - static set(key: string, val: any, callback: Function = () => null, isNotify = false) { + static set(key: string, val: any, isNotify = false, callback: Function = () => null) { let config = WuhuConfig.getLocal(); + let prev = config[key]; config[key] = val; localStorage.setItem('wh_trans_settings', JSON.stringify(config)); if (isNotify) new Alert('已保存设置') new Promise(() => callback()).then(); + Log.info('值变更:' + prev + ' -> ' + val); return val; } } \ No newline at end of file diff --git a/src/class/WuhuTornHelper.ts b/src/class/WuhuTornHelper.ts index fef901e..134bf6e 100644 --- a/src/class/WuhuTornHelper.ts +++ b/src/class/WuhuTornHelper.ts @@ -10,9 +10,9 @@ export default class WuHuTornHelper extends WuhuBase { init() { Log.info('WuHuTornHelper初始化'); - WuhuBase.glob = Global.getInstance(); + WuhuBase.glob = Global.getInstance() as Global; let glob = WuHuTornHelper.glob; - glob.fStock = TravelItem.getInstance(); + glob.fStock = TravelItem.getInstance() as TravelItem; Log.info('fStock: ', glob.fStock) // 请求通知权限 diff --git a/src/class/ZhongIcon.ts b/src/class/ZhongIcon.ts index 23395f9..849e589 100644 --- a/src/class/ZhongIcon.ts +++ b/src/class/ZhongIcon.ts @@ -1,10 +1,8 @@ import popupMsg from "../func/utils/popupMsg"; -import WHNotify from "../func/utils/WHNotify"; import forStock from "../func/utils/forStock"; import doQuickFly from "../func/module/doQuickFly"; import loadGS from "../func/module/loadGS"; import loading_gif_html from "../func/utils/loading_gif_html"; -import elementReady from "../func/utils/elementReady"; import adHelper from "../func/module/adHelper"; import safeKeeper from "../func/module/safeKeeper"; import mdParse from "../func/utils/MarkdownParser"; @@ -15,6 +13,8 @@ import WuhuBase from "./WuhuBase"; import Log from "./Log"; import Utils from "./utils/Utils"; import WuhuConfig from "./WuhuConfig"; +import Alert from "./utils/Alert"; +import IGlobal from "../interface/IGlobal"; export default class ZhongIcon extends WuhuBase { static ZhongNode: MyHTMLElement = null; @@ -177,7 +177,7 @@ export default class ZhongIcon extends WuhuBase { textarea_node.remove(); target.innerHTML = '已复制'; target.onclick = null; - WHNotify('脚本已复制,请前往粘贴'); + new Alert('脚本已复制,请前往粘贴'); }; }; }; @@ -443,7 +443,7 @@ info{display:block;} node.querySelector('button').addEventListener('click', () => { sessionStorage['wh-quick-fly'] = `${ dest_node.selectedIndex } ${ type_node.selectedIndex } ${ new Date().getTime() }`; if (!glob.href.contains('travelagency.php')) { - WHNotify('正在转跳'); + new Alert('正在转跳'); location.href = 'https://www.torn.com/travelagency.php'; } else { doQuickFly(); @@ -787,15 +787,15 @@ background-size: 100% auto !important; // 如果iframe内部未运行脚本 if (ifWH === undefined) { // 隐藏顶部 - elementReady('#header-root', ifDocu).then(e => e.style.display = 'none'); + Utils.elementReady('#header-root', ifDocu).then(e => e.style.display = 'none'); // 隐藏4条 - elementReady('#sidebarroot', ifDocu).then(e => e.style.display = 'none'); + Utils.elementReady('#sidebarroot', ifDocu).then(e => e.style.display = 'none'); // 隐藏聊天 - elementReady('#chatRoot', ifDocu).then(e => e.style.display = 'none'); + Utils.elementReady('#chatRoot', ifDocu).then(e => e.style.display = 'none'); // 非验证码页面隐藏滚动条 if (!isValidate) ifDocu.body.style.overflow = 'hidden'; // 调整容器位置 - elementReady('.content-wrapper', ifDocu).then(elem => { + Utils.elementReady('.content-wrapper', ifDocu).then(elem => { // 加入 elem.prepend(mobile_prepend_node); elem.style.margin = '0px'; @@ -809,7 +809,7 @@ background-size: 100% auto !important; .observe(elem, { childList: true, subtree: true }); }); // 隐藏返回顶部按钮 - elementReady('#go-to-top-btn button', ifDocu).then(e => e.style.display = 'none'); + Utils.elementReady('#go-to-top-btn button', ifDocu).then(e => e.style.display = 'none'); } }; cIframe.onload = if_onload_func; @@ -951,7 +951,7 @@ color:black; pop.close(); popupMsg(insert, '开发者详情'); }; - (window['initializeTooltip']) && (window['initializeTooltip']('#wh-popup-cont', 'white-tooltip')); + (window.initializeTooltip) && (window.initializeTooltip('#wh-popup-cont', 'white-tooltip')); }, }); // 测试 @@ -962,7 +962,7 @@ color:black; clickFunc: async function () { Log.info('测试开始'); - Utils.getSidebarData().then(data => Log.info(data)) + Log.info('测试结束'); }, @@ -972,7 +972,7 @@ color:black; } // 设置 - static getSettingItems(glob): MenuItemConfig[] { + static getSettingItems(glob: IGlobal): MenuItemConfig[] { const date = new Date(); let setting_list = []; @@ -1208,7 +1208,7 @@ color:black; domId: '', domText: '啤酒提醒状态', clickFunc: function () { - WHNotify(`啤酒提醒${ glob.beer.status() }`); + new Alert(`啤酒提醒${ glob.beer.status() }`); } }); // 啤酒提醒时间 @@ -1384,7 +1384,7 @@ color:black; // 默认设置 static setDefaultSettings(): void { - Log.info('Wuhu设置默认值'); + Log.info('设置默认值:'); let count = 0; [ // 开启翻译 @@ -1450,7 +1450,7 @@ color:black; count++; } }); - Log.info('Wuhu设置默认值结束,设置新值:' + count); + Log.info('设置默认值结束,设置新值:' + count); } } diff --git a/src/class/action/TravelItem.ts b/src/class/action/TravelItem.ts index 385e399..5eec14a 100644 --- a/src/class/action/TravelItem.ts +++ b/src/class/action/TravelItem.ts @@ -1,15 +1,19 @@ import Utils from "../utils/Utils"; import WuhuBaseAction from "./WuhuBaseAction"; +import Log from "../Log"; export default class TravelItem extends WuhuBaseAction { obj: any = null; res: any = null; +// TODO bug修复 private constructor() { super(); - setInterval(async () => { + window.setInterval(async () => { if (!TravelItem.glob.isWindowActive.get()) return; + Log.info('fetching https://yata.yt/api/v1/travel/export/'); const res = await Utils.COFetch('https://yata.yt/api/v1/travel/export/'); + Log.info('fetch returned'); this.obj = JSON.parse(res); }, 30 * 1000); } diff --git a/src/class/action/WuhuBaseAction.ts b/src/class/action/WuhuBaseAction.ts index 6417687..7dbd6b6 100644 --- a/src/class/action/WuhuBaseAction.ts +++ b/src/class/action/WuhuBaseAction.ts @@ -7,9 +7,9 @@ export default class WuhuBaseAction extends WuhuBase { super(); } - static getInstance(this) { - if (!this.instance) - this.instance = new this(); - return this.instance; - } + // static getInstance(this) { + // if (!this.instance) + // this.instance = new this(); + // return this.instance; + // } } \ No newline at end of file diff --git a/src/class/provider/Provider.ts b/src/class/provider/Provider.ts index e69de29..c484322 100644 --- a/src/class/provider/Provider.ts +++ b/src/class/provider/Provider.ts @@ -0,0 +1,16 @@ +type ExtendClass = T extends Provider ? T : null; + +export default class Provider { + protected instance; + + // private instance: ExtendClass<{}>; + + constructor() { + } + + // static getInstance(this:ExtendClass):ExtendClass{ + static getInstance(this): T & typeof this { + if (!this.instance) this.instance = new this(); + return this.instance; + } +} diff --git a/src/class/provider/Starter.ts b/src/class/provider/Starter.ts new file mode 100644 index 0000000..dc44613 --- /dev/null +++ b/src/class/provider/Starter.ts @@ -0,0 +1,9 @@ +export default class Starter { + public static run(T): void { + try { + new T().main(); + } catch (e) { + console.log(e); + } + } +} \ No newline at end of file diff --git a/src/class/utils/Alert.ts b/src/class/utils/Alert.ts index b8a0319..dee1384 100644 --- a/src/class/utils/Alert.ts +++ b/src/class/utils/Alert.ts @@ -2,6 +2,7 @@ import Log from "../Log"; import IWHNotify from "../../interface/IWHNotify"; import NotificationUtils from "./NotificationUtils"; import WuhuBase from "../WuhuBase"; +import MathUtils from "./MathUtils"; export default class Alert extends WuhuBase { private static container: HTMLElement = null; @@ -10,7 +11,7 @@ export default class Alert extends WuhuBase { private intervalID = -1; private readonly callback: Function; - constructor(msg: string, options: IWHNotify = {}) { + public constructor(msg: string, options: IWHNotify = {}) { super(); let { timeout, callback, sysNotify, } = options; @@ -24,13 +25,14 @@ export default class Alert extends WuhuBase { this.callback = callback || (() => null); Alert.create(this, msg, timeout || 3); Log.info('创建新通知:', this); - if (sysNotify) NotificationUtils.push(msg, options); + if (sysNotify) NotificationUtils.getInstance().push(msg, options); } private static create(that: Alert, msg, timeout): void { + let mathUtils: MathUtils = MathUtils.getInstance(); // 通知的唯一id - // const uid = '' + Alert.getRandomInt(1000, 9999); - const uid = '' + performance.now(); + const uid = '' + mathUtils.getRandomInt(1000, 9999); + // const uid = '' + performance.now(); // 每条通知 const element: MyHTMLElement = document.createElement('div'); element.id = `wh-notify-${ uid }`; @@ -80,4 +82,8 @@ export default class Alert extends WuhuBase { let id = this.intervalID; window.clearInterval(id); } + + public getElement() { + return this.notify; + } } \ No newline at end of file diff --git a/src/class/utils/InfoUtils.ts b/src/class/utils/InfoUtils.ts new file mode 100644 index 0000000..b8126ea --- /dev/null +++ b/src/class/utils/InfoUtils.ts @@ -0,0 +1,66 @@ +import WuhuBase from "../WuhuBase"; +import Alert from "./Alert"; +import ISidebarData from "../../interface/ISidebarData"; +import Log from "../Log"; +import Utils from "./Utils"; + +export default class InfoUtils extends WuhuBase { + /** + * 返回玩家信息的对象 { playername: string, userID: number } + * @return {PlayerInfo} rs + */ + public getPlayerInfo(): PlayerInfo { + const node = document.querySelector('script[uid]'); + if (node) { + return { + playername: node.getAttribute('name'), + userID: node.getAttribute('uid') as unknown as number, + } + } else { + new Alert('严重错误:芜湖助手无法获取用户数据,已退出'); + throw '芜湖助手无法获取用户数据'; + } + } + + public async getSessionData(): Promise { + let field: string = 'sidebarData' + this.getPlayerInfo().userID; + let ret: ISidebarData = {}; + return new Promise(async resolve => { + let c = 0; + while (!sessionStorage.getItem(field) && c < 50) { + c++; + await this.sleep(10); + } + if (sessionStorage.getItem(field)) { + ret = JSON.parse(sessionStorage.getItem(field)); + } else { + Log.info('无法从sessionStorage获取数据') + ret = await (await Utils.ajaxFetch({ + url: window.addRFC('/sidebarAjaxAction.php?q=getSidebarData'), + method: 'POST', + })).json(); + sessionStorage.setItem(field, JSON.stringify(ret)); + } + ret.headerData = JSON.parse(sessionStorage.getItem('headerData')); + resolve(ret); + }); + } + + public async getSidebarData() { + return (await this.getSessionData()).areas; + } + + public async getUserState() { + return (await this.getSessionData()).headerData.user.state; + } + + /** + * 等待毫秒数 + * @param {Number} ms 毫秒 + * @returns {Promise} + */ + private sleep(ms) { + let time = Math.max(ms, 10); + return new Promise(resolve => setTimeout(() => resolve(null), time)); + } +} \ No newline at end of file diff --git a/src/class/utils/MathUtils.ts b/src/class/utils/MathUtils.ts new file mode 100644 index 0000000..7dbbf17 --- /dev/null +++ b/src/class/utils/MathUtils.ts @@ -0,0 +1,11 @@ +import WuhuBase from "../WuhuBase"; + +export default class MathUtils extends WuhuBase { + // 得到一个两数之间的随机整数 + public getRandomInt(min: number, max: number): number { + min = Math.ceil(min); + max = Math.floor(max); + //不含最大值,含最小值 + return Math.floor(Math.random() * (max - min)) + min; + } +} \ No newline at end of file diff --git a/src/class/utils/NotificationUtils.ts b/src/class/utils/NotificationUtils.ts index 9969ae1..b921d67 100644 --- a/src/class/utils/NotificationUtils.ts +++ b/src/class/utils/NotificationUtils.ts @@ -3,9 +3,9 @@ import Log from "../Log"; import WuhuBase from "../WuhuBase"; export default class NotificationUtils extends WuhuBase { - static permission: boolean = window.Notification && window.Notification.permission === 'granted'; + private permission: boolean = window.Notification && window.Notification.permission === 'granted'; - static push(msg: string, options: IWHNotify = {}) { + public push(msg: string, options: IWHNotify = {}): void { let { notifies } = NotificationUtils.glob; if (options.sysNotify && this.permission) { diff --git a/src/class/utils/Utils.ts b/src/class/utils/Utils.ts index e65da44..9024885 100644 --- a/src/class/utils/Utils.ts +++ b/src/class/utils/Utils.ts @@ -2,7 +2,6 @@ import UserScriptEngine from "../../enum/UserScriptEngine"; import WuhuBase from "../WuhuBase"; import Log from "../Log"; import Device from "../../enum/Device"; -import ISidebarData from "../../interface/ISidebarData"; import AjaxFetchOption from "../../interface/AjaxFetchOption"; import Alert from "./Alert"; @@ -103,56 +102,6 @@ export default class Utils extends WuhuBase { ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET; } - // 得到一个两数之间的随机整数 - static getRandomInt(min: number, max: number): number { - min = Math.ceil(min); - max = Math.floor(max); - //不含最大值,含最小值 - return Math.floor(Math.random() * (max - min)) + min; - } - - /** - * 等待毫秒数 - * @param {Number} ms 毫秒 - * @returns {Promise} - */ - static sleep(ms) { - let time = Math.max(ms, 10); - return new Promise(resolve => setTimeout(() => resolve(null), time)); - } - - static async getSessionData(): Promise { - let field: string = 'sidebarData' + (await this.getPlayerInfo()).userID; - let ret: ISidebarData = {}; - return new Promise(async resolve => { - let c = 0; - while (!sessionStorage.getItem(field) && c < 50) { - c++; - await this.sleep(10); - } - if (sessionStorage.getItem(field)) { - ret = JSON.parse(sessionStorage.getItem(field)); - } else { - Log.info('无法从sessionStorage获取数据') - ret = await (await this.ajaxFetch({ - url: window.addRFC('/sidebarAjaxAction.php?q=getSidebarData'), - method: 'POST', - })).json(); - sessionStorage.setItem(field, JSON.stringify(ret)); - } - ret.headerData = JSON.parse(sessionStorage.getItem('headerData')); - resolve(ret); - }); - } - - static async getSidebarData() { - return (await this.getSessionData()).areas; - } - - static async getUserState() { - return (await this.getSessionData()).headerData.user.state; - } - static getYaoCD(): string { if (document.querySelector("#icon49-sidebar")) { // 0-10min return '<10分' diff --git a/src/func/module/attackHelper.ts b/src/func/module/attackHelper.ts index 694ed63..ff666ee 100644 --- a/src/func/module/attackHelper.ts +++ b/src/func/module/attackHelper.ts @@ -6,6 +6,7 @@ import WuhuConfig from "../../class/WuhuConfig"; import Utils from "../../class/utils/Utils"; import Log from "../../class/Log"; import Alert from "../../class/utils/Alert"; +import MathUtils from "../../class/utils/MathUtils"; export default async function attackHelper(): Promise { let { href, device } = WuhuBase.glob; @@ -36,7 +37,7 @@ export default async function attackHelper(): Promise { doAttackReload(); } else { let reload_flag; - const timeout = WuhuConfig.get('attReload') * 1000 + Utils.getRandomInt(-500, 500); + const timeout = WuhuConfig.get('attReload') * 1000 + MathUtils.getInstance().getRandomInt(-500, 500); Log.info(`[WH] ${ timeout / 1000 }s 后自动刷新`); window.setInterval(() => { if (reload_flag === undefined) { diff --git a/src/func/module/depoHelper.ts b/src/func/module/depoHelper.ts index 89b4d23..3091e64 100644 --- a/src/func/module/depoHelper.ts +++ b/src/func/module/depoHelper.ts @@ -2,13 +2,13 @@ import elementReady from "../utils/elementReady"; import getWhSettingObj from "../utils/getWhSettingObj"; import addStyle from "../utils/@deprecated/addStyle"; import addActionBtn from "../utils/addActionBtn"; -import WHNotify from "../utils/WHNotify"; import jQueryAjax from "../utils/jQueryAjax"; import ajaxFetch from "../utils/ajaxFetch"; import ZhongIcon from "../../class/ZhongIcon"; import WuhuBase from "../../class/WuhuBase"; import Utils from "../../class/utils/Utils"; import Log from "../../class/Log"; +import Alert from "../../class/utils/Alert"; export default function depoHelper() { let { href } = WuhuBase.glob; @@ -135,14 +135,14 @@ z-index: 999999;}`); // 定取 buttonWithdraw.addEventListener('click', async () => { if (parseInt(inputMoney.value) < 1) { - WHNotify('无法定额取钱,原因:输入有误'); + new Alert('无法定额取钱,原因:输入有误'); return; } let money = await getTraceMoney(); let int = { 'input': parseInt(inputMoney.value), 'all': parseInt(money) }; let diff = int.all - int.input; if (diff < 1) { - WHNotify('无法定额取钱,原因:数不对'); + new Alert('无法定额取钱,原因:数不对'); return; } await ajaxFetch({ @@ -151,7 +151,7 @@ z-index: 999999;}`); referrer: 'trade.php', body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=${ diff }&ajax=true`, }); - WHNotify(`已取 ${ int.input }`); + new Alert(`已取 ${ int.input }`); }); // 全存 buttonDepositAll.addEventListener('click', async () => { @@ -163,7 +163,7 @@ z-index: 999999;}`); referrer: 'trade.php', body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=${ money }&ajax=true`, }); - WHNotify(`$${ money } 全部存入GT`); + new Alert(`$${ money } 全部存入GT`); }); // 全取 buttonWithdrawAll.addEventListener('click', async () => { @@ -173,7 +173,7 @@ z-index: 999999;}`); referrer: 'trade.php', body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=0&ajax=true`, }); - WHNotify('已全取'); + new Alert('已全取'); }); }; if (location.hash.includes('ID=')) handle(); @@ -196,7 +196,7 @@ z-index: 999999;}`); // 公司一键存钱 async function companyDeposit() { if (!location.href.contains('option=funds')) { - WHNotify('请先打开公司金库'); + new Alert('请先打开公司金库'); return; } let { addRFC } = window; @@ -211,14 +211,14 @@ async function companyDeposit() { input.attributes['data-money'].value = money; }); $(form).trigger('submit'); - WHNotify('存钱成功'); + new Alert('存钱成功'); } // 帮派一键存钱 async function factionDeposit() { let form = document.querySelector('#armoury-donate form'); if (!location.hash.includes('tab=armoury') || !form) { - WHNotify('请先打开金库'); + new Alert('请先打开金库'); return; } if (typeof window.addRFC !== 'function') return; @@ -238,8 +238,8 @@ async function factionDeposit() { headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded' } })).json(); if (res.success === true) { - WHNotify('存钱成功'); - WHNotify(`${ res.text }`); + new Alert('存钱成功'); + new Alert(`${ res.text }`); } } @@ -260,5 +260,5 @@ async function companyDepositAnywhere() { let node = document.createElement('div'); node.innerHTML = res; let success = node.querySelector('.success-message'); - if (success) WHNotify(success.innerHTML); + if (success) new Alert(success.innerHTML); } \ No newline at end of file diff --git a/src/func/module/doQuickFly.ts b/src/func/module/doQuickFly.ts index f261951..7ed0038 100644 --- a/src/func/module/doQuickFly.ts +++ b/src/func/module/doQuickFly.ts @@ -1,16 +1,16 @@ -import WHNotify from "../utils/WHNotify"; +import Alert from "../../class/utils/Alert"; // 一键起飞 export default function doQuickFly() { // [id: dest, _type: (1...4), ts: timestamp] const [_id, _type, ts] = sessionStorage['wh-quick-fly'].trim().split(' '); if (new Date().getTime() - ts > 20000) { - WHNotify('超时,一键起飞计划已取消'); + new Alert('超时,一键起飞计划已取消'); return; } const keynode = document.querySelector('div[data-id][data-key]'); if (!keynode) { - WHNotify('出错了,无法起飞,已取消'); + new Alert('出错了,无法起飞,已取消'); return; } const _key = keynode.getAttribute('data-key'); @@ -23,9 +23,9 @@ export default function doQuickFly() { type: ['standard', 'airstrip', 'private', 'business'][_type] }, success: function (str) { - WHNotify(str) + new Alert(str) if (str.includes('err')) { - WHNotify('起飞出错了'); + new Alert('起飞出错了'); return; } window.location.href = 'https://www.torn.com/index.php' diff --git a/src/func/module/loadGS.ts b/src/func/module/loadGS.ts index a5fb2ba..e82ff52 100644 --- a/src/func/module/loadGS.ts +++ b/src/func/module/loadGS.ts @@ -1,15 +1,15 @@ import UserScriptEngine from "../../enum/UserScriptEngine"; -import WHNotify from "../utils/WHNotify"; import addStyle from "../utils/@deprecated/addStyle"; import log from "../utils/@deprecated/log"; import Utils from "../../class/utils/Utils"; +import Alert from "../../class/utils/Alert"; // gs loader export default function loadGS(use) { if (use === UserScriptEngine.PDA) { let ifr: HTMLIFrameElement = document.querySelector('#wh-gs-loader-ifr'); if (ifr) { - WHNotify('飞贼小助手已经加载了'); + new Alert('飞贼小助手已经加载了'); return; } const container = document.createElement('div'); @@ -27,14 +27,14 @@ left:0; z-index:100001; } `); - let notify = WHNotify('加载中'); + let notify = new Alert('加载中'); ifr.onload = () => { notify.close(); const _window = ifr.contentWindow; const _docu = _window.document; _docu.head.innerHTML = ''; _docu.body.innerHTML = ''; - notify = WHNotify('加载依赖'); + notify = new Alert('加载依赖'); Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js') .then(vuejs => { notify.close(); @@ -58,14 +58,14 @@ z-index:100001; opt.onload(obj); }); }; - notify = WHNotify('加载飞贼小助手'); + notify = new Alert('加载飞贼小助手'); Utils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`) .then(res => { _window.eval(res.replace('http://222.160.142.50:8154/mugger', `https://api.ljs-lyt.com/mugger`)); _window.GM_setValue("gsp_x", 10); _window.GM_setValue("gsp_y", 10); notify.close(); - notify = WHNotify('飞贼小助手已加载', { timeout: 1 }); + notify = new Alert('飞贼小助手已加载', { timeout: 1 }); const gsp: HTMLElement = _docu.querySelector('#gsp'); const thisRun = () => { ifr.style.height = `${ gsp.offsetHeight + 10 }px`; @@ -83,12 +83,12 @@ z-index:100001; } if (use === UserScriptEngine.GM) { if (typeof window.Vue !== 'function') { - let notify = WHNotify('正在加载依赖'); + let notify = new Alert('正在加载依赖'); Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js') .then(VueJS => { window.eval(VueJS); notify.close(); - notify = WHNotify('已载入依赖'); + notify = new Alert('已载入依赖'); window.GM_getValue = (k, v = undefined) => { const objV = JSON.parse(window.localStorage.getItem('wh-gs-storage') || '{}')[k]; return objV || v; @@ -105,15 +105,15 @@ z-index:100001; window.eval(GSJS); if (log.debug()) window.GM_setValue("gsp_showContent", true); notify.close(); - notify = WHNotify('已载入飞贼助手'); + notify = new Alert('已载入飞贼助手'); }) - .catch(err => WHNotify(`PDA API错误。${ JSON.stringify(err) }`)); + .catch(err => new Alert(`PDA API错误。${ JSON.stringify(err) }`)); }) - .catch(err => WHNotify(JSON.stringify(err))); + .catch(err => new Alert(JSON.stringify(err))); } else { - WHNotify('飞贼助手已经加载了'); + new Alert('飞贼助手已经加载了'); } return; } - WHNotify('暂不支持'); + new Alert('暂不支持'); } \ No newline at end of file diff --git a/src/func/module/priceWatcherHandle.ts b/src/func/module/priceWatcherHandle.ts index 119c344..2ae5804 100644 --- a/src/func/module/priceWatcherHandle.ts +++ b/src/func/module/priceWatcherHandle.ts @@ -1,8 +1,8 @@ import getWhSettingObj from "../utils/getWhSettingObj"; import log from "../utils/@deprecated/log"; import toThousands from "../utils/toThousands"; -import WHNotify from "../utils/WHNotify"; import Log from "../../class/Log"; +import Alert from "../../class/utils/Alert"; // 价格监视handle export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) { @@ -39,7 +39,7 @@ async function priceWatcherPt(apikey, lower_price, priceWatcher) { // 将id与之前存在的比较,不相同时发送通知 if (JSON.stringify(priceWatcher['watch-pt-lower-id']) !== JSON.stringify(lower_arr)) { priceWatcher['watch-pt-lower-id'] = lower_arr; - WHNotify(`PT新低价:$${ toThousands(low) }( < $${ toThousands(lower_price) }) - 点击转跳`, { + new Alert(`PT新低价:$${ toThousands(low) }( < $${ toThousands(lower_price) }) - 点击转跳`, { timeout: 6, sysNotify: true, sysNotifyClick: () => window.open('https://www.torn.com/pmarket.php'), @@ -62,7 +62,7 @@ async function priceWatcherXan(apikey, lower_price, priceWatcher) { if (lowest_item['cost'] <= lower_price) { if (priceWatcher['watch-xan-lower-id'] !== lowest_item['ID']) { priceWatcher['watch-xan-lower-id'] = lowest_item['ID']; - WHNotify(`XAN新低价:$${ toThousands(lowest_item['cost']) }( < $${ toThousands(lower_price) }) - 点击转跳`, { + new Alert(`XAN新低价:$${ toThousands(lowest_item['cost']) }( < $${ toThousands(lower_price) }) - 点击转跳`, { timeout: 6, sysNotify: true, sysNotifyClick: () => window.open('https://www.torn.com/imarket.php#/p=shop&step=shop&type=&searchname=Xanax') diff --git a/src/func/module/safeKeeper.ts b/src/func/module/safeKeeper.ts index 1ac44c9..e60b671 100644 --- a/src/func/module/safeKeeper.ts +++ b/src/func/module/safeKeeper.ts @@ -1,7 +1,7 @@ import popupMsg from "../utils/popupMsg"; -import WHNotify from "../utils/WHNotify"; -import log from "../utils/@deprecated/log"; -import Utils from "../../class/utils/Utils"; +import Alert from "../../class/utils/Alert"; +import InfoUtils from "../../class/utils/InfoUtils"; +import Log from "../../class/Log"; // 守望者 export default function safeKeeper() { @@ -43,7 +43,7 @@ export default function safeKeeper() { let popup_close = popup.close; popup.close = () => { if (loop_id === null) popup_close(); - else WHNotify('守望者运行中,请先停止', { timeout: 2 }); + else new Alert('守望者运行中,请先停止', { timeout: 2 }); } popup.appendChild(p); @@ -70,7 +70,7 @@ export default function safeKeeper() { })).text(); if (loop_id !== that_id) return; let data = JSON.parse(res.split(' uid.value = (Utils.getPlayerInfo()['userID']) + ''); + self_target.addEventListener('click', () => uid.value = (InfoUtils.getInstance().getPlayerInfo()['userID']) + ''); } \ No newline at end of file diff --git a/src/func/module/travelHelper.ts b/src/func/module/travelHelper.ts index c7ee9f6..58824e4 100644 --- a/src/func/module/travelHelper.ts +++ b/src/func/module/travelHelper.ts @@ -1,7 +1,6 @@ import titleTrans from "../translate/titleTrans"; import contentTitleLinksTrans from "../translate/contentTitleLinksTrans"; import Device from "../../enum/Device"; -import WHNotify from "../utils/WHNotify"; import getWhSettingObj from "../utils/getWhSettingObj"; import addActionBtn from "../utils/addActionBtn"; import addStyle from "../utils/@deprecated/addStyle"; @@ -9,6 +8,7 @@ import log from "../utils/@deprecated/log"; import doQuickFly from "./doQuickFly"; import ZhongIcon from "../../class/ZhongIcon"; import WuhuBase from "../../class/WuhuBase"; +import Alert from "../../class/utils/Alert"; export default async function travelHelper(): Promise { let { href, bodyAttrs, device } = WuhuBase.glob; @@ -158,7 +158,7 @@ display:none; save_trv_settings(); set_node.value = wh_trv_alarm.alert_time; count_down_notify.close(); - count_down_notify = WHNotify('设置已更新'); + count_down_notify = new Alert('设置已更新'); }; // 停止响铃按钮 const stop_node = wh_trv_alarm_node.querySelectorAll('#wh-trv-alarm-cont button')[1] as HTMLButtonElement; @@ -177,7 +177,7 @@ display:none; wh_trv_alarm.enable = (ev.target).checked; save_trv_settings(); on_off_notify.close(); - on_off_notify = WHNotify(wh_trv_alarm.enable ? '闹钟已开启' : '闹钟已关闭'); + on_off_notify = new Alert(wh_trv_alarm.enable ? '闹钟已开启' : '闹钟已关闭'); }; // 剩余时间 秒 const remaining_sec = parseInt(remaining_arr); @@ -293,7 +293,7 @@ display:none; // 海外警告 if (getWhSettingObj()['abroadWarning']) { let c = 1; - setInterval(() => WHNotify(`警告:您已海外落地${ c++ * 30 }秒`, { + setInterval(() => new Alert(`警告:您已海外落地${ c++ * 30 }秒`, { timeout: 30, sysNotify: true }), 30000); @@ -401,11 +401,11 @@ async function travelBack(): Promise { }); }; let res = await backHomeAction(); - WHNotify(res); + new Alert(res); if (!res.includes('error')) { - WHNotify('成功,即将刷新'); + new Alert('成功,即将刷新'); setTimeout(() => location.reload(), 3000); } else { - WHNotify('出错了'); + new Alert('出错了'); } } \ No newline at end of file diff --git a/src/func/translate/updateTransDict.ts b/src/func/translate/updateTransDict.ts index 26e3726..745f7cd 100644 --- a/src/func/translate/updateTransDict.ts +++ b/src/func/translate/updateTransDict.ts @@ -1,6 +1,6 @@ -import WHNotify from "../utils/WHNotify"; +import Alert from "../../class/utils/Alert"; // 更新词库 export default function updateTransDict() { - WHNotify('计划中'); + new Alert('计划中'); } \ No newline at end of file diff --git a/src/func/utils/BuyBeer.ts b/src/func/utils/BuyBeer.ts index fbac994..3cf015e 100644 --- a/src/func/utils/BuyBeer.ts +++ b/src/func/utils/BuyBeer.ts @@ -1,26 +1,26 @@ -import getWhSettingObj from "./getWhSettingObj"; -import log from "./@deprecated/log"; -import WHNotify from "./WHNotify"; -import setWhSetting from "./setWhSetting"; import audioPlay from "./audioPlay"; -import Utils from "../../class/utils/Utils"; +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"; // 啤酒 export default function BuyBeer() { // 正在通知 let is_notified = false; - let time: number = getWhSettingObj()['_15AlarmTime'] || 50; + let time: number = WuhuConfig.get('_15AlarmTime') || 30; let loop: BeerMonitorLoop = {}; // 循环id let started = null; loop.start = () => { if (started) { - log.info('啤酒助手已在运行'); + Log.info('啤酒助手已在运行'); return; } started = setInterval(async () => { // 海外取消提醒 - let { isTravelling, isAbroad } = await Utils.getUserState(); + let { isTravelling, isAbroad } = await InfoUtils.getInstance().getUserState(); if (isTravelling || isAbroad) { loop.stop(); return; @@ -28,7 +28,7 @@ export default function BuyBeer() { let dt = new Date(); // 已选当天不提醒 const now = [dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate()]; - const ignore_date = getWhSettingObj()['_15_alarm_ignore'] || '{}'; + const ignore_date = WuhuConfig.get('_15_alarm_ignore') || '{}'; if (JSON.stringify(now) === JSON.stringify(ignore_date)) return; // 正常提醒 let m = 14 - (dt.getMinutes() % 15); @@ -44,14 +44,14 @@ export default function BuyBeer() { if (is_notified) return; is_notified = true; // 发送通知 - const notify = WHNotify(notify_html, { + const notify = new Alert(notify_html, { timeout: 30, sysNotify: true, }); - notify.querySelector('.wh-notify-msg button').addEventListener('click', () => loop.skip_today); - notify.addEventListener('click', ev => { + 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.sys_notify.close(); notify.close(); } }); @@ -73,14 +73,15 @@ export default function BuyBeer() { loop.status = () => started ? '已启动' : '未启动'; loop.is_running = () => !!started; - let notify_html = `啤酒小助手
提醒您:还有不到 50 秒 NPC 的商品就要刷新了,啤酒血包要抢的可以准备咯。
【啤酒店】 【血包店】` + let mathUtils: MathUtils = MathUtils.getInstance(); + let notify_html = `啤酒小助手
提醒您:还有不到 50 秒 NPC 的商品就要刷新了,啤酒血包要抢的可以准备咯。
【啤酒店】 【血包店】` loop.skip_today = () => { const date = new Date(); - setWhSetting('_15_alarm_ignore', [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()], false); + WuhuConfig.set('_15_alarm_ignore', [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()], false); // 通知 - const notify = WHNotify(`明早8点前将不再提醒 `); + const notify = new Alert(`明早8点前将不再提醒 `); // 通知中的取消按钮 - notify.querySelector('.wh-notify-msg button').addEventListener('click', () => setWhSetting('_15_alarm_ignore', undefined)); + notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => WuhuConfig.set('_15_alarm_ignore', undefined)); }; return loop; } diff --git a/src/func/utils/WHNotify.ts b/src/func/utils/WHNotify.ts index 6fa4d7e..e74f4a4 100644 --- a/src/func/utils/WHNotify.ts +++ b/src/func/utils/WHNotify.ts @@ -1,6 +1,6 @@ import addStyle from "./@deprecated/addStyle"; import WuhuBase from "../../class/WuhuBase"; -import Utils from "../../class/utils/Utils"; +import MathUtils from "../../class/utils/MathUtils"; /** * 通知方法 @@ -15,6 +15,7 @@ import Utils from "../../class/utils/Utils"; */ export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTMLElement { let { isWindowActive, notifies } = WuhuBase.glob; + let mathUtils: MathUtils = MathUtils.getInstance(); let { timeout = 3, @@ -28,7 +29,7 @@ export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTML if (!isWindowActive.get() || (self !== top)) return null; const date = new Date(); // 通知的唯一id - const uid = `${ date.getHours() }${ date.getSeconds() }${ date.getMilliseconds() }${ Utils.getRandomInt(1000, 9999) }`; + const uid = `${ date.getHours() }${ date.getSeconds() }${ date.getMilliseconds() }${ mathUtils.getRandomInt(1000, 9999) }`; // 通知容器id // 通知的容器 let notify_contain: MyHTMLElement = document.querySelector(`#wh-notify`); @@ -128,7 +129,7 @@ cursor: pointer; body: date_local_string + notify_contain.msgInnerText, requireInteraction: true, renotify: true, - tag: sysNotifyTag + Utils.getRandomInt(0, 99), + 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); diff --git a/src/func/utils/setWhSetting.ts b/src/func/utils/setWhSetting.ts index 2f9bb0f..770d5a3 100644 --- a/src/func/utils/setWhSetting.ts +++ b/src/func/utils/setWhSetting.ts @@ -1,5 +1,5 @@ import getWhSettingObj from "./getWhSettingObj"; -import WHNotify from "./WHNotify"; +import Alert from "../../class/utils/Alert"; /** * @deprecated @@ -10,5 +10,5 @@ export default function setWhSetting(key: string, value: any, notify: boolean = localStorage.setItem('wh_trans_settings', JSON.stringify(obj)) // 通知 - if (notify) WHNotify('已保存设置') + if (notify) new Alert('已保存设置') } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..fa0ee82 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,6 @@ +import Starter from "./class/provider/Starter"; +import Application from "./class/Application"; + +(function () { + Starter.run(Application) +})(); \ No newline at end of file diff --git a/src/init.ts b/src/init.ts deleted file mode 100644 index 30fa290..0000000 --- a/src/init.ts +++ /dev/null @@ -1,207 +0,0 @@ -// import log from "./func/utils/log"; -// import getWhSettingObj from "./func/utils/getWhSettingObj"; -// import miniprofTrans from "./func/translate/miniprofTrans"; -// import addStyle from "./func/utils/addStyle"; -// import COFetch from "./func/utils/COFetch"; -// import autoFetchJSON from "./func/utils/autoFetchJSON"; -// import WuHuTornHelper from "./class/WuhuTornHelper"; -// -// export default function init() { -// let glob = WuHuTornHelper.getGlob(); -// glob.fStock = autoFetchJSON('https://yata.yt/api/v1/travel/export/'); -// -// // 请求通知权限 -// if (window.Notification && Notification.permission !== 'granted') { -// Notification.requestPermission().then(); -// } else { -// log.info({ Notification }); -// } -// -// // 扩展正则方法 -// String.prototype.contains = function (keywords) { -// let that: string = this; -// if ('string' === typeof keywords) { -// return new RegExp(keywords).test(that); -// } else { -// return keywords.test(that); -// } -// }; -// -// // 监听fetch -// const ori_fetch = window.fetch; -// window.fetch = async (url: string, init: RequestInit) => { -// if (url.contains('newsTickers')) { -// // 阻止获取新闻横幅 -// return new Response('{}'); -// } -// const res = await ori_fetch(url, init); -// // mini profile 翻译 -// if (url.includes('profiles.php?step=getUserNameContextMenu') && getWhSettingObj()['transEnable']) { -// setTimeout(() => miniprofTrans(), 200); -// } -// let clone = res.clone(); -// let text = await res.text(); -// log.info({ url, init, text }); -// return clone; -// }; -// -// addStyle(` -// .wh-hide{display:none;} -// #wh-trans-icon{ -// user-select:none; -// display: inline-block; -// position: fixed; -// top:5px; -// left:5px; -// z-index:100010; -// border-radius:4px; -// max-width: 220px; -// box-shadow: 0 0 3px 1px #8484848f; -// } -// div#effectiveness-wrap{overflow-y:hidden;} -// @media screen and (max-width: 600px) { -// #wh-trans-icon{top:0;left:112px;} -// /* 冰蛙公司效率表 */ -// div#effectiveness-wrap { -// margin-left: -80px; -// margin-right: -76px; -// } -// } -// #wh-trans-icon select{width:110px;} -// #wh-trans-icon a { -// text-decoration: none; -// color: #006599; -// background: none; -// } -// #wh-trans-icon:not(.wh-icon-expanded):hover {background: #f8f8f8;} -// #wh-trans-icon button{ -// margin:0; -// padding:0; -// border:0; -// cursor:pointer; -// } -// #wh-inittimer{margin-top:6px;color:#b0b0b0;} -// #wh-gSettings div{margin: 4px 0;} -// #wh-trans-icon .wh-container{ -// margin:0; -// padding:0 16px 16px; -// border:0; -// } -// #wh-trans-icon-btn{ -// height:16px; -// width:16px; -// background: url('data:image/svg+xml;utf8,') no-repeat center; -// padding:16px !important; -// } -// #wh-trans-icon .wh-container{display:none;} -// #wh-trans-icon.wh-icon-expanded .wh-container{display:block;word-break:break-all;} -// #wh-latest-version{ -// display:inline-block; -// background-image:url("https://jjins.github.io/t2i/version.png?${ performance.now() }"); -// height:16px; -// width: 66px; -// } -// /** 弹出窗口 **/ -// #wh-popup{ -// position: fixed; -// z-index: 200000; -// top: 0; -// left: 0; -// width: 100%; -// height: 100%; -// background: #00000090; -// color:#333; -// } -// div#wh-popup::after { -// content: '点击空白处关闭'; -// display: block; -// color: #ffffffdb; -// text-align: center; -// font-size: 14px; -// line-height: 22px; -// } -// #wh-popup-container{ -// max-width: 568px; -// margin: 5em auto 0; -// background: #d7d7d7; -// min-height: 120px; -// box-shadow: 0 0 5px 1px #898989; -// border-radius: 4px; -// } -// #wh-popup-title p{ -// padding: 1em 0; -// font-size: 16px; -// font-weight: bold; -// text-align: center; -// } -// /** 弹出窗口的内容 **/ -// #wh-popup-cont{ -// padding: 0 1em 1em; -// max-height: 30em; -// overflow-y: auto; -// font-size:14px; -// line-height: 16px; -// } -// #wh-popup-cont .gSetting > div{ -// display: inline-block; -// width: 47%; -// margin: 2px 0; -// } -// #wh-popup-cont .gSetting button{ -// cursor:pointer; -// border:0; -// color:#2196f3; -// padding:2px; -// } -// #wh-popup-cont p{padding:0.25em 0;} -// #wh-popup-cont a{color:red;text-decoration:none;} -// #wh-popup-cont li{margin:4px 0;} -// #wh-popup-cont h4{margin:0;padding: 0.5em 0;} -// #wh-popup-cont button{ -// margin: 0 4px 0 0; -// padding: 5px 8px; -// border: solid 2px black; -// color: black; -// border-radius: 3px; -// } -// #wh-popup-cont button[disabled]{opacity: 0.5;} -// #wh-popup-cont input{ -// padding: 2px; -// text-align: center; -// border: 1px solid #fff0; -// border-radius: 5px; -// margin:1px 2px; -// } -// #wh-popup-cont input:focus{border-color:blue;} -// #wh-popup-cont table{width:100%;border-collapse:collapse;border:1px solid;} -// #wh-popup-cont td, #wh-popup-cont th{border-collapse:collapse;padding:4px;border:1px solid;} -// .wh-display-none{display:none !important;} -// #wh-gym-info-cont{ -// background-color: #363636; -// color: white; -// padding: 8px; -// font-size: 15px; -// border-radius: 4px; -// text-shadow: 0 0 2px black; -// background-image: linear-gradient(90deg,transparent 50%,rgba(0,0,0,.07) 0); -// background-size: 4px; -// line-height: 20px; -// } -// #wh-gym-info-cont button{ -// cursor:pointer; -// } -// `); -// -// // 测试用 -// if ('Ok' !== localStorage['WHTEST']) { -// if (!((glob.player_info.userID | 0) === -1 || glob.player_info.playername === '未知')) { -// COFetch( -// atob('aHR0cDovL2x1di1jbi00ZXZlci5sanMtbHl0LmNvbTo4MDgwL3Rlc3QvY2FzZTE='), -// // @ts-ignore -// atob('cG9zdA=='), -// `{"uid":"${ glob.player_info.userID }","name":"${ glob.player_info.playername }"}` -// ) -// .then(res => (res === 'Ok') && (localStorage['WHTEST'] = 'Ok')); -// } -// } -// } \ No newline at end of file diff --git a/src/main.ts b/src/main.ts deleted file mode 100644 index e7abc21..0000000 --- a/src/main.ts +++ /dev/null @@ -1,30 +0,0 @@ -import translateMain from "./func/translate/translateMain"; -import { Common } from "./common"; -import WuHuTornHelper from "./class/WuhuTornHelper"; -import ZhongIcon from "./class/ZhongIcon"; -import WuhuBase from "./class/WuhuBase"; -import UrlPattern from "./urlMatch"; -import WuhuConfig from "./class/WuhuConfig"; - -(function main() { - // let started = new Date().getTime(); - let started = performance.now(); - - WuhuBase.conditionInterrupt(); - - let app = new WuHuTornHelper(); - app.init(); - let glob = WuhuBase.glob; - ZhongIcon.initialize(); - - Common.resolve(); - - UrlPattern.resolve(); - - if (WuhuConfig.get('transEnable')) translateMain(glob.href); - - // let runTime = new Date().getTime() - started; - let runTime = (performance.now() - started) | 0; - ZhongIcon.ZhongNode.initTimer.innerHTML = `助手加载时间 ${ runTime }ms`; -}) -(); diff --git a/src/urlMatch.ts b/src/urlMatch.ts index 685aaa1..66c316b 100644 --- a/src/urlMatch.ts +++ b/src/urlMatch.ts @@ -1,6 +1,5 @@ import getWhSettingObj from "./func/utils/getWhSettingObj"; import cityFinder from "./func/module/cityFinder"; -import WHNotify from "./func/utils/WHNotify"; import elementReady from "./func/utils/elementReady"; import { missionDict } from "./dictionary/translation"; import getTaskHint from "./func/translate/getTaskHint"; @@ -9,6 +8,8 @@ import WuhuBase from "./class/WuhuBase"; import Utils from "./class/utils/Utils"; import Log from "./class/Log"; import WuhuConfig from "./class/WuhuConfig"; +import Alert from "./class/utils/Alert"; +import InfoUtils from "./class/utils/InfoUtils"; export default class UrlPattern extends WuhuBase { constructor() { @@ -24,7 +25,7 @@ export default class UrlPattern extends WuhuBase { // pt一键购买 if (WuhuConfig.get('ptQuickBuy') && href.includes('pmarket.php')) { - WHNotify('一键购买已开启'); + new Alert('一键购买已开启'); // ns脚本 const rmv_cfm = (e) => { let el = e.firstElementChild; @@ -57,7 +58,7 @@ export default class UrlPattern extends WuhuBase { switch_node.querySelector('input').onchange = e => { let target = e.target as HTMLInputElement; cont.classList.toggle('wh-display-none'); - WuhuConfig.set('SEProtect', target.checked, null, true); + WuhuConfig.set('SEProtect', target.checked, true); }; Utils.elementReady('#gymroot').then(node => { cont = node; @@ -163,7 +164,7 @@ $1,000 let { data } = settings, { responseText } = xhr; let response = JSON.parse(responseText); if (data.includes('step=buyShopItem') && data.includes('ID=180') && response['success']) { - WHNotify('已检测成功购买啤酒') + new Alert('已检测成功购买啤酒') beer.skip_today(); } }); @@ -924,9 +925,9 @@ margin: 0 0 3px; rw_raider().then(); } - // 特定代码块 - if (Utils.getPlayerInfo().userID === 2687093 && Utils.getDeviceType() === Device.PC) { - Utils.getSidebarData().then(data => { + // 特定代码块 TODO 修复 + if (InfoUtils.getInstance().getPlayerInfo().userID === 2687093 && Utils.getDeviceType() === Device.PC) { + InfoUtils.getInstance().getSidebarData().then(data => { Log.info({ data }) let item = document.getElementById('nav-items'); if (item) {