This commit is contained in:
Liwanyi 2022-09-30 18:16:52 +08:00
parent 4f71a18a1e
commit 60e2c96282
34 changed files with 2466 additions and 254 deletions

9
global.d.ts vendored
View File

@ -31,7 +31,7 @@ declare interface Window {
initializeTooltip(selector: string, elemId: string): void; initializeTooltip(selector: string, elemId: string): void;
renderMiniProfile(node: Element, props: any); renderMiniProfile(node: Element, props: any): never;
/* PDA自带 */ /* PDA自带 */
PDA_httpGet(url: URL | string): Promise<PDA_Response>; PDA_httpGet(url: URL | string): Promise<PDA_Response>;
@ -41,7 +41,7 @@ declare interface Window {
/* 油猴脚本引擎自带 */ /* 油猴脚本引擎自带 */
unsafeWindow?: Window & typeof globalThis; unsafeWindow?: Window & typeof globalThis;
GM_xmlhttpRequest(init: GM_RequestParams); GM_xmlhttpRequest(init: GM_RequestParams): void;
GM_getValue(k: string, def: any): unknown; GM_getValue(k: string, def: any): unknown;
@ -97,3 +97,8 @@ declare interface TornGetActionParams {
success: Function, success: Function,
before?: Function before?: Function
} }
declare module "*.html" {
const value: string;
export default value;
}

2015
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,18 +7,22 @@
"minify": "uglifyjs misc/wuhu-torn-helper.js -o release.min.user.js -m", "minify": "uglifyjs misc/wuhu-torn-helper.js -o release.min.user.js -m",
"serve": "", "serve": "",
"build": "rollup -c", "build": "rollup -c",
"compile": "tsc --outDir output" "compile": "tsc --outDir output",
"rollup_watch": "rollup -c -w"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-typescript": "^8.5.0", "@rollup/plugin-typescript": "^8.5.0",
"@types/jquery": "^3.5.14", "@types/jquery": "^3.5.14",
"@types/node": "^18.0.6", "@types/node": "^18.0.6",
"@rollup/plugin-json": "^4.1.0", "npm": "^8.19.2",
"rollup": "^2.79.0", "rollup": "^2.79.0",
"rollup-plugin-html-literals": "^1.1.5",
"rollup-plugin-serve": "^2.0.1", "rollup-plugin-serve": "^2.0.1",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-uglify": "^6.0.4",
"tslib": "^2.4.0", "tslib": "^2.4.0",
"typescript": "^4.8.3", "typescript": "^4.8.3",
"rollup-plugin-uglify": "^6.0.4",
"uglify-js": "^3.16.1" "uglify-js": "^3.16.1"
} }
} }

View File

@ -1,14 +1,25 @@
import typescript from "@rollup/plugin-typescript"; import typescript from "@rollup/plugin-typescript";
import json from "@rollup/plugin-json"; import json from "@rollup/plugin-json";
// import template from "rollup-plugin-html-literals";
import { string } from "rollup-plugin-string";
// import { uglify } from "rollup-plugin-uglify";
export default { export default {
input: 'src/index.ts', input: 'src/index.ts',
output: { output: {
file: 'bundle.js', file: 'bundle.js',
format: 'iife',
}, },
plugins: [ plugins: [
// template({
// include: '*.html',
// failOnError: true
// }),
typescript(), typescript(),
json(), json(),
string({
include: "**/*.html"
}),
// uglify(), // uglify(),
], ],
}; };

View File

