TS重构
This commit is contained in:
parent
bb83b98a23
commit
3f1b6239ca
@ -1,8 +1,7 @@
|
|||||||
import typescript from "@rollup/plugin-typescript";
|
import typescript from "@rollup/plugin-typescript";
|
||||||
import { uglify } from "rollup-plugin-uglify";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: 'src/main.ts',
|
input: 'src/index.ts',
|
||||||
output: {
|
output: {
|
||||||
file: 'bundle.js',
|
file: 'bundle.js',
|
||||||
},
|
},
|
||||||
|
|||||||
29
src/class/Application.ts
Normal file
29
src/class/Application.ts
Normal file
@ -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`;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,8 +3,8 @@ import Device from "../enum/Device";
|
|||||||
import WindowActiveState from "./action/WindowActiveState";
|
import WindowActiveState from "./action/WindowActiveState";
|
||||||
import WuhuBase from "./WuhuBase";
|
import WuhuBase from "./WuhuBase";
|
||||||
import IGlobal from "../interface/IGlobal";
|
import IGlobal from "../interface/IGlobal";
|
||||||
import Utils from "./utils/Utils";
|
|
||||||
import Log from "./Log";
|
import Log from "./Log";
|
||||||
|
import InfoUtils from "./utils/InfoUtils";
|
||||||
|
|
||||||
export default class Global extends WuhuBase implements IGlobal {
|
export default class Global extends WuhuBase implements IGlobal {
|
||||||
GM_xmlhttpRequest: Function = null;
|
GM_xmlhttpRequest: Function = null;
|
||||||
@ -44,7 +44,7 @@ export default class Global extends WuhuBase implements IGlobal {
|
|||||||
|
|
||||||
// 窗口活动状态
|
// 窗口活动状态
|
||||||
// isWindowActive = null;
|
// isWindowActive = null;
|
||||||
isWindowActive = WindowActiveState.getInstance();
|
isWindowActive = WindowActiveState.getInstance() as WindowActiveState;
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
Log.info('WH脚本参数初始化');
|
Log.info('WH脚本参数初始化');
|
||||||
@ -56,7 +56,7 @@ export default class Global extends WuhuBase implements IGlobal {
|
|||||||
this.PDA_APIKey = '###PDA-APIKEY###';
|
this.PDA_APIKey = '###PDA-APIKEY###';
|
||||||
this.isPDA = !this.PDA_APIKey.includes('###');
|
this.isPDA = !this.PDA_APIKey.includes('###');
|
||||||
this.device = window.innerWidth >= 1000 ? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
|
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.beer = BuyBeer();
|
||||||
this.popup_node = null;
|
this.popup_node = null;
|
||||||
this.notifies = { count: 0 };
|
this.notifies = { count: 0 };
|
||||||
@ -96,10 +96,10 @@ export default class Global extends WuhuBase implements IGlobal {
|
|||||||
Log.info('WH脚本参数初始化结束');
|
Log.info('WH脚本参数初始化结束');
|
||||||
}
|
}
|
||||||
|
|
||||||
static getInstance(this): Global {
|
// static getInstance(this): Global {
|
||||||
if (!this.instance) {
|
// if (!this.instance) {
|
||||||
this.instance = new this();
|
// this.instance = new this();
|
||||||
}
|
// }
|
||||||
return this.instance;
|
// return this.instance;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
@ -1,8 +1,9 @@
|
|||||||
import IGlobal from "../interface/IGlobal";
|
import IGlobal from "../interface/IGlobal";
|
||||||
import IWHSettings from "../interface/IWHSettings";
|
import IWHSettings from "../interface/IWHSettings";
|
||||||
import Log from "./Log";
|
import Log from "./Log";
|
||||||
|
import Provider from "./provider/Provider";
|
||||||
|
|
||||||
export default class WuhuBase {
|
export default class WuhuBase extends Provider {
|
||||||
static glob: IGlobal = null;
|
static glob: IGlobal = null;
|
||||||
|
|
||||||
static getLocal(): IWHSettings {
|
static getLocal(): IWHSettings {
|
||||||
@ -21,6 +22,7 @@ export default class WuhuBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
super();
|
||||||
Log.info('创建对象:' + this.constructor.name)
|
Log.info('创建对象:' + this.constructor.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,19 +1,22 @@
|
|||||||
import WuhuBase from "./WuhuBase";
|
import WuhuBase from "./WuhuBase";
|
||||||
import Alert from "./utils/Alert";
|
import Alert from "./utils/Alert";
|
||||||
|
import Log from "./Log";
|
||||||
|
|
||||||
export default class WuhuConfig extends WuhuBase {
|
export default class WuhuConfig extends WuhuBase {
|
||||||
static get(key: string) {
|
static get(key: string) {
|
||||||
return WuhuConfig.getLocal()[key];
|
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 config = WuhuConfig.getLocal();
|
||||||
|
let prev = config[key];
|
||||||
config[key] = val;
|
config[key] = val;
|
||||||
localStorage.setItem('wh_trans_settings', JSON.stringify(config));
|
localStorage.setItem('wh_trans_settings', JSON.stringify(config));
|
||||||
|
|
||||||
if (isNotify)
|
if (isNotify)
|
||||||
new Alert('已保存设置')
|
new Alert('已保存设置')
|
||||||
new Promise(() => callback()).then();
|
new Promise(() => callback()).then();
|
||||||
|
Log.info('值变更:' + prev + ' -> ' + val);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10,9 +10,9 @@ export default class WuHuTornHelper extends WuhuBase {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
Log.info('WuHuTornHelper初始化');
|
Log.info('WuHuTornHelper初始化');
|
||||||
WuhuBase.glob = Global.getInstance();
|
WuhuBase.glob = Global.getInstance() as Global;
|
||||||
let glob = WuHuTornHelper.glob;
|
let glob = WuHuTornHelper.glob;
|
||||||
glob.fStock = TravelItem.getInstance();
|
glob.fStock = TravelItem.getInstance() as TravelItem;
|
||||||
Log.info('fStock: ', glob.fStock)
|
Log.info('fStock: ', glob.fStock)
|
||||||
|
|
||||||
// 请求通知权限
|
// 请求通知权限
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
import popupMsg from "../func/utils/popupMsg";
|
import popupMsg from "../func/utils/popupMsg";
|
||||||
import WHNotify from "../func/utils/WHNotify";
|
|
||||||
import forStock from "../func/utils/forStock";
|
import forStock from "../func/utils/forStock";
|
||||||
import doQuickFly from "../func/module/doQuickFly";
|
import doQuickFly from "../func/module/doQuickFly";
|
||||||
import loadGS from "../func/module/loadGS";
|
import loadGS from "../func/module/loadGS";
|
||||||
import loading_gif_html from "../func/utils/loading_gif_html";
|
import loading_gif_html from "../func/utils/loading_gif_html";
|
||||||
import elementReady from "../func/utils/elementReady";
|
|
||||||
import adHelper from "../func/module/adHelper";
|
import adHelper from "../func/module/adHelper";
|
||||||
import safeKeeper from "../func/module/safeKeeper";
|
import safeKeeper from "../func/module/safeKeeper";
|
||||||
import mdParse from "../func/utils/MarkdownParser";
|
import mdParse from "../func/utils/MarkdownParser";
|
||||||
@ -15,6 +13,8 @@ import WuhuBase from "./WuhuBase";
|
|||||||
import Log from "./Log";
|
import Log from "./Log";
|
||||||
import Utils from "./utils/Utils";
|
import Utils from "./utils/Utils";
|
||||||
import WuhuConfig from "./WuhuConfig";
|
import WuhuConfig from "./WuhuConfig";
|
||||||
|
import Alert from "./utils/Alert";
|
||||||
|
import IGlobal from "../interface/IGlobal";
|
||||||
|
|
||||||
export default class ZhongIcon extends WuhuBase {
|
export default class ZhongIcon extends WuhuBase {
|
||||||
static ZhongNode: MyHTMLElement = null;
|
static ZhongNode: MyHTMLElement = null;
|
||||||
@ -177,7 +177,7 @@ export default class ZhongIcon extends WuhuBase {
|
|||||||
textarea_node.remove();
|
textarea_node.remove();
|
||||||
target.innerHTML = '已复制';
|
target.innerHTML = '已复制';
|
||||||
target.onclick = null;
|
target.onclick = null;
|
||||||
WHNotify('脚本已复制,请前往粘贴');
|
new Alert('脚本已复制,请前往粘贴');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -443,7 +443,7 @@ info{display:block;}
|
|||||||
node.querySelector('button').addEventListener('click', () => {
|
node.querySelector('button').addEventListener('click', () => {
|
||||||
sessionStorage['wh-quick-fly'] = `${ dest_node.selectedIndex } ${ type_node.selectedIndex } ${ new Date().getTime() }`;
|
sessionStorage['wh-quick-fly'] = `${ dest_node.selectedIndex } ${ type_node.selectedIndex } ${ new Date().getTime() }`;
|
||||||
if (!glob.href.contains('travelagency.php')) {
|
if (!glob.href.contains('travelagency.php')) {
|
||||||
WHNotify('正在转跳');
|
new Alert('正在转跳');
|
||||||
location.href = 'https://www.torn.com/travelagency.php';
|
location.href = 'https://www.torn.com/travelagency.php';
|
||||||
} else {
|
} else {
|
||||||
doQuickFly();
|
doQuickFly();
|
||||||
@ -787,15 +787,15 @@ background-size: 100% auto !important;
|
|||||||
// 如果iframe内部未运行脚本
|
// 如果iframe内部未运行脚本
|
||||||
if (ifWH === undefined) {
|
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条
|
// 隐藏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';
|
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.prepend(mobile_prepend_node);
|
||||||
elem.style.margin = '0px';
|
elem.style.margin = '0px';
|
||||||
@ -809,7 +809,7 @@ background-size: 100% auto !important;
|
|||||||
.observe(elem, { childList: true, subtree: true });
|
.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;
|
cIframe.onload = if_onload_func;
|
||||||
@ -951,7 +951,7 @@ color:black;
|
|||||||
pop.close();
|
pop.close();
|
||||||
popupMsg(insert, '开发者详情');
|
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 () {
|
clickFunc: async function () {
|
||||||
Log.info('测试开始');
|
Log.info('测试开始');
|
||||||
|
|
||||||
Utils.getSidebarData().then(data => Log.info(data))
|
|
||||||
|
|
||||||
Log.info('测试结束');
|
Log.info('测试结束');
|
||||||
},
|
},
|
||||||
@ -972,7 +972,7 @@ color:black;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置
|
// 设置
|
||||||
static getSettingItems(glob): MenuItemConfig[] {
|
static getSettingItems(glob: IGlobal): MenuItemConfig[] {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
|
|
||||||
let setting_list = [];
|
let setting_list = [];
|
||||||
@ -1208,7 +1208,7 @@ color:black;
|
|||||||
domId: '',
|
domId: '',
|
||||||
domText: '啤酒提醒状态',
|
domText: '啤酒提醒状态',
|
||||||
clickFunc: function () {
|
clickFunc: function () {
|
||||||
WHNotify(`啤酒提醒${ glob.beer.status() }`);
|
new Alert(`啤酒提醒${ glob.beer.status() }`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 啤酒提醒时间
|
// 啤酒提醒时间
|
||||||
@ -1384,7 +1384,7 @@ color:black;
|
|||||||
|
|
||||||
// 默认设置
|
// 默认设置
|
||||||
static setDefaultSettings(): void {
|
static setDefaultSettings(): void {
|
||||||
Log.info('Wuhu设置默认值');
|
Log.info('设置默认值:');
|
||||||
let count = 0;
|
let count = 0;
|
||||||
[
|
[
|
||||||
// 开启翻译
|
// 开启翻译
|
||||||
@ -1450,7 +1450,7 @@ color:black;
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Log.info('Wuhu设置默认值结束,设置新值:' + count);
|
Log.info('设置默认值结束,设置新值:' + count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,19 @@
|
|||||||
import Utils from "../utils/Utils";
|
import Utils from "../utils/Utils";
|
||||||
import WuhuBaseAction from "./WuhuBaseAction";
|
import WuhuBaseAction from "./WuhuBaseAction";
|
||||||
|
import Log from "../Log";
|
||||||
|
|
||||||
export default class TravelItem extends WuhuBaseAction {
|
export default class TravelItem extends WuhuBaseAction {
|
||||||
obj: any = null;
|
obj: any = null;
|
||||||
res: any = null;
|
res: any = null;
|
||||||
|
|
||||||
|
// TODO bug修复
|
||||||
private constructor() {
|
private constructor() {
|
||||||
super();
|
super();
|
||||||
setInterval(async () => {
|
window.setInterval(async () => {
|
||||||
if (!TravelItem.glob.isWindowActive.get()) return;
|
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/');
|
const res = await Utils.COFetch('https://yata.yt/api/v1/travel/export/');
|
||||||
|
Log.info('fetch returned');
|
||||||
this.obj = JSON.parse(res);
|
this.obj = JSON.parse(res);
|
||||||
}, 30 * 1000);
|
}, 30 * 1000);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,9 @@ export default class WuhuBaseAction extends WuhuBase {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
static getInstance(this) {
|
// static getInstance(this) {
|
||||||
if (!this.instance)
|
// if (!this.instance)
|
||||||
this.instance = new this();
|
// this.instance = new this();
|
||||||
return this.instance;
|
// return this.instance;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
type ExtendClass<T> = T extends Provider ? T : null;
|
||||||
|
|
||||||
|
export default class Provider {
|
||||||
|
protected instance;
|
||||||
|
|
||||||
|
// private instance: ExtendClass<{}>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// static getInstance<T extends Provider>(this:ExtendClass<T>):ExtendClass<T>{
|
||||||
|
static getInstance<T extends Provider>(this): T & typeof this {
|
||||||
|
if (!this.instance) this.instance = new this();
|
||||||
|
return this.instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/class/provider/Starter.ts
Normal file
9
src/class/provider/Starter.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export default class Starter {
|
||||||
|
public static run(T): void {
|
||||||
|
try {
|
||||||
|
new T().main();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ import Log from "../Log";
|
|||||||
import IWHNotify from "../../interface/IWHNotify";
|
import IWHNotify from "../../interface/IWHNotify";
|
||||||
import NotificationUtils from "./NotificationUtils";
|
import NotificationUtils from "./NotificationUtils";
|
||||||
import WuhuBase from "../WuhuBase";
|
import WuhuBase from "../WuhuBase";
|
||||||
|
import MathUtils from "./MathUtils";
|
||||||
|
|
||||||
export default class Alert extends WuhuBase {
|
export default class Alert extends WuhuBase {
|
||||||
private static container: HTMLElement = null;
|
private static container: HTMLElement = null;
|
||||||
@ -10,7 +11,7 @@ export default class Alert extends WuhuBase {
|
|||||||
private intervalID = -1;
|
private intervalID = -1;
|
||||||
private readonly callback: Function;
|
private readonly callback: Function;
|
||||||
|
|
||||||
constructor(msg: string, options: IWHNotify = {}) {
|
public constructor(msg: string, options: IWHNotify = {}) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
let { timeout, callback, sysNotify, } = options;
|
let { timeout, callback, sysNotify, } = options;
|
||||||
@ -24,13 +25,14 @@ export default class Alert extends WuhuBase {
|
|||||||
this.callback = callback || (() => null);
|
this.callback = callback || (() => null);
|
||||||
Alert.create(this, msg, timeout || 3);
|
Alert.create(this, msg, timeout || 3);
|
||||||
Log.info('创建新通知:', this);
|
Log.info('创建新通知:', this);
|
||||||
if (sysNotify) NotificationUtils.push(msg, options);
|
if (sysNotify) NotificationUtils.getInstance().push(msg, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static create(that: Alert, msg, timeout): void {
|
private static create(that: Alert, msg, timeout): void {
|
||||||
|
let mathUtils: MathUtils = MathUtils.getInstance();
|
||||||
// 通知的唯一id
|
// 通知的唯一id
|
||||||
// const uid = '' + Alert.getRandomInt(1000, 9999);
|
const uid = '' + mathUtils.getRandomInt(1000, 9999);
|
||||||
const uid = '' + performance.now();
|
// const uid = '' + performance.now();
|
||||||
// 每条通知
|
// 每条通知
|
||||||
const element: MyHTMLElement = document.createElement('div');
|
const element: MyHTMLElement = document.createElement('div');
|
||||||
element.id = `wh-notify-${ uid }`;
|
element.id = `wh-notify-${ uid }`;
|
||||||
@ -80,4 +82,8 @@ export default class Alert extends WuhuBase {
|
|||||||
let id = this.intervalID;
|
let id = this.intervalID;
|
||||||
window.clearInterval(id);
|
window.clearInterval(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getElement() {
|
||||||
|
return this.notify;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
66
src/class/utils/InfoUtils.ts
Normal file
66
src/class/utils/InfoUtils.ts
Normal file
@ -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<ISidebarData> {
|
||||||
|
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<void>}
|
||||||
|
*/
|
||||||
|
private sleep(ms) {
|
||||||
|
let time = Math.max(ms, 10);
|
||||||
|
return new Promise(resolve => setTimeout(() => resolve(null), time));
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/class/utils/MathUtils.ts
Normal file
11
src/class/utils/MathUtils.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,9 +3,9 @@ import Log from "../Log";
|
|||||||
import WuhuBase from "../WuhuBase";
|
import WuhuBase from "../WuhuBase";
|
||||||
|
|
||||||
export default class NotificationUtils extends 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;
|
let { notifies } = NotificationUtils.glob;
|
||||||
|
|
||||||
if (options.sysNotify && this.permission) {
|
if (options.sysNotify && this.permission) {
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import UserScriptEngine from "../../enum/UserScriptEngine";
|
|||||||
import WuhuBase from "../WuhuBase";
|
import WuhuBase from "../WuhuBase";
|
||||||
import Log from "../Log";
|
import Log from "../Log";
|
||||||
import Device from "../../enum/Device";
|
import Device from "../../enum/Device";
|
||||||
import ISidebarData from "../../interface/ISidebarData";
|
|
||||||
import AjaxFetchOption from "../../interface/AjaxFetchOption";
|
import AjaxFetchOption from "../../interface/AjaxFetchOption";
|
||||||
import Alert from "./Alert";
|
import Alert from "./Alert";
|
||||||
|
|
||||||
@ -103,56 +102,6 @@ export default class Utils extends WuhuBase {
|
|||||||
? Device.PC : window.innerWidth <= 600 ? Device.MOBILE : Device.TABLET;
|
? 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<void>}
|
|
||||||
*/
|
|
||||||
static sleep(ms) {
|
|
||||||
let time = Math.max(ms, 10);
|
|
||||||
return new Promise(resolve => setTimeout(() => resolve(null), time));
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getSessionData(): Promise<ISidebarData> {
|
|
||||||
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 {
|
static getYaoCD(): string {
|
||||||
if (document.querySelector("#icon49-sidebar")) { // 0-10min
|
if (document.querySelector("#icon49-sidebar")) { // 0-10min
|
||||||
return '<10分'
|
return '<10分'
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import WuhuConfig from "../../class/WuhuConfig";
|
|||||||
import Utils from "../../class/utils/Utils";
|
import Utils from "../../class/utils/Utils";
|
||||||
import Log from "../../class/Log";
|
import Log from "../../class/Log";
|
||||||
import Alert from "../../class/utils/Alert";
|
import Alert from "../../class/utils/Alert";
|
||||||
|
import MathUtils from "../../class/utils/MathUtils";
|
||||||
|
|
||||||
export default async function attackHelper(): Promise<null> {
|
export default async function attackHelper(): Promise<null> {
|
||||||
let { href, device } = WuhuBase.glob;
|
let { href, device } = WuhuBase.glob;
|
||||||
@ -36,7 +37,7 @@ export default async function attackHelper(): Promise<null> {
|
|||||||
doAttackReload();
|
doAttackReload();
|
||||||
} else {
|
} else {
|
||||||
let reload_flag;
|
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 后自动刷新`);
|
Log.info(`[WH] ${ timeout / 1000 }s 后自动刷新`);
|
||||||
window.setInterval(() => {
|
window.setInterval(() => {
|
||||||
if (reload_flag === undefined) {
|
if (reload_flag === undefined) {
|
||||||
|
|||||||
@ -2,13 +2,13 @@ import elementReady from "../utils/elementReady";
|
|||||||
import getWhSettingObj from "../utils/getWhSettingObj";
|
import getWhSettingObj from "../utils/getWhSettingObj";
|
||||||
import addStyle from "../utils/@deprecated/addStyle";
|
import addStyle from "../utils/@deprecated/addStyle";
|
||||||
import addActionBtn from "../utils/addActionBtn";
|
import addActionBtn from "../utils/addActionBtn";
|
||||||
import WHNotify from "../utils/WHNotify";
|
|
||||||
import jQueryAjax from "../utils/jQueryAjax";
|
import jQueryAjax from "../utils/jQueryAjax";
|
||||||
import ajaxFetch from "../utils/ajaxFetch";
|
import ajaxFetch from "../utils/ajaxFetch";
|
||||||
import ZhongIcon from "../../class/ZhongIcon";
|
import ZhongIcon from "../../class/ZhongIcon";
|
||||||
import WuhuBase from "../../class/WuhuBase";
|
import WuhuBase from "../../class/WuhuBase";
|
||||||
import Utils from "../../class/utils/Utils";
|
import Utils from "../../class/utils/Utils";
|
||||||
import Log from "../../class/Log";
|
import Log from "../../class/Log";
|
||||||
|
import Alert from "../../class/utils/Alert";
|
||||||
|
|
||||||
export default function depoHelper() {
|
export default function depoHelper() {
|
||||||
let { href } = WuhuBase.glob;
|
let { href } = WuhuBase.glob;
|
||||||
@ -135,14 +135,14 @@ z-index: 999999;}`);
|
|||||||
// 定取
|
// 定取
|
||||||
buttonWithdraw.addEventListener('click', async () => {
|
buttonWithdraw.addEventListener('click', async () => {
|
||||||
if (parseInt(inputMoney.value) < 1) {
|
if (parseInt(inputMoney.value) < 1) {
|
||||||
WHNotify('无法定额取钱,原因:输入有误');
|
new Alert('无法定额取钱,原因:输入有误');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let money = await getTraceMoney();
|
let money = await getTraceMoney();
|
||||||
let int = { 'input': parseInt(inputMoney.value), 'all': parseInt(money) };
|
let int = { 'input': parseInt(inputMoney.value), 'all': parseInt(money) };
|
||||||
let diff = int.all - int.input;
|
let diff = int.all - int.input;
|
||||||
if (diff < 1) {
|
if (diff < 1) {
|
||||||
WHNotify('无法定额取钱,原因:数不对');
|
new Alert('无法定额取钱,原因:数不对');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await ajaxFetch({
|
await ajaxFetch({
|
||||||
@ -151,7 +151,7 @@ z-index: 999999;}`);
|
|||||||
referrer: 'trade.php',
|
referrer: 'trade.php',
|
||||||
body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=${ diff }&ajax=true`,
|
body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=${ diff }&ajax=true`,
|
||||||
});
|
});
|
||||||
WHNotify(`已取 ${ int.input }`);
|
new Alert(`已取 ${ int.input }`);
|
||||||
});
|
});
|
||||||
// 全存
|
// 全存
|
||||||
buttonDepositAll.addEventListener('click', async () => {
|
buttonDepositAll.addEventListener('click', async () => {
|
||||||
@ -163,7 +163,7 @@ z-index: 999999;}`);
|
|||||||
referrer: 'trade.php',
|
referrer: 'trade.php',
|
||||||
body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=${ money }&ajax=true`,
|
body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=${ money }&ajax=true`,
|
||||||
});
|
});
|
||||||
WHNotify(`$${ money } 全部存入GT`);
|
new Alert(`$${ money } 全部存入GT`);
|
||||||
});
|
});
|
||||||
// 全取
|
// 全取
|
||||||
buttonWithdrawAll.addEventListener('click', async () => {
|
buttonWithdrawAll.addEventListener('click', async () => {
|
||||||
@ -173,7 +173,7 @@ z-index: 999999;}`);
|
|||||||
referrer: 'trade.php',
|
referrer: 'trade.php',
|
||||||
body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=0&ajax=true`,
|
body: `step=view&sub_step=addmoney2&ID=${ traceId }&amount=0&ajax=true`,
|
||||||
});
|
});
|
||||||
WHNotify('已全取');
|
new Alert('已全取');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
if (location.hash.includes('ID=')) handle();
|
if (location.hash.includes('ID=')) handle();
|
||||||
@ -196,7 +196,7 @@ z-index: 999999;}`);
|
|||||||
// 公司一键存钱
|
// 公司一键存钱
|
||||||
async function companyDeposit() {
|
async function companyDeposit() {
|
||||||
if (!location.href.contains('option=funds')) {
|
if (!location.href.contains('option=funds')) {
|
||||||
WHNotify('请先打开公司金库');
|
new Alert('请先打开公司金库');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let { addRFC } = window;
|
let { addRFC } = window;
|
||||||
@ -211,14 +211,14 @@ async function companyDeposit() {
|
|||||||
input.attributes['data-money'].value = money;
|
input.attributes['data-money'].value = money;
|
||||||
});
|
});
|
||||||
$(form).trigger('submit');
|
$(form).trigger('submit');
|
||||||
WHNotify('存钱成功');
|
new Alert('存钱成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 帮派一键存钱
|
// 帮派一键存钱
|
||||||
async function factionDeposit() {
|
async function factionDeposit() {
|
||||||
let form = document.querySelector('#armoury-donate form');
|
let form = document.querySelector('#armoury-donate form');
|
||||||
if (!location.hash.includes('tab=armoury') || !form) {
|
if (!location.hash.includes('tab=armoury') || !form) {
|
||||||
WHNotify('请先打开金库');
|
new Alert('请先打开金库');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof window.addRFC !== 'function') 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' }
|
headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||||
})).json();
|
})).json();
|
||||||
if (res.success === true) {
|
if (res.success === true) {
|
||||||
WHNotify('存钱成功');
|
new Alert('存钱成功');
|
||||||
WHNotify(`${ res.text }`);
|
new Alert(`${ res.text }`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,5 +260,5 @@ async function companyDepositAnywhere() {
|
|||||||
let node = document.createElement('div');
|
let node = document.createElement('div');
|
||||||
node.innerHTML = res;
|
node.innerHTML = res;
|
||||||
let success = node.querySelector('.success-message');
|
let success = node.querySelector('.success-message');
|
||||||
if (success) WHNotify(success.innerHTML);
|
if (success) new Alert(success.innerHTML);
|
||||||
}
|
}
|
||||||
@ -1,16 +1,16 @@
|
|||||||
import WHNotify from "../utils/WHNotify";
|
import Alert from "../../class/utils/Alert";
|
||||||
|
|
||||||
// 一键起飞
|
// 一键起飞
|
||||||
export default function doQuickFly() {
|
export default function doQuickFly() {
|
||||||
// [id: dest, _type: (1...4), ts: timestamp]
|
// [id: dest, _type: (1...4), ts: timestamp]
|
||||||
const [_id, _type, ts] = sessionStorage['wh-quick-fly'].trim().split(' ');
|
const [_id, _type, ts] = sessionStorage['wh-quick-fly'].trim().split(' ');
|
||||||
if (new Date().getTime() - ts > 20000) {
|
if (new Date().getTime() - ts > 20000) {
|
||||||
WHNotify('超时,一键起飞计划已取消');
|
new Alert('超时,一键起飞计划已取消');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const keynode = document.querySelector('div[data-id][data-key]');
|
const keynode = document.querySelector('div[data-id][data-key]');
|
||||||
if (!keynode) {
|
if (!keynode) {
|
||||||
WHNotify('出错了,无法起飞,已取消');
|
new Alert('出错了,无法起飞,已取消');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const _key = keynode.getAttribute('data-key');
|
const _key = keynode.getAttribute('data-key');
|
||||||
@ -23,9 +23,9 @@ export default function doQuickFly() {
|
|||||||
type: ['standard', 'airstrip', 'private', 'business'][_type]
|
type: ['standard', 'airstrip', 'private', 'business'][_type]
|
||||||
},
|
},
|
||||||
success: function (str) {
|
success: function (str) {
|
||||||
WHNotify(str)
|
new Alert(str)
|
||||||
if (str.includes('err')) {
|
if (str.includes('err')) {
|
||||||
WHNotify('起飞出错了');
|
new Alert('起飞出错了');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.location.href = 'https://www.torn.com/index.php'
|
window.location.href = 'https://www.torn.com/index.php'
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
import UserScriptEngine from "../../enum/UserScriptEngine";
|
import UserScriptEngine from "../../enum/UserScriptEngine";
|
||||||
import WHNotify from "../utils/WHNotify";
|
|
||||||
import addStyle from "../utils/@deprecated/addStyle";
|
import addStyle from "../utils/@deprecated/addStyle";
|
||||||
import log from "../utils/@deprecated/log";
|
import log from "../utils/@deprecated/log";
|
||||||
import Utils from "../../class/utils/Utils";
|
import Utils from "../../class/utils/Utils";
|
||||||
|
import Alert from "../../class/utils/Alert";
|
||||||
|
|
||||||
// gs loader
|
// gs loader
|
||||||
export default function loadGS(use) {
|
export default function loadGS(use) {
|
||||||
if (use === UserScriptEngine.PDA) {
|
if (use === UserScriptEngine.PDA) {
|
||||||
let ifr: HTMLIFrameElement = document.querySelector('#wh-gs-loader-ifr');
|
let ifr: HTMLIFrameElement = document.querySelector('#wh-gs-loader-ifr');
|
||||||
if (ifr) {
|
if (ifr) {
|
||||||
WHNotify('飞贼小助手已经加载了');
|
new Alert('飞贼小助手已经加载了');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const container = document.createElement('div');
|
const container = document.createElement('div');
|
||||||
@ -27,14 +27,14 @@ left:0;
|
|||||||
z-index:100001;
|
z-index:100001;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
let notify = WHNotify('加载中');
|
let notify = new Alert('加载中');
|
||||||
ifr.onload = () => {
|
ifr.onload = () => {
|
||||||
notify.close();
|
notify.close();
|
||||||
const _window = ifr.contentWindow;
|
const _window = ifr.contentWindow;
|
||||||
const _docu = _window.document;
|
const _docu = _window.document;
|
||||||
_docu.head.innerHTML = '';
|
_docu.head.innerHTML = '';
|
||||||
_docu.body.innerHTML = '';
|
_docu.body.innerHTML = '';
|
||||||
notify = WHNotify('加载依赖');
|
notify = new Alert('加载依赖');
|
||||||
Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
|
Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
|
||||||
.then(vuejs => {
|
.then(vuejs => {
|
||||||
notify.close();
|
notify.close();
|
||||||
@ -58,14 +58,14 @@ z-index:100001;
|
|||||||
opt.onload(obj);
|
opt.onload(obj);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
notify = WHNotify('加载飞贼小助手');
|
notify = new Alert('加载飞贼小助手');
|
||||||
Utils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`)
|
Utils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
_window.eval(res.replace('http://222.160.142.50:8154/mugger', `https://api.ljs-lyt.com/mugger`));
|
_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_x", 10);
|
||||||
_window.GM_setValue("gsp_y", 10);
|
_window.GM_setValue("gsp_y", 10);
|
||||||
notify.close();
|
notify.close();
|
||||||
notify = WHNotify('飞贼小助手已加载', { timeout: 1 });
|
notify = new Alert('飞贼小助手已加载', { timeout: 1 });
|
||||||
const gsp: HTMLElement = _docu.querySelector('#gsp');
|
const gsp: HTMLElement = _docu.querySelector('#gsp');
|
||||||
const thisRun = () => {
|
const thisRun = () => {
|
||||||
ifr.style.height = `${ gsp.offsetHeight + 10 }px`;
|
ifr.style.height = `${ gsp.offsetHeight + 10 }px`;
|
||||||
@ -83,12 +83,12 @@ z-index:100001;
|
|||||||
}
|
}
|
||||||
if (use === UserScriptEngine.GM) {
|
if (use === UserScriptEngine.GM) {
|
||||||
if (typeof window.Vue !== 'function') {
|
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')
|
Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
|
||||||
.then(VueJS => {
|
.then(VueJS => {
|
||||||
window.eval(VueJS);
|
window.eval(VueJS);
|
||||||
notify.close();
|
notify.close();
|
||||||
notify = WHNotify('已载入依赖');
|
notify = new Alert('已载入依赖');
|
||||||
window.GM_getValue = (k, v = undefined) => {
|
window.GM_getValue = (k, v = undefined) => {
|
||||||
const objV = JSON.parse(window.localStorage.getItem('wh-gs-storage') || '{}')[k];
|
const objV = JSON.parse(window.localStorage.getItem('wh-gs-storage') || '{}')[k];
|
||||||
return objV || v;
|
return objV || v;
|
||||||
@ -105,15 +105,15 @@ z-index:100001;
|
|||||||
window.eval(GSJS);
|
window.eval(GSJS);
|
||||||
if (log.debug()) window.GM_setValue("gsp_showContent", true);
|
if (log.debug()) window.GM_setValue("gsp_showContent", true);
|
||||||
notify.close();
|
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 {
|
} else {
|
||||||
WHNotify('飞贼助手已经加载了');
|
new Alert('飞贼助手已经加载了');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WHNotify('暂不支持');
|
new Alert('暂不支持');
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
import getWhSettingObj from "../utils/getWhSettingObj";
|
import getWhSettingObj from "../utils/getWhSettingObj";
|
||||||
import log from "../utils/@deprecated/log";
|
import log from "../utils/@deprecated/log";
|
||||||
import toThousands from "../utils/toThousands";
|
import toThousands from "../utils/toThousands";
|
||||||
import WHNotify from "../utils/WHNotify";
|
|
||||||
import Log from "../../class/Log";
|
import Log from "../../class/Log";
|
||||||
|
import Alert from "../../class/utils/Alert";
|
||||||
|
|
||||||
// 价格监视handle
|
// 价格监视handle
|
||||||
export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) {
|
export default function priceWatcherHandle(isPDA: boolean, PDA_APIKey: string) {
|
||||||
@ -39,7 +39,7 @@ async function priceWatcherPt(apikey, lower_price, priceWatcher) {
|
|||||||
// 将id与之前存在的比较,不相同时发送通知
|
// 将id与之前存在的比较,不相同时发送通知
|
||||||
if (JSON.stringify(priceWatcher['watch-pt-lower-id']) !== JSON.stringify(lower_arr)) {
|
if (JSON.stringify(priceWatcher['watch-pt-lower-id']) !== JSON.stringify(lower_arr)) {
|
||||||
priceWatcher['watch-pt-lower-id'] = lower_arr;
|
priceWatcher['watch-pt-lower-id'] = lower_arr;
|
||||||
WHNotify(`PT新低价:$${ toThousands(low) }( < $${ toThousands(lower_price) }) - <a href="/pmarket.php" target="_blank">点击转跳</a>`, {
|
new Alert(`PT新低价:$${ toThousands(low) }( < $${ toThousands(lower_price) }) - <a href="/pmarket.php" target="_blank">点击转跳</a>`, {
|
||||||
timeout: 6,
|
timeout: 6,
|
||||||
sysNotify: true,
|
sysNotify: true,
|
||||||
sysNotifyClick: () => window.open('https://www.torn.com/pmarket.php'),
|
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 (lowest_item['cost'] <= lower_price) {
|
||||||
if (priceWatcher['watch-xan-lower-id'] !== lowest_item['ID']) {
|
if (priceWatcher['watch-xan-lower-id'] !== lowest_item['ID']) {
|
||||||
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) }) - <a href="/imarket.php#/p=shop&step=shop&type=&searchname=Xanax" target="_blank">点击转跳</a>`, {
|
new Alert(`XAN新低价:$${ toThousands(lowest_item['cost']) }( < $${ toThousands(lower_price) }) - <a href="/imarket.php#/p=shop&step=shop&type=&searchname=Xanax" target="_blank">点击转跳</a>`, {
|
||||||
timeout: 6,
|
timeout: 6,
|
||||||
sysNotify: true,
|
sysNotify: true,
|
||||||
sysNotifyClick: () => window.open('https://www.torn.com/imarket.php#/p=shop&step=shop&type=&searchname=Xanax')
|
sysNotifyClick: () => window.open('https://www.torn.com/imarket.php#/p=shop&step=shop&type=&searchname=Xanax')
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import popupMsg from "../utils/popupMsg";
|
import popupMsg from "../utils/popupMsg";
|
||||||
import WHNotify from "../utils/WHNotify";
|
import Alert from "../../class/utils/Alert";
|
||||||
import log from "../utils/@deprecated/log";
|
import InfoUtils from "../../class/utils/InfoUtils";
|
||||||
import Utils from "../../class/utils/Utils";
|
import Log from "../../class/Log";
|
||||||
|
|
||||||
// 守望者
|
// 守望者
|
||||||
export default function safeKeeper() {
|
export default function safeKeeper() {
|
||||||
@ -43,7 +43,7 @@ export default function safeKeeper() {
|
|||||||
let popup_close = popup.close;
|
let popup_close = popup.close;
|
||||||
popup.close = () => {
|
popup.close = () => {
|
||||||
if (loop_id === null) popup_close();
|
if (loop_id === null) popup_close();
|
||||||
else WHNotify('守望者运行中,请先停止', { timeout: 2 });
|
else new Alert('守望者运行中,请先停止', { timeout: 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
popup.appendChild(p);
|
popup.appendChild(p);
|
||||||
@ -70,7 +70,7 @@ export default function safeKeeper() {
|
|||||||
})).text();
|
})).text();
|
||||||
if (loop_id !== that_id) return;
|
if (loop_id !== that_id) return;
|
||||||
let data = JSON.parse(res.split('<div')[0]);
|
let data = JSON.parse(res.split('<div')[0]);
|
||||||
log.info(count++, data);
|
Log.info(count++, data);
|
||||||
let { DB, currentFightStatistics, histLog } = data;
|
let { DB, currentFightStatistics, histLog } = data;
|
||||||
// 攻击人
|
// 攻击人
|
||||||
// 格式:currentFightStatistics = {uid: {...}, uid2: {...}}
|
// 格式:currentFightStatistics = {uid: {...}, uid2: {...}}
|
||||||
@ -116,5 +116,5 @@ export default function safeKeeper() {
|
|||||||
loop_id = null;
|
loop_id = null;
|
||||||
p.innerHTML = '状态:已关 ❎';
|
p.innerHTML = '状态:已关 ❎';
|
||||||
});
|
});
|
||||||
self_target.addEventListener('click', () => uid.value = (Utils.getPlayerInfo()['userID']) + '');
|
self_target.addEventListener('click', () => uid.value = (InfoUtils.getInstance().getPlayerInfo()['userID']) + '');
|
||||||
}
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
import titleTrans from "../translate/titleTrans";
|
import titleTrans from "../translate/titleTrans";
|
||||||
import contentTitleLinksTrans from "../translate/contentTitleLinksTrans";
|
import contentTitleLinksTrans from "../translate/contentTitleLinksTrans";
|
||||||
import Device from "../../enum/Device";
|
import Device from "../../enum/Device";
|
||||||
import WHNotify from "../utils/WHNotify";
|
|
||||||
import getWhSettingObj from "../utils/getWhSettingObj";
|
import getWhSettingObj from "../utils/getWhSettingObj";
|
||||||
import addActionBtn from "../utils/addActionBtn";
|
import addActionBtn from "../utils/addActionBtn";
|
||||||
import addStyle from "../utils/@deprecated/addStyle";
|
import addStyle from "../utils/@deprecated/addStyle";
|
||||||
@ -9,6 +8,7 @@ import log from "../utils/@deprecated/log";
|
|||||||
import doQuickFly from "./doQuickFly";
|
import doQuickFly from "./doQuickFly";
|
||||||
import ZhongIcon from "../../class/ZhongIcon";
|
import ZhongIcon from "../../class/ZhongIcon";
|
||||||
import WuhuBase from "../../class/WuhuBase";
|
import WuhuBase from "../../class/WuhuBase";
|
||||||
|
import Alert from "../../class/utils/Alert";
|
||||||
|
|
||||||
export default async function travelHelper(): Promise<null> {
|
export default async function travelHelper(): Promise<null> {
|
||||||
let { href, bodyAttrs, device } = WuhuBase.glob;
|
let { href, bodyAttrs, device } = WuhuBase.glob;
|
||||||
@ -158,7 +158,7 @@ display:none;
|
|||||||
save_trv_settings();
|
save_trv_settings();
|
||||||
set_node.value = wh_trv_alarm.alert_time;
|
set_node.value = wh_trv_alarm.alert_time;
|
||||||
count_down_notify.close();
|
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;
|
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 = (<HTMLInputElement>ev.target).checked;
|
wh_trv_alarm.enable = (<HTMLInputElement>ev.target).checked;
|
||||||
save_trv_settings();
|
save_trv_settings();
|
||||||
on_off_notify.close();
|
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);
|
const remaining_sec = parseInt(remaining_arr);
|
||||||
@ -293,7 +293,7 @@ display:none;
|
|||||||
// 海外警告
|
// 海外警告
|
||||||
if (getWhSettingObj()['abroadWarning']) {
|
if (getWhSettingObj()['abroadWarning']) {
|
||||||
let c = 1;
|
let c = 1;
|
||||||
setInterval(() => WHNotify(`警告:您已海外落地${ c++ * 30 }秒`, {
|
setInterval(() => new Alert(`警告:您已海外落地${ c++ * 30 }秒`, {
|
||||||
timeout: 30,
|
timeout: 30,
|
||||||
sysNotify: true
|
sysNotify: true
|
||||||
}), 30000);
|
}), 30000);
|
||||||
@ -401,11 +401,11 @@ async function travelBack(): Promise<null> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
let res = await backHomeAction();
|
let res = await backHomeAction();
|
||||||
WHNotify(res);
|
new Alert(res);
|
||||||
if (!res.includes('error')) {
|
if (!res.includes('error')) {
|
||||||
WHNotify('成功,即将刷新');
|
new Alert('成功,即将刷新');
|
||||||
setTimeout(() => location.reload(), 3000);
|
setTimeout(() => location.reload(), 3000);
|
||||||
} else {
|
} else {
|
||||||
WHNotify('出错了');
|
new Alert('出错了');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import WHNotify from "../utils/WHNotify";
|
import Alert from "../../class/utils/Alert";
|
||||||
|
|
||||||
// 更新词库
|
// 更新词库
|
||||||
export default function updateTransDict() {
|
export default function updateTransDict() {
|
||||||
WHNotify('计划中');
|
new Alert('计划中');
|
||||||
}
|
}
|
||||||
@ -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 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() {
|
export default function BuyBeer() {
|
||||||
// 正在通知
|
// 正在通知
|
||||||
let is_notified = false;
|
let is_notified = false;
|
||||||
let time: number = getWhSettingObj()['_15AlarmTime'] || 50;
|
let time: number = WuhuConfig.get('_15AlarmTime') || 30;
|
||||||
let loop: BeerMonitorLoop = {};
|
let loop: BeerMonitorLoop = {};
|
||||||
// 循环id
|
// 循环id
|
||||||
let started = null;
|
let started = null;
|
||||||
loop.start = () => {
|
loop.start = () => {
|
||||||
if (started) {
|
if (started) {
|
||||||
log.info('啤酒助手已在运行');
|
Log.info('啤酒助手已在运行');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
started = setInterval(async () => {
|
started = setInterval(async () => {
|
||||||
// 海外取消提醒
|
// 海外取消提醒
|
||||||
let { isTravelling, isAbroad } = await Utils.getUserState();
|
let { isTravelling, isAbroad } = await InfoUtils.getInstance().getUserState();
|
||||||
if (isTravelling || isAbroad) {
|
if (isTravelling || isAbroad) {
|
||||||
loop.stop();
|
loop.stop();
|
||||||
return;
|
return;
|
||||||
@ -28,7 +28,7 @@ export default function BuyBeer() {
|
|||||||
let dt = new Date();
|
let dt = new Date();
|
||||||
// 已选当天不提醒
|
// 已选当天不提醒
|
||||||
const now = [dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate()];
|
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;
|
if (JSON.stringify(now) === JSON.stringify(ignore_date)) return;
|
||||||
// 正常提醒
|
// 正常提醒
|
||||||
let m = 14 - (dt.getMinutes() % 15);
|
let m = 14 - (dt.getMinutes() % 15);
|
||||||
@ -44,14 +44,14 @@ export default function BuyBeer() {
|
|||||||
if (is_notified) return;
|
if (is_notified) return;
|
||||||
is_notified = true;
|
is_notified = true;
|
||||||
// 发送通知
|
// 发送通知
|
||||||
const notify = WHNotify(notify_html, {
|
const notify = new Alert(notify_html, {
|
||||||
timeout: 30,
|
timeout: 30,
|
||||||
sysNotify: true,
|
sysNotify: true,
|
||||||
});
|
});
|
||||||
notify.querySelector('.wh-notify-msg button').addEventListener('click', () => loop.skip_today);
|
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => loop.skip_today);
|
||||||
notify.addEventListener('click', ev => {
|
notify.getElement().addEventListener('click', ev => {
|
||||||
if ((ev.target as HTMLElement).tagName.toLowerCase() === 'a') {
|
if ((ev.target as HTMLElement).tagName.toLowerCase() === 'a') {
|
||||||
notify.sys_notify.close();
|
// notify.sys_notify.close();
|
||||||
notify.close();
|
notify.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -73,14 +73,15 @@ export default function BuyBeer() {
|
|||||||
loop.status = () => started ? '已启动' : '未启动';
|
loop.status = () => started ? '已启动' : '未启动';
|
||||||
loop.is_running = () => !!started;
|
loop.is_running = () => !!started;
|
||||||
|
|
||||||
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-${ Utils.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>`
|
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 = () => {
|
loop.skip_today = () => {
|
||||||
const date = new Date();
|
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点前将不再提醒 <button id="wh-rd-btn-${ Utils.getRandomInt(0, 100) }">取消</button>`);
|
const notify = new Alert(`明早8点前将不再提醒 <button id="wh-rd-btn-${ mathUtils.getRandomInt(0, 100) }">取消</button>`);
|
||||||
// 通知中的取消按钮
|
// 通知中的取消按钮
|
||||||
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;
|
return loop;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import addStyle from "./@deprecated/addStyle";
|
import addStyle from "./@deprecated/addStyle";
|
||||||
import WuhuBase from "../../class/WuhuBase";
|
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 {
|
export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTMLElement {
|
||||||
let { isWindowActive, notifies } = WuhuBase.glob;
|
let { isWindowActive, notifies } = WuhuBase.glob;
|
||||||
|
let mathUtils: MathUtils = MathUtils.getInstance();
|
||||||
|
|
||||||
let {
|
let {
|
||||||
timeout = 3,
|
timeout = 3,
|
||||||
@ -28,7 +29,7 @@ export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTML
|
|||||||
if (!isWindowActive.get() || (self !== top)) return null;
|
if (!isWindowActive.get() || (self !== top)) return null;
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
// 通知的唯一id
|
// 通知的唯一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
|
// 通知容器id
|
||||||
// 通知的容器
|
// 通知的容器
|
||||||
let notify_contain: MyHTMLElement = document.querySelector(`#wh-notify`);
|
let notify_contain: MyHTMLElement = document.querySelector(`#wh-notify`);
|
||||||
@ -128,7 +129,7 @@ cursor: pointer;
|
|||||||
body: date_local_string + notify_contain.msgInnerText,
|
body: date_local_string + notify_contain.msgInnerText,
|
||||||
requireInteraction: true,
|
requireInteraction: true,
|
||||||
renotify: 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.addEventListener('close', () => sysNotifyClick());
|
||||||
notify_obj.sys_notify.onshow = () => setTimeout(() => notify_obj.sys_notify.close(), timeout * 1000);
|
notify_obj.sys_notify.onshow = () => setTimeout(() => notify_obj.sys_notify.close(), timeout * 1000);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import getWhSettingObj from "./getWhSettingObj";
|
import getWhSettingObj from "./getWhSettingObj";
|
||||||
import WHNotify from "./WHNotify";
|
import Alert from "../../class/utils/Alert";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@ -10,5 +10,5 @@ export default function setWhSetting(key: string, value: any, notify: boolean =
|
|||||||
localStorage.setItem('wh_trans_settings', JSON.stringify(obj))
|
localStorage.setItem('wh_trans_settings', JSON.stringify(obj))
|
||||||
|
|
||||||
// 通知
|
// 通知
|
||||||
if (notify) WHNotify('已保存设置')
|
if (notify) new Alert('已保存设置')
|
||||||
}
|
}
|
||||||
6
src/index.ts
Normal file
6
src/index.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import Starter from "./class/provider/Starter";
|
||||||
|
import Application from "./class/Application";
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
Starter.run(Application)
|
||||||
|
})();
|
||||||
207
src/init.ts
207
src/init.ts
@ -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,<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M160 144a32 32 0 0 0-32 32V864a32 32 0 0 0 32 32h688a32 32 0 0 0 32-32V176a32 32 0 0 0-32-32H160z m0-64h688a96 96 0 0 1 96 96V864a96 96 0 0 1-96 96H160a96 96 0 0 1-96-96V176a96 96 0 0 1 96-96z"/><path d="M482.176 262.272h59.616v94.4h196v239.072h-196v184.416h-59.616v-184.416H286.72v-239.04h195.456V262.24z m-137.504 277.152h137.504v-126.4H344.64v126.4z m197.12 0h138.048v-126.4H541.76v126.4z"/></svg>') 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'));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
30
src/main.ts
30
src/main.ts
@ -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`;
|
|
||||||
})
|
|
||||||
();
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
import getWhSettingObj from "./func/utils/getWhSettingObj";
|
import getWhSettingObj from "./func/utils/getWhSettingObj";
|
||||||
import cityFinder from "./func/module/cityFinder";
|
import cityFinder from "./func/module/cityFinder";
|
||||||
import WHNotify from "./func/utils/WHNotify";
|
|
||||||
import elementReady from "./func/utils/elementReady";
|
import elementReady from "./func/utils/elementReady";
|
||||||
import { missionDict } from "./dictionary/translation";
|
import { missionDict } from "./dictionary/translation";
|
||||||
import getTaskHint from "./func/translate/getTaskHint";
|
import getTaskHint from "./func/translate/getTaskHint";
|
||||||
@ -9,6 +8,8 @@ import WuhuBase from "./class/WuhuBase";
|
|||||||
import Utils from "./class/utils/Utils";
|
import Utils from "./class/utils/Utils";
|
||||||
import Log from "./class/Log";
|
import Log from "./class/Log";
|
||||||
import WuhuConfig from "./class/WuhuConfig";
|
import WuhuConfig from "./class/WuhuConfig";
|
||||||
|
import Alert from "./class/utils/Alert";
|
||||||
|
import InfoUtils from "./class/utils/InfoUtils";
|
||||||
|
|
||||||
export default class UrlPattern extends WuhuBase {
|
export default class UrlPattern extends WuhuBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -24,7 +25,7 @@ export default class UrlPattern extends WuhuBase {
|
|||||||
|
|
||||||
// pt一键购买
|
// pt一键购买
|
||||||
if (WuhuConfig.get('ptQuickBuy') && href.includes('pmarket.php')) {
|
if (WuhuConfig.get('ptQuickBuy') && href.includes('pmarket.php')) {
|
||||||
WHNotify('一键购买已开启');
|
new Alert('一键购买已开启');
|
||||||
// ns脚本
|
// ns脚本
|
||||||
const rmv_cfm = (e) => {
|
const rmv_cfm = (e) => {
|
||||||
let el = e.firstElementChild;
|
let el = e.firstElementChild;
|
||||||
@ -57,7 +58,7 @@ export default class UrlPattern extends WuhuBase {
|
|||||||
switch_node.querySelector('input').onchange = e => {
|
switch_node.querySelector('input').onchange = e => {
|
||||||
let target = e.target as HTMLInputElement;
|
let target = e.target as HTMLInputElement;
|
||||||
cont.classList.toggle('wh-display-none');
|
cont.classList.toggle('wh-display-none');
|
||||||
WuhuConfig.set('SEProtect', target.checked, null, true);
|
WuhuConfig.set('SEProtect', target.checked, true);
|
||||||
};
|
};
|
||||||
Utils.elementReady('#gymroot').then(node => {
|
Utils.elementReady('#gymroot').then(node => {
|
||||||
cont = node;
|
cont = node;
|
||||||
@ -163,7 +164,7 @@ $<span class="total">1,000</span>
|
|||||||
let { data } = settings, { responseText } = xhr;
|
let { data } = settings, { responseText } = xhr;
|
||||||
let response = JSON.parse(responseText);
|
let response = JSON.parse(responseText);
|
||||||
if (data.includes('step=buyShopItem') && data.includes('ID=180') && response['success']) {
|
if (data.includes('step=buyShopItem') && data.includes('ID=180') && response['success']) {
|
||||||
WHNotify('已检测成功购买啤酒')
|
new Alert('已检测成功购买啤酒')
|
||||||
beer.skip_today();
|
beer.skip_today();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -924,9 +925,9 @@ margin: 0 0 3px;
|
|||||||
rw_raider().then();
|
rw_raider().then();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 特定代码块
|
// 特定代码块 TODO 修复
|
||||||
if (Utils.getPlayerInfo().userID === 2687093 && Utils.getDeviceType() === Device.PC) {
|
if (InfoUtils.getInstance().getPlayerInfo().userID === 2687093 && Utils.getDeviceType() === Device.PC) {
|
||||||
Utils.getSidebarData().then(data => {
|
InfoUtils.getInstance().getSidebarData().then(data => {
|
||||||
Log.info({ data })
|
Log.info({ data })
|
||||||
let item = document.getElementById('nav-items');
|
let item = document.getElementById('nav-items');
|
||||||
if (item) {
|
if (item) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user