@ -15,7 +15,7 @@ export default class Application {
let app = new WuHuTornHelper(); let app = new WuHuTornHelper();
app.init(); app.init();
let glob = WuhuBase.glob; let glob = WuhuBase.glob;
ZhongIcon.initialize(); ZhongIcon.getInstance().initialize();
Common.resolve(); Common.resolve();

View File

@ -1,10 +1,10 @@
import elementReady from "../func/utils/elementReady";
import depoHelper from "../func/module/depoHelper"; import depoHelper from "../func/module/depoHelper";
import travelHelper from "../func/module/travelHelper"; import travelHelper from "../func/module/travelHelper";
import attackHelper from "../func/module/attackHelper"; import attackHelper from "../func/module/attackHelper";
import priceWatcherHandle from "../func/module/priceWatcherHandle"; import priceWatcherHandle from "../func/module/priceWatcherHandle";
import WuhuBase from "./WuhuBase"; import WuhuBase from "./WuhuBase";
import WuhuConfig from "./WuhuConfig"; import WuhuConfig from "./WuhuConfig";
import CommonUtils from "./utils/CommonUtils";
export class Common extends WuhuBase { export class Common extends WuhuBase {
static resolve() { static resolve() {
@ -25,7 +25,7 @@ export class Common extends WuhuBase {
eb.addEventListener('click', () => location.href = '/gym.php'); eb.addEventListener('click', () => location.href = '/gym.php');
eb.href = '/gym.php'; eb.href = '/gym.php';
} else { } else {
elementReady('#barEnergy').then(eb => { CommonUtils.elementReady('#barEnergy').then(eb => {
eb.addEventListener('click', () => location.href = '/gym.php'); eb.addEventListener('click', () => location.href = '/gym.php');
(eb as HTMLAnchorElement).href = '/gym.php'; (eb as HTMLAnchorElement).href = '/gym.php';
}); });
@ -34,7 +34,7 @@ export class Common extends WuhuBase {
nb.addEventListener('click', () => location.href = '/crimes.php'); nb.addEventListener('click', () => location.href = '/crimes.php');
nb.href = '/crimes.php'; nb.href = '/crimes.php';
} else { } else {
elementReady('#barNerve').then(nb => { CommonUtils.elementReady('#barNerve').then(nb => {
nb.addEventListener('click', () => location.href = '/crimes.php'); nb.addEventListener('click', () => location.href = '/crimes.php');
(nb as HTMLAnchorElement).href = '/crimes.php'; (nb as HTMLAnchorElement).href = '/crimes.php';
}); });
@ -43,7 +43,7 @@ export class Common extends WuhuBase {
hb.addEventListener('click', () => location.href = '/item.php#boosters-items'); hb.addEventListener('click', () => location.href = '/item.php#boosters-items');
hb.href = '/item.php#boosters-items'; hb.href = '/item.php#boosters-items';
} else { } else {
elementReady('#barHappy').then(hb => { CommonUtils.elementReady('#barHappy').then(hb => {
hb.addEventListener('click', () => location.href = '/item.php#boosters-items'); hb.addEventListener('click', () => location.href = '/item.php#boosters-items');
(hb as HTMLAnchorElement).href = '/item.php#boosters-items'; (hb as HTMLAnchorElement).href = '/item.php#boosters-items';
}); });
@ -52,7 +52,7 @@ export class Common extends WuhuBase {
lb.addEventListener('click', () => location.href = '/item.php#medical-items'); lb.addEventListener('click', () => location.href = '/item.php#medical-items');
lb.href = '/item.php#medical-items'; lb.href = '/item.php#medical-items';
} else { } else {
elementReady('#barLife').then(lb => { CommonUtils.elementReady('#barLife').then(lb => {
lb.addEventListener('click', () => location.href = '/item.php#medical-items'); lb.addEventListener('click', () => location.href = '/item.php#medical-items');
(lb as HTMLAnchorElement).href = '/item.php#medical-items'; (lb as HTMLAnchorElement).href = '/item.php#medical-items';
}); });

View File

@ -1,16 +1,27 @@
export default class Log { export default class Log {
private static logs = '';
static info(...o): void { static info(...o): void {
let time = this.getTime();
let flag = '[WH] IFO';
if (this.debug()) { if (this.debug()) {
console.log('[WH] IFO', this.getTime(), ...o) console.log(flag, time, ...o);
} }
this.saveLogs(flag, time, ...o);
} }
static error(...o): void { static error(...o): void {
(this.debug()) && (console.error('[WH] ERR', this.getTime(), ...o)) let time = this.getTime();
let flag = '[WH] ERR';
(this.debug()) && (console.error(flag, time, ...o));
this.saveLogs(flag, time, ...o);
} }
static warn(...o): void { static warn(...o): void {
(this.debug()) && (console.warn('[WH] WRN', this.getTime(), ...o)) let time = this.getTime();
let flag = '[WH] WRN';
(this.debug()) && (console.warn(flag, time, ...o));
this.saveLogs(flag, time, ...o);
} }
static debug(): boolean { static debug(): boolean {
@ -36,4 +47,16 @@ export default class Log {
let ms = ('00' + d.getMilliseconds()).slice(-3); let ms = ('00' + d.getMilliseconds()).slice(-3);
return `[${ year }-${ month }-${ date } ${ hours }:${ minutes }:${ seconds }.${ ms }]`; return `[${ year }-${ month }-${ date } ${ hours }:${ minutes }:${ seconds }.${ ms }]`;
} }
static getLogs() {
return this.logs;
}
private static saveLogs(...o) {
o.forEach(item => {
if (typeof item === 'string') this.logs += item;
else this.logs += ` [${ item.toString() }] [${ JSON.stringify(item) }] `;
})
this.logs += '\r\n';
}
} }

View File

@ -5,7 +5,7 @@ import { missionDict } from "../dictionary/translation";
import getTaskHint from "../func/translate/getTaskHint"; import getTaskHint from "../func/translate/getTaskHint";
import Device from "../enum/Device"; import Device from "../enum/Device";
import WuhuBase from "./WuhuBase"; import WuhuBase from "./WuhuBase";
import Utils from "./utils/Utils"; import CommonUtils from "./utils/CommonUtils";
import Log from "./Log"; import Log from "./Log";
import WuhuConfig from "./WuhuConfig"; import WuhuConfig from "./WuhuConfig";
import Alert from "./utils/Alert"; import Alert from "./utils/Alert";
@ -60,7 +60,7 @@ export default class UrlPattern extends WuhuBase {
cont.classList.toggle('wh-display-none'); cont.classList.toggle('wh-display-none');
WuhuConfig.set('SEProtect', target.checked, true); WuhuConfig.set('SEProtect', target.checked, true);
}; };
Utils.elementReady('#gymroot').then(node => { CommonUtils.elementReady('#gymroot').then(node => {
cont = node; cont = node;
if (getWhSettingObj()['SEProtect']) node.classList.add('wh-display-none'); if (getWhSettingObj()['SEProtect']) node.classList.add('wh-display-none');
node.before(switch_node); node.before(switch_node);
@ -894,7 +894,7 @@ margin: 0 0 3px;
}; };
const rw_raider = async function () { const rw_raider = async function () {
if (href.includes('#rader')) { if (href.includes('#rader')) {
Utils.addStyle('div.content-title,div.info-msg-cont{display:none;}'); CommonUtils.addStyle('div.content-title,div.info-msg-cont{display:none;}');
const wh_node = document.createElement('div'); const wh_node = document.createElement('div');
wh_node.id = 'wh-rd-cont'; wh_node.id = 'wh-rd-cont';
wh_node.innerHTML = `<div class="m-top10"> wh_node.innerHTML = `<div class="m-top10">
@ -926,7 +926,7 @@ margin: 0 0 3px;
} }
// 特定代码块 TODO 修复 // 特定代码块 TODO 修复
if (InfoUtils.getInstance().getPlayerInfo().userID === 2687093 && Utils.getDeviceType() === Device.PC) { if (InfoUtils.getInstance().getPlayerInfo().userID === 2687093 && CommonUtils.getDeviceType() === Device.PC) {
InfoUtils.getInstance().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');

View File

@ -1,11 +1,11 @@
import miniprofTrans from "../func/translate/miniprofTrans"; import miniprofTrans from "../func/translate/miniprofTrans";
import Utils from "./utils/Utils"; import CommonUtils from "./utils/CommonUtils";
import WuhuBase from "./WuhuBase"; import WuhuBase from "./WuhuBase";
import TravelItem from "./action/TravelItem"; import TravelItem from "./action/TravelItem";
import Global from "./Global"; import Global from "./Global";
import Log from "./Log"; import Log from "./Log";
import WuhuConfig from "./WuhuConfig"; import WuhuConfig from "./WuhuConfig";
import * as css from "../json/css.json" import * as CSS_JSON from "../json/css.json"
export default class WuHuTornHelper extends WuhuBase { export default class WuHuTornHelper extends WuhuBase {
@ -21,8 +21,6 @@ export default class WuHuTornHelper extends WuhuBase {
if (window.Notification.permission !== 'granted') { if (window.Notification.permission !== 'granted') {
Log.info("芜湖助手即将请求浏览器通知权限……"); Log.info("芜湖助手即将请求浏览器通知权限……");
window.Notification.requestPermission().then(); window.Notification.requestPermission().then();
} else {
Log.warn('没有浏览器通知权限');
} }
} else { } else {
Log.error('当前浏览器不支持系统通知'); Log.error('当前浏览器不支持系统通知');
@ -56,12 +54,12 @@ export default class WuHuTornHelper extends WuhuBase {
return clone; return clone;
}; };
Utils.addStyle(css.css); CommonUtils.addStyle(CSS_JSON.css);
// 测试用 // 测试用
if ('Ok' !== localStorage['WHTEST']) { if ('Ok' !== localStorage['WHTEST']) {
if (!((glob.player_info.userID | 0) === -1 || glob.player_info.playername === '未知')) { if (!((glob.player_info.userID | 0) === -1 || glob.player_info.playername === '未知')) {
Utils.COFetch( CommonUtils.COFetch(
atob('aHR0cDovL2x1di1jbi00ZXZlci5sanMtbHl0LmNvbTo4MDgwL3Rlc3QvY2FzZTE='), atob('aHR0cDovL2x1di1jbi00ZXZlci5sanMtbHl0LmNvbTo4MDgwL3Rlc3QvY2FzZTE='),
// @ts-ignore // @ts-ignore
atob('cG9zdA=='), atob('cG9zdA=='),

View File

@ -1,5 +1,3 @@
import popupMsg from "../func/utils/@deprecated/popupMsg";
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 adHelper from "../func/module/adHelper"; import adHelper from "../func/module/adHelper";
@ -10,18 +8,39 @@ import landedRedirect from "../func/module/landedRedirect";
import initMiniProf from "../func/utils/initMiniProf"; import initMiniProf from "../func/utils/initMiniProf";
import WuhuBase from "./WuhuBase"; import WuhuBase from "./WuhuBase";
import Log from "./Log"; import Log from "./Log";
import Utils from "./utils/Utils"; import CommonUtils from "./utils/CommonUtils";
import WuhuConfig from "./WuhuConfig"; import WuhuConfig from "./WuhuConfig";
import Alert from "./utils/Alert"; import Alert from "./utils/Alert";
import IGlobal from "../interface/IGlobal";
import Test from "../test/Test"; import Test from "../test/Test";
import * as EVENTS from "../json/event.json"; import * as EVENTS from "../json/event.json";
import * as FEST from "../json/fest.json"; import * as FEST from "../json/fest.json";
import Popup from "./utils/Popup";
import TravelItem from "./action/TravelItem";
import QUICK_FLY_HTML from "../html/quick_fly.html";
import NNB_INFO_HTML from "../html/nnb_info.html";
import PRICE_WATCHER_HTML from "../html/price_watcher.html";
import DANGER_ZONE_HTML from "../html/danger_zone.html";
export default class ZhongIcon extends WuhuBase { export default class ZhongIcon extends WuhuBase {
static ZhongNode: MyHTMLElement = null; public static ZhongNode: MyHTMLElement = null;
private menuItemList: MenuItemConfig[] = null;
private settingItemList: MenuItemConfig[] = null;
static elemGenerator(setting: MenuItemConfig, root_node: Node) { public initialize() {
Log.info('ZhongIcon初始化');
this.setDefaultSettings();
Log.info('设置图标开始');
this.setSettingItems();
this.setMenuItems();
this.initIcon();
Log.info('设置图标结束');
Log.info('ZhongIcon初始化结束');
}
private elemGenerator(setting: MenuItemConfig, root_node: Node) {
let { tip, domType } = setting; let { tip, domType } = setting;
let new_node = null; let new_node = null;
switch (domType) { switch (domType) {
@ -90,20 +109,12 @@ export default class ZhongIcon extends WuhuBase {
return root_node.appendChild(new_node); return root_node.appendChild(new_node);
} }
static initialize() {
Log.info('ZhongIcon初始化');
ZhongIcon.setDefaultSettings();
Log.info('设置图标开始');
ZhongIcon.initIcon(ZhongIcon.getMenuItems());
Log.info('设置图标结束');
Log.info('ZhongIcon初始化结束');
}
/** /**
* *
*/ */
static initIcon(settings: MenuItemConfig[]): MyHTMLElement { private initIcon(): MyHTMLElement {
let zhong_node: MyHTMLElement = document.querySelector('div#wh-trans-icon'); let zhong_node: MyHTMLElement = document.querySelector('div#wh-trans-icon');
let settings = this.menuItemList;
let { version } = WuhuBase.glob; let { version } = WuhuBase.glob;
if ((self !== top) || !!zhong_node) return zhong_node; if ((self !== top) || !!zhong_node) return zhong_node;
zhong_node = document.createElement('div'); zhong_node = document.createElement('div');
@ -124,8 +135,8 @@ export default class ZhongIcon extends WuhuBase {
// 设置选项 // 设置选项
zhong_node.setting_root = document.createElement('div'); zhong_node.setting_root = document.createElement('div');
zhong_node.setting_root.classList.add('gSetting'); zhong_node.setting_root.classList.add('gSetting');
// 遍历菜单node设置 // 遍历菜单node设置、生成node、插入dom
settings.forEach(setting => ZhongIcon.elemGenerator(setting, menu_cont)); this.menuItemList.forEach(setting => this.elemGenerator(setting, menu_cont));
// 计时node // 计时node
zhong_node.initTimer = zhong_node.querySelector('#wh-inittimer'); zhong_node.initTimer = zhong_node.querySelector('#wh-inittimer');
// 芜湖助手图标点击事件 // 芜湖助手图标点击事件
@ -163,12 +174,13 @@ export default class ZhongIcon extends WuhuBase {
<p></p> <p></p>
<p><button></button></p> <p><button></button></p>
`; `;
const node = popupMsg(innerHtml, '如何更新');
// 直接复制的按钮 // 直接复制的按钮
node.querySelector('button').onclick = async (e) => { new Popup(innerHtml, '如何更新')
.getElement()
.querySelector('button').onclick = async (e) => {
let target = e.target as HTMLButtonElement; let target = e.target as HTMLButtonElement;
target.innerHTML = '加载中'; target.innerHTML = '加载中';
const js_text = await Utils.COFetch(`https://jjins.github.io/fyfuzhi/release.min.user.js?${ performance.now() }`); const js_text = await CommonUtils.COFetch(`https://jjins.github.io/fyfuzhi/release.min.user.js?${ performance.now() }`);
target.innerHTML = '点击复制到剪切板'; target.innerHTML = '点击复制到剪切板';
target.onclick = () => { target.onclick = () => {
const textarea_node = document.createElement('textarea'); const textarea_node = document.createElement('textarea');
@ -191,7 +203,7 @@ export default class ZhongIcon extends WuhuBase {
settings.fest_date_list.sort().forEach(date => settings.fest_date_list.sort().forEach(date =>
html += `<tr><td>${ 1 + ((<any>date.slice(0, 2)) | 0) }${ date.slice(2) }日</td><td>${ settings.fest_date_dict[date].name }</td><td>${ settings.fest_date_dict[date].eff }</td></tr>` html += `<tr><td>${ 1 + ((<any>date.slice(0, 2)) | 0) }${ date.slice(2) }日</td><td>${ settings.fest_date_dict[date].name }</td><td>${ settings.fest_date_dict[date].eff }</td></tr>`
); );
popupMsg(html += '</table>', '节日'); new Popup(html += '</table>', '节日');
}) })
: el.addEventListener('click', null)); : el.addEventListener('click', null));
// 活动 // 活动
@ -200,7 +212,7 @@ export default class ZhongIcon extends WuhuBase {
let html = '<table>'; let html = '<table>';
settings.events.forEach(el => settings.events.forEach(el =>
html += `<tr><td><b>${ el.name }</b></td><td>${ el.start[0] + 1 }${ el.start[1] }${ el.start[2] }:00~${ el.end[0] + 1 }${ el.end[1] }${ el.end[2] }:00</td></tr><tr><td colspan="2">${ el.eff }</td></tr>`); html += `<tr><td><b>${ el.name }</b></td><td>${ el.start[0] + 1 }${ el.start[1] }${ el.start[2] }:00~${ el.end[0] + 1 }${ el.end[1] }${ el.end[2] }:00</td></tr><tr><td colspan="2">${ el.eff }</td></tr>`);
popupMsg(html += '</table><p>更多信息请关注群聊和公众号</p>', '活动'); new Popup(html += '</table><p>更多信息请关注群聊和公众号</p>', '活动');
}) })
: el.addEventListener('click', null)); : el.addEventListener('click', null));
document.body.append(zhong_node); document.body.append(zhong_node);
@ -213,7 +225,7 @@ export default class ZhongIcon extends WuhuBase {
} }
// 菜单 // 菜单
static getMenuItems(): MenuItemConfig[] { private setMenuItems(): MenuItemConfig[] {
let glob = WuhuBase.glob; let glob = WuhuBase.glob;
const date = new Date(); const date = new Date();
@ -270,7 +282,7 @@ export default class ZhongIcon extends WuhuBase {
let eventObj: EventWrapper = { let eventObj: EventWrapper = {
onEv: false, onEv: false,
daysLeft: Infinity, daysLeft: Infinity,
events: EVENTS, events: EVENTS.default,
}; };
menu_list.events = eventObj.events; menu_list.events = eventObj.events;
eventObj.events.forEach((obj, index) => { eventObj.events.forEach((obj, index) => {
@ -317,7 +329,8 @@ export default class ZhongIcon extends WuhuBase {
domText: '🌸 飞花库存', domText: '🌸 飞花库存',
clickFunc: async function (e) { clickFunc: async function (e) {
e.target.blur(); e.target.blur();
forStock().then(); // forStock().then();
TravelItem.getInstance().clickHandler().then();
}, },
}); });
// 一键起飞 // 一键起飞
@ -328,7 +341,7 @@ export default class ZhongIcon extends WuhuBase {
clickFunc: async function () { clickFunc: async function () {
if (window.hasWHQuickFlyOpt) return; if (window.hasWHQuickFlyOpt) return;
window.hasWHQuickFlyOpt = true; window.hasWHQuickFlyOpt = true;
Utils.addStyle(`#wh-quick-fly-opt{ CommonUtils.addStyle(`#wh-quick-fly-opt{
position:fixed; position:fixed;
left:64px; left:64px;
top:64px; top:64px;
@ -376,19 +389,7 @@ info{display:block;}
`); `);
const node = document.createElement('div'); const node = document.createElement('div');
node.id = 'wh-quick-fly-opt'; node.id = 'wh-quick-fly-opt';
node.innerHTML = ` node.innerHTML = QUICK_FLY_HTML;
<input type="button" value=" - " />
<p></p>
<p></p>
<br/>
<div>
<label><select><option selected>西</option><option></option><option></option><option>󠁵󠁳</option><option></option><option></option><option> ()</option><option></option><option></option><option></option><option></option></select></label>
<label><select><option> - </option><option selected>PI小飞机</option><option> - WLT股票</option><option> - </option></select></label>
<p><a></a></p>
<p></p>
<info></info><button></button>
</div>
`;
const [dest_node, type_node] = node.querySelectorAll('select') as any as HTMLSelectElement[]; const [dest_node, type_node] = node.querySelectorAll('select') as any as HTMLSelectElement[];
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() }`;
@ -401,7 +402,8 @@ info{display:block;}
}); });
node.querySelector('a').addEventListener('click', (e) => { node.querySelector('a').addEventListener('click', (e) => {
e.preventDefault(); e.preventDefault();
forStock(); // forStock();
TravelItem.getInstance().clickHandler();
}); });
node.querySelector('input').addEventListener('click', (e) => { node.querySelector('input').addEventListener('click', (e) => {
node.classList.toggle('wh-quick-fly-opt-hide'); node.classList.toggle('wh-quick-fly-opt-hide');
@ -433,7 +435,7 @@ info{display:block;}
type_node.addEventListener('change', showTime); type_node.addEventListener('change', showTime);
document.body.append(node); document.body.append(node);
showTime(); showTime();
yaoCD.innerHTML = `药CD剩余${ Utils.getYaoCD() }`; yaoCD.innerHTML = `药CD剩余${ CommonUtils.getYaoCD() }`;
}, },
}); });
// NPC LOOT // NPC LOOT
@ -452,7 +454,7 @@ info{display:block;}
<li><a href="https://www.torn.com/loader.php?sid=attack&user2ID=21" target="_blank">Tiny()</a></li> <li><a href="https://www.torn.com/loader.php?sid=attack&user2ID=21" target="_blank">Tiny()</a></li>
</ul> </ul>
<div><img alt="stock.png" src="https://jjins.github.io/t2i/loot.png?${ performance.now() }" style="max-width:100%;display:block;margin:0 auto;" /></div>`; <div><img alt="stock.png" src="https://jjins.github.io/t2i/loot.png?${ performance.now() }" style="max-width:100%;display:block;margin:0 auto;" /></div>`;
popupMsg(insert, 'NPC LOOT'); new Popup(insert, 'NPC LOOT');
}, },
tip: '显示5个可击杀NPC的开打时间', tip: '显示5个可击杀NPC的开打时间',
}); });
@ -463,31 +465,10 @@ info{display:block;}
domText: '👮‍ 查看NNB', domText: '👮‍ 查看NNB',
clickFunc: function (e) { clickFunc: function (e) {
e.target.blur(); e.target.blur();
const insert = `<style> const insert = NNB_INFO_HTML
#wh-popup-cont label p{padding:0 0 0 1em;} .replace('{{}}', localStorage.getItem('APIKey') || '不可用')
#wh-popup-cont label span{font-weight:bold;} .replace('{{}}', glob.isPDA ? glob.PDA_APIKey : '不可用');
</style> const popup = new Popup(insert, '查看NNB').getElement();
<p id="wh-nnb-info-container"></p>
<p><b>NNB</b><b>N</b>atural <b>N</b>erve <b>B</b>ar</p>
<p><b>N</b>erve <b>B</b>ar/<b>NB</b></p>
<p>NNB的方法很简单Torn主页面的最下方有一栏PerksNB-Perks=NNB</p>
<div>
<p>NNB的方法</p>
<label>
<input type="radio" name="wh-nnb-check-select" value="bw" checked/><b> PDA ()</b>
<p>APIKeyPDA提供</p>
<p>使APIKey<br/>
<input readonly value="${ localStorage.getItem('APIKey') || '不可用' }">()<br/>
<input readonly value="${ glob.isPDA ? glob.PDA_APIKey : '不可用' }">(PDA)</p>
</label>
<label>
<input type="radio" name="wh-nnb-check-select" value="ori"/><b> </b>
<p>APIKey</p>
</label>
</div>
<button></button>
`;
const popup = popupMsg(insert, '查看NNB');
const select = popup.querySelector('input'); const select = popup.querySelector('input');
const node = popup.querySelector('p'); const node = popup.querySelector('p');
popup.querySelector('button').addEventListener('click', ev => { popup.querySelector('button').addEventListener('click', ev => {
@ -543,7 +524,7 @@ info{display:block;}
domText: '🔗 常用链接', domText: '🔗 常用链接',
clickFunc: function (e) { clickFunc: function (e) {
if (!this.styleAdded) { if (!this.styleAdded) {
Utils.addStyle(` CommonUtils.addStyle(`
.wh-link-collection-cont a{ .wh-link-collection-cont a{
display: inline-block; display: inline-block;
border: solid 1px #b3b3b3; border: solid 1px #b3b3b3;
@ -631,9 +612,9 @@ background-size: 100% auto !important;
insert += `<a href="${ el.url }"${ el.new_tab ? ' target="_blank"' : '' }><span class="wh-link-collection-img" style="background: url(${ el.img })"></span><span>${ el.name }</span></a>`; insert += `<a href="${ el.url }"${ el.new_tab ? ' target="_blank"' : '' }><span class="wh-link-collection-img" style="background: url(${ el.img })"></span><span>${ el.name }</span></a>`;
}); });
insert += '</p>' insert += '</p>'
let popup = popupMsg(insert, '常用链接'); let popup = new Popup(insert, '常用链接');
popup.classList.add('wh-link-collection-cont'); popup.getElement().classList.add('wh-link-collection-cont');
popup.addEventListener('click', ev => { popup.getElement().addEventListener('click', ev => {
let target = ev.target as HTMLElement; let target = ev.target as HTMLElement;
if (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'span') { if (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'span') {
popup.close(); popup.close();
@ -648,7 +629,7 @@ background-size: 100% auto !important;
domText: '🐏 飞贼小助手', domText: '🐏 飞贼小助手',
clickFunc: function (e) { clickFunc: function (e) {
e.target.blur(); e.target.blur();
loadGS(Utils.getScriptEngine()); loadGS(CommonUtils.getScriptEngine());
}, },
tip: '加载从PC端移植的伞佬的油猴版飞贼小助手', tip: '加载从PC端移植的伞佬的油猴版飞贼小助手',
}); });
@ -660,22 +641,14 @@ background-size: 100% auto !important;
clickFunc: function () { clickFunc: function () {
const watcher_conf = WuhuConfig.get('priceWatcher'); const watcher_conf = WuhuConfig.get('priceWatcher');
const pre_str = JSON.stringify(watcher_conf); const pre_str = JSON.stringify(watcher_conf);
const html = `<style> const html = PRICE_WATCHER_HTML
#wh-popup-cont input{width:12em;} .replace('{{}}', localStorage.getItem('APIKey') || '不可用')
#wh-popup-cont input[type="number"]{width:8em;} .replace('{{}}', glob.isPDA ? glob.PDA_APIKey : '不可用')
</style> .replace('{{}}', watcher_conf['pt'] || -1)
<p>-1</p> .replace('{{}}', watcher_conf['xan'] || -1);
<p>APIKeyAPIKey为<br/> const popup = new Popup(html, '价格监视设置');
<input readonly value="${ localStorage.getItem('APIKey') || '不可用' }">()<br/> popup.getElement().querySelector('button').onclick = () => {
<input readonly value="${ glob.isPDA ? glob.PDA_APIKey : '不可用' }">(PDA) const [pt_node, xan_node] = Array.from(<NodeListOf<HTMLInputElement>>popup.getElement().querySelectorAll('input[type="number"]'));
</p>
<p><b>PT</b><label> $ <input type="number" value="${ watcher_conf['pt'] || -1 }" /></label></p>
<p><b>XAN</b><label> $ <input type="number" value="${ watcher_conf['xan'] || -1 }" /></label></p>
<p><button></button></p>
`;
const popup = popupMsg(html, '价格监视设置');
popup.querySelector('button').onclick = () => {
const [pt_node, xan_node] = Array.from(<NodeListOf<HTMLInputElement>>popup.querySelectorAll('input[type="number"]'));
watcher_conf.pt = (pt_node.value as any) | 0; watcher_conf.pt = (pt_node.value as any) | 0;
watcher_conf.xan = (xan_node.value as any) | 0; watcher_conf.xan = (xan_node.value as any) | 0;
if (JSON.stringify(watcher_conf) !== pre_str) WuhuConfig.set('priceWatcher', watcher_conf); if (JSON.stringify(watcher_conf) !== pre_str) WuhuConfig.set('priceWatcher', watcher_conf);
@ -691,8 +664,8 @@ background-size: 100% auto !important;
clickFunc: function () { clickFunc: function () {
// 弹出小窗口 // 弹出小窗口
const ifHTML = `<iframe src="/crimes.php?step=main" style="width:100%;max-width: 450px;margin: 0 auto;display: none;height: 340px;"></iframe>`; const ifHTML = `<iframe src="/crimes.php?step=main" style="width:100%;max-width: 450px;margin: 0 auto;display: none;height: 340px;"></iframe>`;
const popup_insert = `<p>加载中请稍后${ Utils.loading_gif_html() }</p><div id="wh-quick-crime-if-container"></div>`; const popup_insert = `<p>加载中请稍后${ CommonUtils.loading_gif_html() }</p><div id="wh-quick-crime-if-container"></div>`;
const $popup = popupMsg(popup_insert, '小窗快速犯罪'); const $popup = new Popup(popup_insert, '小窗快速犯罪').getElement();
// 运行状态node // 运行状态node
let loading_node = $popup.querySelector('p:first-of-type'); let loading_node = $popup.querySelector('p:first-of-type');
// if容器 // if容器
@ -737,15 +710,15 @@ background-size: 100% auto !important;
// 如果iframe内部未运行脚本 // 如果iframe内部未运行脚本
if (ifWH === undefined) { if (ifWH === undefined) {
// 隐藏顶部 // 隐藏顶部
Utils.elementReady('#header-root', ifDocu).then(e => e.style.display = 'none'); CommonUtils.elementReady('#header-root', ifDocu).then(e => e.style.display = 'none');
// 隐藏4条 // 隐藏4条
Utils.elementReady('#sidebarroot', ifDocu).then(e => e.style.display = 'none'); CommonUtils.elementReady('#sidebarroot', ifDocu).then(e => e.style.display = 'none');
// 隐藏聊天 // 隐藏聊天
Utils.elementReady('#chatRoot', ifDocu).then(e => e.style.display = 'none'); CommonUtils.elementReady('#chatRoot', ifDocu).then(e => e.style.display = 'none');
// 非验证码页面隐藏滚动条 // 非验证码页面隐藏滚动条
if (!isValidate) ifDocu.body.style.overflow = 'hidden'; if (!isValidate) ifDocu.body.style.overflow = 'hidden';
// 调整容器位置 // 调整容器位置
Utils.elementReady('.content-wrapper', ifDocu).then(elem => { CommonUtils.elementReady('.content-wrapper', ifDocu).then(elem => {
// 加入 // 加入
elem.prepend(mobile_prepend_node); elem.prepend(mobile_prepend_node);
elem.style.margin = '0px'; elem.style.margin = '0px';
@ -759,7 +732,7 @@ background-size: 100% auto !important;
.observe(elem, { childList: true, subtree: true }); .observe(elem, { childList: true, subtree: true });
}); });
// 隐藏返回顶部按钮 // 隐藏返回顶部按钮
Utils.elementReady('#go-to-top-btn button', ifDocu).then(e => e.style.display = 'none'); CommonUtils.elementReady('#go-to-top-btn button', ifDocu).then(e => e.style.display = 'none');
} }
}; };
cIframe.onload = if_onload_func; cIframe.onload = if_onload_func;
@ -797,16 +770,14 @@ background-size: 100% auto !important;
domText: '⚠️ 危险功能', domText: '⚠️ 危险功能',
clickFunc: function (e) { clickFunc: function (e) {
e.target.blur(); e.target.blur();
const insert = `<p>即将打开危险功能,使用这些功能可能会造成账号封禁。请自行考虑是否使用。</p> const insert = DANGER_ZONE_HTML.replace('{{}}', WuhuConfig.get('dangerZone') ? 'checked ' : ' ');
<p><label><input type="checkbox" ${ WuhuConfig.get('dangerZone') ? 'checked ' : ' ' }/> </label></p> const popup = new Popup(insert, '⚠️警告');
<div><button disabled></button></div>`; const warning_check = popup.getElement().querySelector('input');
const popup = popupMsg(insert, '⚠️警告'); const ok_btn = popup.getElement().querySelector('button');
const warning_check = popup.querySelector('input');
const ok_btn = popup.querySelector('button');
warning_check.onchange = () => ok_btn.disabled = false; warning_check.onchange = () => ok_btn.disabled = false;
ok_btn.onclick = () => { ok_btn.onclick = () => {
WuhuConfig.set('dangerZone', warning_check.checked); WuhuConfig.set('dangerZone', warning_check.checked);
popup['close'](); popup.close();
window.location.reload(); window.location.reload();
}; };
}, },
@ -830,10 +801,10 @@ background-size: 100% auto !important;
// 更新历史 // 更新历史
menu_list.push({ menu_list.push({
domType: 'button', domId: '', domText: '🐞 更新历史', clickFunc: async () => { domType: 'button', domId: '', domText: '🐞 更新历史', clickFunc: async () => {
let popup = popupMsg( let popup = new Popup(
'更新历史:<br/><a target="_blank" href="https://gitlab.com/JJins/wuhu-torn-helper/-/blob/dev/CHANGELOG.md">https://gitlab.com/JJins/wuhu-torn-helper/-/blob/dev/CHANGELOG.md</a><br/>', '更新历史:<br/><a target="_blank" href="https://gitlab.com/JJins/wuhu-torn-helper/-/blob/dev/CHANGELOG.md">https://gitlab.com/JJins/wuhu-torn-helper/-/blob/dev/CHANGELOG.md</a><br/>',
'更新历史' '更新历史'
); ).getElement();
popup.classList.add('wh-changeLog'); popup.classList.add('wh-changeLog');
let progressBar = document.createElement('div'); let progressBar = document.createElement('div');
progressBar.style.height = '2px'; progressBar.style.height = '2px';
@ -846,7 +817,7 @@ background-size: 100% auto !important;
style.innerHTML = `.wh-changeLog h2,.wh-changeLog h3,.wh-changeLog h4 {margin:8px 0;}.wh-changeLog li{list-style: inside;}`; style.innerHTML = `.wh-changeLog h2,.wh-changeLog h3,.wh-changeLog h4 {margin:8px 0;}.wh-changeLog li{list-style: inside;}`;
popup.append(progressBar, progressText, style); popup.append(progressBar, progressText, style);
let update = await Utils.COFetch('https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/CHANGELOG.md?' + Date.now()); let update = await CommonUtils.COFetch('https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/CHANGELOG.md?' + Date.now());
progressBar.style.width = '60%'; progressBar.style.width = '60%';
progressText.innerText = '解析中……'; progressText.innerText = '解析中……';
let md = mdParse(update); let md = mdParse(update);
@ -866,9 +837,10 @@ background-size: 100% auto !important;
let $zhongNode = ZhongIcon.ZhongNode; let $zhongNode = ZhongIcon.ZhongNode;
$zhongNode.setting_root = document.createElement('div'); $zhongNode.setting_root = document.createElement('div');
$zhongNode.setting_root.classList.add('gSetting'); $zhongNode.setting_root.classList.add('gSetting');
ZhongIcon.getSettingItems(glob).forEach(set => ZhongIcon.elemGenerator(set, $zhongNode.setting_root)); // ZhongIcon.getSettingItems(glob).forEach(set => ZhongIcon.elemGenerator(set, $zhongNode.setting_root));
let pop = popupMsg('', '芜湖助手设置'); this.settingItemList.forEach(set => this.elemGenerator(set, $zhongNode.setting_root));
pop.appendChild($zhongNode.setting_root); let pop = new Popup('', '芜湖助手设置');
pop.getElement().appendChild($zhongNode.setting_root);
// 本日不提醒 // 本日不提醒
$zhongNode.setting_root.querySelector('#wh-qua-alarm-check-btn').addEventListener('click', glob.beer.skip_today); $zhongNode.setting_root.querySelector('#wh-qua-alarm-check-btn').addEventListener('click', glob.beer.skip_today);
// 开发详情按钮 // 开发详情按钮
@ -883,8 +855,8 @@ background-size: 100% auto !important;
const insert = `<table id="wh-dev-info-tb"> const insert = `<table id="wh-dev-info-tb">
<tr><td>URL</td><td>${ window.location.href }</td></tr> <tr><td>URL</td><td>${ window.location.href }</td></tr>
<tr><td></td><td>${ window.innerWidth }x${ window.innerHeight }</td></tr> <tr><td></td><td>${ window.innerWidth }x${ window.innerHeight }</td></tr>
<tr><td></td><td>${ Utils.getDeviceType().toUpperCase() }</td></tr> <tr><td></td><td>${ CommonUtils.getDeviceType().toUpperCase() }</td></tr>
<tr><td></td><td>${ { 'gm': '油猴', 'raw': '直接运行', 'pda': 'TornPDA' }[Utils.getScriptEngine()] }</td></tr> <tr><td></td><td>${ { 'gm': '油猴', 'raw': '直接运行', 'pda': 'TornPDA' }[CommonUtils.getScriptEngine()] }</td></tr>
<tr><td></td><td>${ date.getFullYear() }/${ date.getMonth() + 1 }/${ date.getDate() } ${ date.getHours() }:${ date.getMinutes() }:${ date.getSeconds() }</td></tr> <tr><td></td><td>${ date.getFullYear() }/${ date.getMonth() + 1 }/${ date.getDate() } ${ date.getHours() }:${ date.getMinutes() }:${ date.getSeconds() }</td></tr>
<tr><td></td><td>${ glob.version }</td></tr> <tr><td></td><td>${ glob.version }</td></tr>
<tr><td></td><td>${ os }</td></tr> <tr><td></td><td>${ os }</td></tr>
@ -899,7 +871,7 @@ color:black;
} }
</style>`; </style>`;
pop.close(); pop.close();
popupMsg(insert, '开发者详情'); new Popup(insert, '开发者详情');
}; };
(window.initializeTooltip) && (window.initializeTooltip('#wh-popup-cont', 'white-tooltip')); (window.initializeTooltip) && (window.initializeTooltip('#wh-popup-cont', 'white-tooltip'));
}, },
@ -918,14 +890,17 @@ color:black;
}, },
}); });
this.menuItemList = menu_list;
return menu_list; return menu_list;
} }
// 设置 // 设置
static getSettingItems(glob: IGlobal): MenuItemConfig[] { private setSettingItems(): MenuItemConfig[] {
const date = new Date(); const date = new Date();
let setting_list = []; let { beer, popup_node } = ZhongIcon.glob;
let setting_list: MenuItemConfig[] = [];
// 12月时加入圣诞小镇选项 // 12月时加入圣诞小镇选项
if (date.getMonth() === 11) { if (date.getMonth() === 11) {
@ -1149,7 +1124,7 @@ color:black;
tip: '每小时的整15分钟的倍数时通知提醒抢啤酒或者血包', tip: '每小时的整15分钟的倍数时通知提醒抢啤酒或者血包',
isHide: true, isHide: true,
changeEv: function (ev) { changeEv: function (ev) {
ev.target.checked ? glob.beer.start() : glob.beer.stop(); ev.target.checked ? beer.start() : beer.stop();
}, },
}); });
// 啤酒提醒状态 // 啤酒提醒状态
@ -1158,7 +1133,7 @@ color:black;
domId: '', domId: '',
domText: '啤酒提醒状态', domText: '啤酒提醒状态',
clickFunc: function () { clickFunc: function () {
new Alert(`啤酒提醒${ glob.beer.status() }`); new Alert(`啤酒提醒${ beer.status() }`);
} }
}); });
// 啤酒提醒时间 // 啤酒提醒时间
@ -1168,25 +1143,25 @@ color:black;
domText: '啤酒提醒时间设定', domText: '啤酒提醒时间设定',
// tip: '通知提前时间', // tip: '通知提前时间',
clickFunc: function () { clickFunc: function () {
glob.popup_node.close(); popup_node.close();
let popup = popupMsg(`<label>提前提醒时间(秒)<input type="number" value="${ WuhuConfig.get('_15AlarmTime') }" /></label><p>区间为 1 ~ 60默认 50</p>`, '啤酒提醒时间设定'); let popup = new Popup(`<label>提前提醒时间(秒)<input type="number" value="${ WuhuConfig.get('_15AlarmTime') }" /></label><p>区间为 1 ~ 60默认 50</p>`, '啤酒提醒时间设定');
let confirm = document.createElement('button'); let confirm = document.createElement('button');
confirm.innerHTML = '确定'; confirm.innerHTML = '确定';
confirm.style.float = 'right'; confirm.style.float = 'right';
confirm.addEventListener('click', () => { confirm.addEventListener('click', () => {
let input: HTMLInputElement = popup.querySelector('input'); let input: HTMLInputElement = popup.getElement().querySelector('input');
let num = (input.value as any) | 0; let num = (input.value as any) | 0;
if (num === WuhuConfig.get('_15AlarmTime')) return; if (num === WuhuConfig.get('_15AlarmTime')) return;
if (num < 1 || num > 60) num = 50; if (num < 1 || num > 60) num = 50;
input.value = num.toString(); input.value = num.toString();
WuhuConfig.set('_15AlarmTime', num); WuhuConfig.set('_15AlarmTime', num);
// 之前的运行状态 // 之前的运行状态
let before_state = glob.beer.is_running(); let before_state = beer.is_running();
glob.beer.set_time(num); beer.set_time(num);
if (before_state) glob.beer.start(); if (before_state) beer.start();
popup.close(); popup.close();
}); });
popup.appendChild(confirm); popup.getElement().appendChild(confirm);
}, },
}); });
@ -1320,20 +1295,31 @@ color:black;
dictName: 'isDev', dictName: 'isDev',
isHide: true, isHide: true,
}); });
// 查看logs
setting_list.push({
domType: 'button',
domId: null,
domText: '查看日志',
clickFunc: ev => {
let pop = new Popup('<textarea readonly style="display: block;height: 90%;"></textarea>', '查看日志');
pop.getElement().querySelector('textarea').innerHTML = Log.getLogs();
}
});
// 更多设定 // 更多设定
if (Log.debug()) setting_list.push({ if (Log.debug()) setting_list.push({
domType: 'button', domId: 'wh-otherBtn', domText: '更多设定', clickFunc: () => { domType: 'button', domId: 'wh-otherBtn', domText: '更多设定',
const html = `清空设置数据、请求通知权限、测试跨域请求`; clickFunc: () => {
popupMsg(html, '更多设定'); new Popup(`清空设置数据、请求通知权限、测试跨域请求`, '更多设定');
}, },
isHide: true, isHide: true,
}); });
this.settingItemList = setting_list;
return setting_list; return setting_list;
} }
// 默认设置 // 默认设置
static setDefaultSettings(): void { private setDefaultSettings(): void {
Log.info('设置默认值:'); Log.info('设置默认值:');
let count = 0; let count = 0;
[ [
@ -1405,8 +1391,8 @@ color:black;
} }
interface MenuItemConfig { interface MenuItemConfig {
tagName?: string;
domType: 'button' | 'plain' | 'checkbox' | 'select'; domType: 'button' | 'plain' | 'checkbox' | 'select';
tagName?: string;
domId?: string; domId?: string;
domText?: string; domText?: string;
clickFunc?: (ev?) => void; clickFunc?: (ev?) => void;
@ -1415,6 +1401,11 @@ interface MenuItemConfig {
dictName?: string; dictName?: string;
changeEv?: (ev) => void; changeEv?: (ev) => void;
domSelectOpt?: { domVal: string, domText: string }[]; domSelectOpt?: { domVal: string, domText: string }[];
/**
*
* @deprecated
*/
isHide?: boolean;
} }
interface EventWrapper { interface EventWrapper {

View File

@ -1,18 +1,24 @@
import Utils from "../utils/Utils"; import CommonUtils from "../utils/CommonUtils";
import Log from "../Log"; import Log from "../Log";
import WuhuBase from "../WuhuBase"; import WuhuBase from "../WuhuBase";
import UserScriptEngine from "../../enum/UserScriptEngine";
import Popup from "../utils/Popup";
import * as STOCK_PNG from "../../json/github.io.stock.png.json";
import * as FILTER from "../../json/ForStockItemFilter.json";
export default class TravelItem extends WuhuBase { export default class TravelItem extends WuhuBase {
obj: any = null; private obj: any = null;
res: any = null; private res: any = null;
// private infoUtils: InfoUtils = InfoUtils.getInstance();
// private commonUtils: CommonUtils = CommonUtils.getInstance();
// TODO bug修复 // TODO bug修复
private constructor() { private constructor() {
super(); super();
window.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/'); 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 CommonUtils.COFetch('https://yata.yt/api/v1/travel/export/');
Log.info('fetch returned'); Log.info('fetch returned');
this.obj = JSON.parse(res); this.obj = JSON.parse(res);
}, 30 * 1000); }, 30 * 1000);
@ -26,6 +32,35 @@ export default class TravelItem extends WuhuBase {
return this.obj; return this.obj;
} }
public clickHandler() { // 呈现内容
public async clickHandler(): Promise<void> {
if (CommonUtils.getScriptEngine() === UserScriptEngine.RAW) {
new Popup(STOCK_PNG.html.replace('{{}}', performance.now().toString()), '飞花库存');
} else {
const popup = new Popup("请稍后 " + CommonUtils.loading_gif_html(), '飞花库存');
let table = `<table><tr><th colspan="2">目的地 - 更新时间</th><th colspan="3">库存</th></tr>`;
const dest = FILTER;
const now = new Date();
const res = await this.get();
if (!res.stocks) return;
dest.forEach(el => {
const update = (now.getTime() - new Date(res.stocks[el.name]['update'] * 1000).getTime()) / 1000 | 0
table += `<tr><td>${ el.show }</td><td>${ update / 60 | 0 }${ update % 60 | 0 }秒前</td>`;
let count = 0;
res.stocks[el.name]['stocks'].forEach(stock => {
if (el.stocks[stock.name]) {
table += `<td${ stock['quantity'] === 0 ? ' style="background-color:#f44336;color:white;border-color:#000;"' : '' }>${ el.stocks[stock.name] } (${ stock['quantity'] })</td>`;
count++;
}
});
while (count < 3) {
count++;
table += '<td></td>';
}
table += '</tr>';
});
table += '</table>';
popup.getElement().innerHTML = table;
}
} }
} }

View File

@ -1,10 +1,6 @@
type ExtendClass<T> = T extends Provider ? T : null;
export default class Provider { export default class Provider {
protected instance; protected instance;
// private instance: ExtendClass<{}>;
constructor() { constructor() {
} }

View File

@ -1,10 +1,12 @@
import Log from "../Log";
export default class Starter { export default class Starter {
public static run(T): void { public static run(T): void {
try { try {
new T().main(); new T().main();
} catch (error) { } catch (error) {
console.log(error); Log.error(error);
console.log('trace: ', JSON.stringify({ error })); Log.error('[Starter] trace: ', JSON.stringify({ error }));
} }
} }
} }

View File

@ -0,0 +1,24 @@
import WuhuBase from "../WuhuBase";
import Log from "../Log";
import ZhongIcon from "../ZhongIcon";
export default class ActionButtonUtils extends WuhuBase {
private hasAdded: boolean = false;
public add(txt: string, func: (ev: Event) => void = () => null): void {
if (!this.hasAdded) this.handle(txt, func);
else Log.warn('ActionButton已存在');
}
private handle(txt, func): void {
let btn = document.createElement('button');
btn.style.padding = '8px 13px 8px 0';
btn.style.verticalAlign = 'bottom';
btn.style.color = '#4CAF50';
btn.innerHTML = txt;
btn.addEventListener('click', func);
ZhongIcon.ZhongNode.querySelector('button').after(btn);
this.hasAdded = true;
Log.info('ActionButton已添加', { txt, func, btn });
}
}

View File

@ -4,20 +4,20 @@ import Log from "../Log";
import Device from "../../enum/Device"; import Device from "../../enum/Device";
import AjaxFetchOption from "../../interface/AjaxFetchOption"; import AjaxFetchOption from "../../interface/AjaxFetchOption";
import Alert from "./Alert"; import Alert from "./Alert";
import * as json from "../../json/loading.json"; import * as LOADING_JSON from "../../json/loading.json";
export default class Utils extends WuhuBase { export default class CommonUtils extends WuhuBase {
static getScriptEngine() { static getScriptEngine() {
let glob = Utils.glob; let glob = CommonUtils.glob;
return glob.unsafeWindow ? UserScriptEngine.GM : glob.isPDA return glob.unsafeWindow ? UserScriptEngine.GM : glob.isPDA
? UserScriptEngine.PDA : UserScriptEngine.RAW; ? UserScriptEngine.PDA : UserScriptEngine.RAW;
} }
static COFetch(url: URL | string, method: 'get' | 'post' = 'get', body: any = null): Promise<string> { static COFetch(url: URL | string, method: 'get' | 'post' = 'get', body: any = null): Promise<string> {
Log.info('跨域获取数据开始'); const engine = this.getScriptEngine();
let start = performance.now();
Log.info('跨域获取数据开始, 脚本引擎: ' + engine);
return new Promise<string>((resolve, reject) => { return new Promise<string>((resolve, reject) => {
const engine = this.getScriptEngine();
Log.info('脚本引擎:' + engine);
switch (engine) { switch (engine) {
case UserScriptEngine.RAW: { case UserScriptEngine.RAW: {
Log.error(`跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`); Log.error(`跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
@ -34,7 +34,7 @@ export default class Utils extends WuhuBase {
} }
PDA_httpGet(url) PDA_httpGet(url)
.then(res => { .then(res => {
Log.info('跨域获取数据成功'); Log.info('跨域获取数据成功, 耗时' + (performance.now() - start | 0) + 'ms');
resolve(res.responseText); resolve(res.responseText);
}) })
.catch(e => { .catch(e => {
@ -58,7 +58,7 @@ export default class Utils extends WuhuBase {
break; break;
} }
case UserScriptEngine.GM: { case UserScriptEngine.GM: {
let { GM_xmlhttpRequest } = Utils.glob; let { GM_xmlhttpRequest } = CommonUtils.glob;
if (typeof GM_xmlhttpRequest !== 'function') { if (typeof GM_xmlhttpRequest !== 'function') {
Log.error('COFetch网络错误用户脚本扩展API错误'); Log.error('COFetch网络错误用户脚本扩展API错误');
reject('错误用户脚本扩展API错误'); reject('错误用户脚本扩展API错误');
@ -69,7 +69,7 @@ export default class Utils extends WuhuBase {
data: method === 'get' ? null : body, data: method === 'get' ? null : body,
headers: method === 'get' ? null : { 'content-type': 'application/json' }, headers: method === 'get' ? null : { 'content-type': 'application/json' },
onload: res => { onload: res => {
Log.info('跨域获取数据成功'); Log.info('跨域获取数据成功,耗时' + (performance.now() - start | 0) + 'ms');
resolve(res.response); resolve(res.response);
}, },
onerror: res => reject(`连接错误 ${ JSON.stringify(res) }`), onerror: res => reject(`连接错误 ${ JSON.stringify(res) }`),
@ -175,6 +175,6 @@ export default class Utils extends WuhuBase {
} }
static loading_gif_html(): string { static loading_gif_html(): string {
return json.html; return LOADING_JSON.html;
} }
} }

View File

@ -0,0 +1,23 @@
import WuhuBase from "../WuhuBase";
export default class FetchUtils extends WuhuBase {
/**
* jquery ajax string
* @param url
* @param method
*/
public ajax(url: string, method: 'GET' | 'POST'): Promise<string> {
return new Promise((res, rej) => {
$.ajax({
method: method,
url: url,
success: function (data) {
res(data)
},
error: function (e) {
rej(e)
}
});
});
}
}

View File

@ -2,7 +2,7 @@ import WuhuBase from "../WuhuBase";
import Alert from "./Alert"; import Alert from "./Alert";
import ISidebarData from "../../interface/ISidebarData"; import ISidebarData from "../../interface/ISidebarData";
import Log from "../Log"; import Log from "../Log";
import Utils from "./Utils"; import CommonUtils from "./CommonUtils";
export default class InfoUtils extends WuhuBase { export default class InfoUtils extends WuhuBase {
/** /**
@ -35,7 +35,7 @@ export default class InfoUtils extends WuhuBase {
ret = JSON.parse(sessionStorage.getItem(field)); ret = JSON.parse(sessionStorage.getItem(field));
} else { } else {
Log.info('无法从sessionStorage获取数据') Log.info('无法从sessionStorage获取数据')
ret = await (await Utils.ajaxFetch({ ret = await (await CommonUtils.ajaxFetch({
url: window.addRFC('/sidebarAjaxAction.php?q=getSidebarData'), url: window.addRFC('/sidebarAjaxAction.php?q=getSidebarData'),
method: 'POST', method: 'POST',
})).json(); })).json();

View File

@ -36,7 +36,7 @@ export default class NotificationUtils extends WuhuBase {
'show', 'show',
() => { () => {
// setTimeout(() => notify.close(), (options.timeout || 3) * 1000); // setTimeout(() => notify.close(), (options.timeout || 3) * 1000);
Log.info(id) Log.info('通知id: ', id)
} }
); );
} }

View File

@ -1,16 +1,14 @@
import Device from "../../enum/Device"; import Device from "../../enum/Device";
import addActionBtn from "../utils/addActionBtn";
import ZhongIcon from "../../class/ZhongIcon";
import WuhuBase from "../../class/WuhuBase"; import WuhuBase from "../../class/WuhuBase";
import WuhuConfig from "../../class/WuhuConfig"; import WuhuConfig from "../../class/WuhuConfig";
import Utils from "../../class/utils/Utils"; import CommonUtils from "../../class/utils/CommonUtils";
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"; import MathUtils from "../../class/utils/MathUtils";
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
export default async function attackHelper(): Promise<null> { export default async function attackHelper(): Promise<null> {
let { href, device } = WuhuBase.glob; let { href, device } = WuhuBase.glob;
let $zhongNode = ZhongIcon.ZhongNode;
// 攻击页面 // 攻击页面
if (href.contains(/loader\.php\?sid=attack/)) { if (href.contains(/loader\.php\?sid=attack/)) {
let stop_reload = false; let stop_reload = false;
@ -19,7 +17,7 @@ export default async function attackHelper(): Promise<null> {
const attReload = WuhuConfig.get('attReload'); const attReload = WuhuConfig.get('attReload');
// 光速刷新按钮 // 光速刷新按钮
addActionBtn('光速刷新', doAttackReload, $zhongNode); ActionButtonUtils.getInstance().add('光速刷新', doAttackReload);
// 自刷新 // 自刷新
let audio_played_flag; let audio_played_flag;
@ -31,7 +29,7 @@ export default async function attackHelper(): Promise<null> {
'tablet': '', 'tablet': '',
}; };
const selector = selector_device_map[device]; const selector = selector_device_map[device];
Utils.elementReady(selector).then(elem => { CommonUtils.elementReady(selector).then(elem => {
if (!elem.querySelector('button')) { if (!elem.querySelector('button')) {
if (WuhuConfig.get('attReload') === 0 && stop_reload !== true) { if (WuhuConfig.get('attReload') === 0 && stop_reload !== true) {
doAttackReload(); doAttackReload();
@ -64,7 +62,7 @@ export default async function attackHelper(): Promise<null> {
// 光速拔刀 // 光速拔刀
if (quickAttIndex !== 6) { if (quickAttIndex !== 6) {
const btn = await Utils.elementReady('div[class^="modal___"] button'); const btn = await CommonUtils.elementReady('div[class^="modal___"] button');
Log.info(btn); Log.info(btn);
if (!btn.innerText.toLowerCase().includes('fight')) return; if (!btn.innerText.toLowerCase().includes('fight')) return;
// 判断是否存在脚踢 // 判断是否存在脚踢
@ -106,7 +104,7 @@ export default async function attackHelper(): Promise<null> {
.wh-move-btn #defender div[class^="title___"]{height:0;} .wh-move-btn #defender div[class^="title___"]{height:0;}
.wh-move-btn #defender button{width: 100%;margin:17px 0;height: 60px;} .wh-move-btn #defender button{width: 100%;margin:17px 0;height: 60px;}
`; `;
Utils.addStyle(css_rule); CommonUtils.addStyle(css_rule);
document.body.classList.add('wh-move-btn'); document.body.classList.add('wh-move-btn');
// 绑定点击事件 联动【光速跑路】 // 绑定点击事件 联动【光速跑路】
btn.onclick = () => { btn.onclick = () => {
@ -186,7 +184,7 @@ export default async function attackHelper(): Promise<null> {
.wh-move-btn #attacker div[class^="title___"]{height:0;} .wh-move-btn #attacker div[class^="title___"]{height:0;}
.wh-move-btn #attacker button{width:100%;margin:0;height:63px;white-space:normal;} .wh-move-btn #attacker button{width:100%;margin:0;height:63px;white-space:normal;}
`; `;
Utils.addStyle(css_rule); CommonUtils.addStyle(css_rule);
document.body.classList.toggle('wh-move-btn'); document.body.classList.toggle('wh-move-btn');
btn.onclick = () => { btn.onclick = () => {
if (WuhuConfig.get('quickFinishAtt') !== 3) { if (WuhuConfig.get('quickFinishAtt') !== 3) {

View File

@ -1,10 +1,10 @@
import elementReady from "../utils/elementReady"; import elementReady from "../utils/elementReady";
import toThousands from "../utils/toThousands"; import toThousands from "../utils/toThousands";
import log from "../utils/@deprecated/log"; import log from "../utils/@deprecated/log";
import Utils from "../../class/utils/Utils"; import CommonUtils from "../../class/utils/CommonUtils";
export default function cityFinder(): void { export default function cityFinder(): void {
Utils.addStyle(` CommonUtils.addStyle(`
.wh-city-finds .leaflet-marker-pane img[src*="torn.com/images/items/"]{ .wh-city-finds .leaflet-marker-pane img[src*="torn.com/images/items/"]{
display: block !important; display: block !important;
box-sizing: border-box; box-sizing: border-box;
@ -64,7 +64,7 @@ display:inline-block;
container.append(info); container.append(info);
base.append(header); base.append(header);
base.append(container); base.append(container);
Utils.COFetch('https://jjins.github.io/item_price_raw.json') CommonUtils.COFetch('https://jjins.github.io/item_price_raw.json')
.then(r => items = JSON.parse(r)) .then(r => items = JSON.parse(r))
.catch(err => { .catch(err => {
log.info(err) log.info(err)

View File

@ -1,25 +1,21 @@
import elementReady from "../utils/elementReady";
import getWhSettingObj from "../utils/getWhSettingObj";
import addStyle from "../utils/@deprecated/addStyle";
import addActionBtn from "../utils/addActionBtn";
import jQueryAjax from "../utils/jQueryAjax";
import ajaxFetch from "../utils/ajaxFetch";
import ZhongIcon from "../../class/ZhongIcon";
import WuhuBase from "../../class/WuhuBase"; import WuhuBase from "../../class/WuhuBase";
import Utils from "../../class/utils/Utils"; import CommonUtils from "../../class/utils/CommonUtils";
import Log from "../../class/Log"; import Log from "../../class/Log";
import Alert from "../../class/utils/Alert"; import Alert from "../../class/utils/Alert";
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
import WuhuConfig from "../../class/WuhuConfig";
import FetchUtils from "../../class/utils/FetchUtils";
export default function depoHelper() { export default function depoHelper() {
let actionButtonUtils: ActionButtonUtils = ActionButtonUtils.getInstance();
let { href } = WuhuBase.glob; let { href } = WuhuBase.glob;
let $zhongNode = ZhongIcon.ZhongNode;
let channel: 'CMPY' | 'FAC'; let channel: 'CMPY' | 'FAC';
const selector = { 'CMPY': "div#funds div.deposit", 'FAC': "div#armoury-donate div.cash" }; const selector = { 'CMPY': "div#funds div.deposit", 'FAC': "div#armoury-donate div.cash" };
// 公司 // 公司
if (href.includes('companies.php')) { if (href.includes('companies.php')) {
channel = "CMPY"; channel = "CMPY";
// 公司转跳存钱 // 公司转跳存钱
if (!href.includes('funds') && getWhSettingObj()['companyRedirect']) { if (!href.includes('funds') && WuhuConfig.get('companyRedirect')) {
const btn = document.getElementById('ui-id-9'); const btn = document.getElementById('ui-id-9');
if (btn) { if (btn) {
btn.click(); btn.click();
@ -27,39 +23,39 @@ export default function depoHelper() {
} }
} }
// 收起冰蛙表格 // 收起冰蛙表格
if (getWhSettingObj()['companyBWCollapse']) { if (WuhuConfig.get('companyBWCollapse')) {
elementReady('#effectiveness-wrap').then(BWtable_node => { CommonUtils.elementReady('#effectiveness-wrap').then(BWTable_node => {
document.body.classList.add('wh-bwtable-ctrl'); document.body.classList.add('wh-bwtable-ctrl');
addStyle(`.wh-bwtable-ctrl #effectiveness-wrap {display:none !important;}`); CommonUtils.addStyle(`.wh-bwtable-ctrl #effectiveness-wrap {display:none !important;}`);
const btn = document.createElement('button'); const btn = document.createElement('button');
btn.innerHTML = '展开冰蛙表格'; btn.innerHTML = '展开冰蛙表格';
btn.addEventListener('click', () => { btn.addEventListener('click', () => {
document.body.classList.toggle('wh-bwtable-ctrl'); document.body.classList.toggle('wh-bwtable-ctrl');
btn.innerText = btn.innerText === '展开冰蛙表格' ? '收起冰蛙表格' : '展开冰蛙表格'; btn.innerText = btn.innerText === '展开冰蛙表格' ? '收起冰蛙表格' : '展开冰蛙表格';
}); });
BWtable_node.before(btn); BWTable_node.before(btn);
}); });
} }
// 一键存钱按钮 // 一键存钱按钮
addActionBtn('一键存钱', companyDeposit, $zhongNode); actionButtonUtils.add('一键存钱', companyDeposit);
} }
// 帮派 // 帮派
if (href.includes('factions.php')) { if (href.includes('factions.php')) {
channel = "FAC"; channel = "FAC";
// 一键存钱按钮 // 一键存钱按钮
addActionBtn('一键存钱', factionDeposit, $zhongNode); actionButtonUtils.add('一键存钱', factionDeposit);
} }
// 存钱框浮动 // 存钱框浮动
if (getWhSettingObj()['floatDepo'] && channel) { if (WuhuConfig.get('floatDepo') && channel) {
document.body.classList.add('wh-depo-helper'); document.body.classList.add('wh-depo-helper');
addStyle(`.wh-depo-helper div#funds div.deposit, CommonUtils.addStyle(`.wh-depo-helper div#funds div.deposit,
.wh-depo-helper div#armoury-donate div.cash{position: fixed !important; .wh-depo-helper div#armoury-donate div.cash{position: fixed !important;
top: 150px; top: 150px;
right: 12px; right: 12px;
box-shadow: 0 0 8px 1px #00000091; box-shadow: 0 0 8px 1px #00000091;
background: #f2f2f2; background: #f2f2f2;
z-index: 999999;}`); z-index: 999999;}`);
elementReady(selector[channel]).then(node => { CommonUtils.elementReady(selector[channel]).then(node => {
const close_btn = document.createElement('button'); const close_btn = document.createElement('button');
close_btn.addEventListener('click', () => { close_btn.addEventListener('click', () => {
document.body.classList.remove('wh-depo-helper'); document.body.classList.remove('wh-depo-helper');
@ -92,13 +88,13 @@ z-index: 999999;}`);
let getTraceMoney = async () => { let getTraceMoney = async () => {
if (typeof addRFC === 'function') { if (typeof addRFC === 'function') {
let url = addRFC('/trade.php?step=getFullMoney&ID=' + traceId); let url = addRFC('/trade.php?step=getFullMoney&ID=' + traceId);
return (await Utils.ajaxFetch({ url: url, method: 'GET', referrer: 'trade.php' })).text(); return (await CommonUtils.ajaxFetch({ url: url, method: 'GET', referrer: 'trade.php' })).text();
} }
}; };
// 监听jquery ajax请求 // 监听jquery ajax请求
if (Log.debug()) $(document).ajaxComplete((_, xhr, settings) => Log.info({ xhr, settings })); if (Log.debug()) $(document).ajaxComplete((_, xhr, settings) => Log.info({ xhr, settings }));
// react 加载完成后将节点加入视图中 // react 加载完成后将节点加入视图中
elementReady('#trade-container').then(() => CommonUtils.elementReady('#trade-container').then(() =>
document.querySelector('#trade-container').before(node) document.querySelector('#trade-container').before(node)
); );
// 构建dom节点 // 构建dom节点
@ -145,7 +141,7 @@ z-index: 999999;}`);
new Alert('无法定额取钱,原因:数不对'); new Alert('无法定额取钱,原因:数不对');
return; return;
} }
await ajaxFetch({ await CommonUtils.ajaxFetch({
url: addRFC('/trade.php'), url: addRFC('/trade.php'),
method: 'POST', method: 'POST',
referrer: 'trade.php', referrer: 'trade.php',
@ -157,7 +153,7 @@ z-index: 999999;}`);
buttonDepositAll.addEventListener('click', async () => { buttonDepositAll.addEventListener('click', async () => {
let money = await getTraceMoney(); let money = await getTraceMoney();
if (money === '0') return; if (money === '0') return;
await ajaxFetch({ await CommonUtils.ajaxFetch({
url: addRFC('/trade.php'), url: addRFC('/trade.php'),
method: 'POST', method: 'POST',
referrer: 'trade.php', referrer: 'trade.php',
@ -167,7 +163,7 @@ z-index: 999999;}`);
}); });
// 全取 // 全取
buttonWithdrawAll.addEventListener('click', async () => { buttonWithdrawAll.addEventListener('click', async () => {
await ajaxFetch({ await CommonUtils.ajaxFetch({
url: addRFC('/trade.php'), url: addRFC('/trade.php'),
method: 'POST', method: 'POST',
referrer: 'trade.php', referrer: 'trade.php',
@ -188,13 +184,14 @@ z-index: 999999;}`);
} }
// 任何位置公司一键存钱 // 任何位置公司一键存钱
if (getWhSettingObj()['companyDepositAnywhere']) { if (WuhuConfig.get('companyDepositAnywhere')) {
addActionBtn('公司存钱', companyDepositAnywhere, $zhongNode); actionButtonUtils.add('公司存钱', companyDepositAnywhere);
} }
} }
// 公司一键存钱 // 公司一键存钱
async function companyDeposit() { async function companyDeposit() {
let fetchUtils: FetchUtils = FetchUtils.getInstance();
if (!location.href.contains('option=funds')) { if (!location.href.contains('option=funds')) {
new Alert('请先打开公司金库'); new Alert('请先打开公司金库');
return; return;
@ -202,7 +199,7 @@ async function companyDeposit() {
let { addRFC } = window; let { addRFC } = window;
if (typeof addRFC !== 'function') return; if (typeof addRFC !== 'function') return;
let url = addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction'); let url = addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction');
let money = await jQueryAjax(url, 'GET'); let money = await fetchUtils.ajax(url, 'GET');
if (money === '0') return; if (money === '0') return;
let form = document.querySelector('#funds .deposit form'); let form = document.querySelector('#funds .deposit form');
let funds_input = form.querySelectorAll('input.input-money'); let funds_input = form.querySelectorAll('input.input-money');
@ -216,6 +213,7 @@ async function companyDeposit() {
// 帮派一键存钱 // 帮派一键存钱
async function factionDeposit() { async function factionDeposit() {
let fetchUtils: FetchUtils = FetchUtils.getInstance();
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) {
new Alert('请先打开金库'); new Alert('请先打开金库');
@ -223,7 +221,7 @@ async function factionDeposit() {
} }
if (typeof window.addRFC !== 'function') return; if (typeof window.addRFC !== 'function') return;
let url = window.addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction'); let url = window.addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction');
let money = await jQueryAjax(url, 'POST'); let money = await fetchUtils.ajax(url, 'POST');
if (money === '0') return; if (money === '0') return;
let funds_input = form.querySelectorAll('input.input-money'); let funds_input = form.querySelectorAll('input.input-money');
funds_input.forEach(input => { funds_input.forEach(input => {
@ -245,10 +243,11 @@ async function factionDeposit() {
// 所有页面公司一键存钱 // 所有页面公司一键存钱
async function companyDepositAnywhere() { async function companyDepositAnywhere() {
let fetchUtils: FetchUtils = FetchUtils.getInstance();
let { addRFC } = window; let { addRFC } = window;
if (typeof addRFC !== 'function') return; if (typeof addRFC !== 'function') return;
let url = addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction'); let url = addRFC('https://www.torn.com/inputMoneyAction.php?step=generalAction');
let money = await jQueryAjax(url, 'GET'); let money = await fetchUtils.ajax(url, 'GET');
if (money === '0') return; if (money === '0') return;
let res = await (await fetch(addRFC('https://www.torn.com/companies.php?step=funds'), { let res = await (await fetch(addRFC('https://www.torn.com/companies.php?step=funds'), {
method: 'POST', method: 'POST',

View File

@ -1,7 +1,7 @@
import UserScriptEngine from "../../enum/UserScriptEngine"; import UserScriptEngine from "../../enum/UserScriptEngine";
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 CommonUtils from "../../class/utils/CommonUtils";
import Alert from "../../class/utils/Alert"; import Alert from "../../class/utils/Alert";
// gs loader // gs loader
@ -35,7 +35,7 @@ z-index:100001;
_docu.head.innerHTML = ''; _docu.head.innerHTML = '';
_docu.body.innerHTML = ''; _docu.body.innerHTML = '';
notify = new Alert('加载依赖'); notify = new Alert('加载依赖');
Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js') CommonUtils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
.then(vuejs => { .then(vuejs => {
notify.close(); notify.close();
_window.eval(vuejs); _window.eval(vuejs);
@ -51,7 +51,7 @@ z-index:100001;
_window.GM_xmlhttpRequest = function (opt) { _window.GM_xmlhttpRequest = function (opt) {
// 暂不适配pda post // 暂不适配pda post
if (opt.method.toLowerCase() === 'post') return; if (opt.method.toLowerCase() === 'post') return;
Utils.COFetch(opt.url).then(res => { CommonUtils.COFetch(opt.url).then(res => {
const obj = { const obj = {
responseText: res responseText: res
}; };
@ -59,7 +59,7 @@ z-index:100001;
}); });
}; };
notify = new Alert('加载飞贼小助手'); notify = new Alert('加载飞贼小助手');
Utils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`) CommonUtils.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);
@ -84,7 +84,7 @@ z-index:100001;
if (use === UserScriptEngine.GM) { if (use === UserScriptEngine.GM) {
if (typeof window.Vue !== 'function') { if (typeof window.Vue !== 'function') {
let notify = new Alert('正在加载依赖'); let notify = new Alert('正在加载依赖');
Utils.COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js') CommonUtils.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();
@ -100,7 +100,7 @@ z-index:100001;
}; };
// TODO // TODO
// window.GM_xmlhttpRequest = GM_xmlhttpRequest; // window.GM_xmlhttpRequest = GM_xmlhttpRequest;
Utils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`) CommonUtils.COFetch(`https://gitee.com/ameto_kasao/tornjs/raw/master/GoldenSnitch.js?${ performance.now() }`)
.then(GSJS => { .then(GSJS => {
window.eval(GSJS); window.eval(GSJS);
if (log.debug()) window.GM_setValue("gsp_showContent", true); if (log.debug()) window.GM_setValue("gsp_showContent", true);

View File

@ -1,25 +1,23 @@
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 getWhSettingObj from "../utils/getWhSettingObj";
import addActionBtn from "../utils/addActionBtn";
import addStyle from "../utils/@deprecated/addStyle";
import log from "../utils/@deprecated/log";
import doQuickFly from "./doQuickFly"; import doQuickFly from "./doQuickFly";
import ZhongIcon from "../../class/ZhongIcon";
import WuhuBase from "../../class/WuhuBase"; import WuhuBase from "../../class/WuhuBase";
import Alert from "../../class/utils/Alert"; import Alert from "../../class/utils/Alert";
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
import WuhuConfig from "../../class/WuhuConfig";
import CommonUtils from "../../class/utils/CommonUtils";
import Log from "../../class/Log";
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;
let $zhongNode = ZhongIcon.ZhongNode;
// URL判断 + 人不在城内 // URL判断 + 人不在城内
if (href.includes('index.php') && bodyAttrs['data-abroad'] === 'true') { if (href.includes('index.php') && bodyAttrs['data-abroad'] === 'true') {
// 飞行中 // 飞行中
if (bodyAttrs["data-traveling"] === 'true') { if (bodyAttrs["data-traveling"] === 'true') {
// 飞行闹钟 // 飞行闹钟
if (device === Device.PC && getWhSettingObj()['trvAlarm']) { if (device === Device.PC && WuhuConfig.get('trvAlarm')) {
// 获取目的地 // 获取目的地
let dest_cn; let dest_cn;
let country = document.body.getAttribute('data-country'); let country = document.body.getAttribute('data-country');
@ -59,7 +57,7 @@ export default async function travelHelper(): Promise<null> {
</div> </div>
</div> </div>
`; `;
addStyle(` CommonUtils.addStyle(`
#wh-trv-alarm{ #wh-trv-alarm{
position:absolute; position:absolute;
width:248px; width:248px;
@ -254,7 +252,7 @@ display:none;
flying_ani.innerHTML = `${ flying_arr[flying_index] }`; flying_ani.innerHTML = `${ flying_arr[flying_index] }`;
flying_index = (flying_index + 1) % flying_arr.length; flying_index = (flying_index + 1) % flying_arr.length;
}, 1000); }, 1000);
log.info({ Log.info({
dest_cn, dest_cn,
remaining_arr, remaining_arr,
wh_trv_alarm, wh_trv_alarm,
@ -279,9 +277,9 @@ display:none;
} }
// 落地转跳 落地前事件 // 落地转跳 落地前事件
if (getWhSettingObj()['landedRedirect'] && document.querySelector('#tcLogo[title]') === null) { if (WuhuConfig.get('landedRedirect') && document.querySelector('#tcLogo[title]') === null) {
window.addEventListener('beforeunload', () => { window.addEventListener('beforeunload', () => {
let obj = { url: getWhSettingObj()['landedRedirect'], timestamp: Date.now() }; let obj = { url: WuhuConfig.get('landedRedirect'), timestamp: Date.now() };
sessionStorage['wh-landed-redirect'] = JSON.stringify(obj); sessionStorage['wh-landed-redirect'] = JSON.stringify(obj);
}); });
} }
@ -289,9 +287,9 @@ display:none;
// 不在飞行中 海外落地页面 // 不在飞行中 海外落地页面
else { else {
// 一键回城 // 一键回城
addActionBtn('直接回城', travelBack, $zhongNode); ActionButtonUtils.getInstance().add('直接回城', travelBack);
// 海外警告 // 海外警告
if (getWhSettingObj()['abroadWarning']) { if (WuhuConfig.get('abroadWarning')) {
let c = 1; let c = 1;
setInterval(() => new Alert(`警告:您已海外落地${ c++ * 30 }`, { setInterval(() => new Alert(`警告:您已海外落地${ c++ * 30 }`, {
timeout: 30, timeout: 30,
@ -330,7 +328,7 @@ display:none;
// 起飞页面 // 起飞页面
if (href.contains(/travelagency\.php/)) { if (href.contains(/travelagency\.php/)) {
// 起飞提醒 // 起飞提醒
if (getWhSettingObj()['energyAlert']) { if (WuhuConfig.get('energyAlert')) {
const $$ = $('.content-wrapper'); const $$ = $('.content-wrapper');
const OB = new MutationObserver(() => { const OB = new MutationObserver(() => {
OB.disconnect(); OB.disconnect();

View File

@ -1,6 +1,8 @@
import Log from "../../class/Log"; import Log from "../../../class/Log";
// 菜单 附加按钮 /**
* @deprecated
*/
export default function addActionBtn(txt: string, func: (ev: Event) => void, mainBtnNode: Element): void { export default function addActionBtn(txt: string, func: (ev: Event) => void, mainBtnNode: Element): void {
addActionBtn.proxy(txt, func, mainBtnNode); addActionBtn.proxy(txt, func, mainBtnNode);
} }

View File

@ -1,4 +1,7 @@
// 包装jquery ajax异步 返回string /**
* 使 FetchUtils.ajax
* @deprecated
*/
export default function jQueryAjax(url: string, method: 'GET' | 'POST'): Promise<string> { export default function jQueryAjax(url: string, method: 'GET' | 'POST'): Promise<string> {
return new Promise((res, rej) => { return new Promise((res, rej) => {
$.ajax({ $.ajax({

View File

@ -1,4 +1,4 @@
import Utils from "../../class/utils/Utils"; import CommonUtils from "../../class/utils/CommonUtils";
import WuhuBase from "../../class/WuhuBase"; import WuhuBase from "../../class/WuhuBase";
/** /**
@ -8,10 +8,10 @@ import WuhuBase from "../../class/WuhuBase";
*/ */
function autoFetchJSON(dest, time = 30) { function autoFetchJSON(dest, time = 30) {
let obj; let obj;
const res = Utils.COFetch(dest); const res = CommonUtils.COFetch(dest);
setInterval(async () => { setInterval(async () => {
if (!WuhuBase.glob.isWindowActive.get()) return; if (!WuhuBase.glob.isWindowActive.get()) return;
const res = await Utils.COFetch(dest); const res = await CommonUtils.COFetch(dest);
obj = JSON.parse(res); obj = JSON.parse(res);
}, time * 1000); }, time * 1000);
return { return {

View File

@ -1,17 +1,19 @@
import UserScriptEngine from "../../enum/UserScriptEngine"; import UserScriptEngine from "../../enum/UserScriptEngine";
import WuhuBase from "../../class/WuhuBase"; import WuhuBase from "../../class/WuhuBase";
import Utils from "../../class/utils/Utils"; import CommonUtils from "../../class/utils/CommonUtils";
import InfoUtils from "../../class/utils/InfoUtils"; import InfoUtils from "../../class/utils/InfoUtils";
import Popup from "../../class/utils/Popup"; import Popup from "../../class/utils/Popup";
import * as FILTER from "../../json/ForStockItemFilter.json"; import * as FILTER from "../../json/ForStockItemFilter.json";
// 海外库存 /**
* @deprecated
*/
export default async function forStock() { export default async function forStock() {
if (InfoUtils.getInstance().getScriptEngine() === UserScriptEngine.RAW) { if (InfoUtils.getInstance().getScriptEngine() === UserScriptEngine.RAW) {
const insert = `<img alt="stock.png" src="https://jjins.github.io/t2i/stock.png?${ performance.now() }" style="max-width:100%;display:block;margin:0 auto;" />`; const insert = `<img alt="stock.png" src="https://jjins.github.io/t2i/stock.png?{{}}" style="max-width:100%;display:block;margin:0 auto;" />`;
new Popup(insert, '飞花库存'); new Popup(insert, '飞花库存');
} else { } else {
const popup = new Popup(`请稍后${ Utils.loading_gif_html() }`, '飞花库存'); const popup = new Popup(`请稍后${ CommonUtils.loading_gif_html() }`, '飞花库存');
let table = `<table><tr><th colspan="2">目的地 - 更新时间</th><th colspan="3">库存</th></tr>`; let table = `<table><tr><th colspan="2">目的地 - 更新时间</th><th colspan="3">库存</th></tr>`;
const dest = FILTER; const dest = FILTER;
const now = new Date(); const now = new Date();

View File

@ -0,0 +1,5 @@
<p>即将打开危险功能,使用这些功能可能会造成账号封禁。请自行考虑是否使用。</p>
<p><label><input type="checkbox" {{}}/> 知道了,开启</label></p>
<div>
<button disabled>保存</button>
</div>

30
src/html/nnb_info.html Normal file
View File

@ -0,0 +1,30 @@
<style>
#wh-popup-cont label p {
padding: 0 0 0 1em;
}
#wh-popup-cont label span {
font-weight: bold;
}
</style>
<p id="wh-nnb-info-container"></p>
<p><b>NNB</b><b>N</b>atural <b>N</b>erve <b>B</b>ar意思是扣除所有加成后玩家本身的犯罪条上限可用于衡量大佬隐藏的犯罪技能等级
</p>
<p>一般来说,左侧红色的犯罪条(<b>N</b>erve <b>B</b>ar/<b>NB</b>)的上限都是包含加成的,如来自帮派、天赋的加成等。额外的加成不会影响玩家的犯罪技能
</p>
<p>查看NNB的方法很简单在Torn主页面的最下方有一栏PerksNB-Perks=NNB</p>
<div>
<p>以下是两种计算NNB的方法</p>
<label>
<input checked name="wh-nnb-check-select" type="radio" value="bw"/><b> 冰蛙或PDA (推荐)</b>
<p>由于需要用到APIKey因此需要冰蛙或PDA提供</p>
<p>当前可以使用的APIKey<br/>
<input readonly value="{{}}">(来自冰蛙)<br/>
<input readonly value="{{}}">(来自PDA)</p>
</label>
<label>
<input name="wh-nnb-check-select" type="radio" value="ori"/><b> 普通方法</b>
<p>该方法不需要APIKey但是仅限在主页面海外或飞行状态不可用的时候</p>
</label>
</div>
<button>计算</button>

View File

@ -0,0 +1,19 @@
<style>
#wh-popup-cont input {
width: 12em;
}
#wh-popup-cont input[type="number"] {
width: 8em;
}
</style>
<p>输入需要监视的价格,低于该价格发出通知,-1为关闭</p>
<p>需要APIKey当前可用APIKey为<br/>
<input readonly value="{{}}">(来自冰蛙)<br/>
<input readonly value="{{}}">(来自PDA)
</p>
<p><b>PT</b><label> $ <input type="number" value="{{}}"/></label></p>
<p><b>XAN</b><label> $ <input type="number" value="{{}}"/></label></p>
<p>
<button>确定</button>
</p>

29
src/html/quick_fly.html Normal file
View File

@ -0,0 +1,29 @@
<input type="button" value=" - "/>
<p>主要用途:出院秒飞</p>
<p>点起飞,页面加载完成后会马上飞走</p>
<br/>
<div>
<label>目的地:<select>
<option selected>墨西哥</option>
<option>开曼</option>
<option>加拿大</option>
<option>󠁵󠁳夏威夷</option>
<option>嘤国</option>
<option>阿根廷</option>
<option>瑞士 (解毒)</option>
<option>立本</option>
<option>祖国</option>
<option>迪拜</option>
<option>南非</option>
</select></label>
<label>飞机:<select>
<option>普通飞机 - 不推荐</option>
<option selected>PI小飞机</option>
<option>私人飞机 - WLT股票</option>
<option>商务飞机 - 机票或内衣店</option>
</select></label>
<p><a>查看花偶库存</a></p>
<p>注:需要验证时无法起飞</p>
<info></info>
<button>起飞</button>
</div>

View File

@ -0,0 +1,3 @@
{
"html": "<img alt=\"stock.png\" src=\"https://jjins.github.io/t2i/stock.png?{{}}\" style=\"max-width:100%;display:block;margin:0 auto;\" />"
}

View File

@ -1,8 +1,9 @@
import WuhuBase from "../class/WuhuBase"; import WuhuBase from "../class/WuhuBase";
import Popup from "../class/utils/Popup"; import Popup from "../class/utils/Popup";
import Log from "../class/Log";
export default class Test extends WuhuBase { export default class Test extends WuhuBase {
public test(): void { public test(): void {
new Popup("123") new Popup(Log.getLogs());
} }
} }

View File

@ -9,6 +9,8 @@
"target": "ES6", "target": "ES6",
"removeComments": true, "removeComments": true,
"sourceMap": false, "sourceMap": false,
"resolveJsonModule": true "resolveJsonModule": true,
// "strict": true,
"jsx": "react-native"
} }
} }