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;
renderMiniProfile(node: Element, props: any);
renderMiniProfile(node: Element, props: any): never;
/* PDA自带 */
PDA_httpGet(url: URL | string): Promise<PDA_Response>;
@ -41,7 +41,7 @@ declare interface Window {
/* 油猴脚本引擎自带 */
unsafeWindow?: Window & typeof globalThis;
GM_xmlhttpRequest(init: GM_RequestParams);
GM_xmlhttpRequest(init: GM_RequestParams): void;
GM_getValue(k: string, def: any): unknown;
@ -96,4 +96,9 @@ declare interface TornGetActionParams {
},
success: 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",
"serve": "",
"build": "rollup -c",
"compile": "tsc --outDir output"
"compile": "tsc --outDir output",
"rollup_watch": "rollup -c -w"
},
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-typescript": "^8.5.0",
"@types/jquery": "^3.5.14",
"@types/node": "^18.0.6",
"@rollup/plugin-json": "^4.1.0",
"npm": "^8.19.2",
"rollup": "^2.79.0",
"rollup-plugin-html-literals": "^1.1.5",
"rollup-plugin-serve": "^2.0.1",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-uglify": "^6.0.4",
"tslib": "^2.4.0",
"typescript": "^4.8.3",
"rollup-plugin-uglify": "^6.0.4",
"uglify-js": "^3.16.1"
}
}

View File

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

View File

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

View File

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

View File

@ -1,16 +1,27 @@
export default class Log {
private static logs = '';
static info(...o): void {
let time = this.getTime();
let flag = '[WH] IFO';
if (this.debug()) {
console.log('[WH] IFO', this.getTime(), ...o)
console.log(flag, time, ...o);
}
this.saveLogs(flag, time, ...o);
}
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 {
(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 {
@ -36,4 +47,16 @@ export default class Log {
let ms = ('00' + d.getMilliseconds()).slice(-3);
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 Device from "../enum/Device";
import WuhuBase from "./WuhuBase";
import Utils from "./utils/Utils";
import CommonUtils from "./utils/CommonUtils";
import Log from "./Log";
import WuhuConfig from "./WuhuConfig";
import Alert from "./utils/Alert";
@ -60,7 +60,7 @@ export default class UrlPattern extends WuhuBase {
cont.classList.toggle('wh-display-none');
WuhuConfig.set('SEProtect', target.checked, true);
};
Utils.elementReady('#gymroot').then(node => {
CommonUtils.elementReady('#gymroot').then(node => {
cont = node;
if (getWhSettingObj()['SEProtect']) node.classList.add('wh-display-none');
node.before(switch_node);
@ -894,7 +894,7 @@ margin: 0 0 3px;
};
const rw_raider = async function () {
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');
wh_node.id = 'wh-rd-cont';
wh_node.innerHTML = `<div class="m-top10">
@ -926,7 +926,7 @@ margin: 0 0 3px;
}
// 特定代码块 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 => {
Log.info({ data })
let item = document.getElementById('nav-items');

View File

@ -1,11 +1,11 @@
import miniprofTrans from "../func/translate/miniprofTrans";
import Utils from "./utils/Utils";
import CommonUtils from "./utils/CommonUtils";
import WuhuBase from "./WuhuBase";
import TravelItem from "./action/TravelItem";
import Global from "./Global";
import Log from "./Log";
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 {
@ -21,8 +21,6 @@ export default class WuHuTornHelper extends WuhuBase {
if (window.Notification.permission !== 'granted') {
Log.info("芜湖助手即将请求浏览器通知权限……");
window.Notification.requestPermission().then();
} else {
Log.warn('没有浏览器通知权限');
}
} else {
Log.error('当前浏览器不支持系统通知');
@ -56,12 +54,12 @@ export default class WuHuTornHelper extends WuhuBase {
return clone;
};
Utils.addStyle(css.css);
CommonUtils.addStyle(CSS_JSON.css);
// 测试用
if ('Ok' !== localStorage['WHTEST']) {
if (!((glob.player_info.userID | 0) === -1 || glob.player_info.playername === '未知')) {
Utils.COFetch(
CommonUtils.COFetch(
atob('aHR0cDovL2x1di1jbi00ZXZlci5sanMtbHl0LmNvbTo4MDgwL3Rlc3QvY2FzZTE='),
// @ts-ignore
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 loadGS from "../func/module/loadGS";
import adHelper from "../func/module/adHelper";
@ -10,18 +8,39 @@ import landedRedirect from "../func/module/landedRedirect";
import initMiniProf from "../func/utils/initMiniProf";
import WuhuBase from "./WuhuBase";
import Log from "./Log";
import Utils from "./utils/Utils";
import CommonUtils from "./utils/CommonUtils";
import WuhuConfig from "./WuhuConfig";
import Alert from "./utils/Alert";
import IGlobal from "../interface/IGlobal";
import Test from "../test/Test";
import * as EVENTS from "../json/event.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 {
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 new_node = null;
switch (domType) {
@ -90,20 +109,12 @@ export default class ZhongIcon extends WuhuBase {
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 settings = this.menuItemList;
let { version } = WuhuBase.glob;
if ((self !== top) || !!zhong_node) return zhong_node;
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.classList.add('gSetting');
// 遍历菜单node设置
settings.forEach(setting => ZhongIcon.elemGenerator(setting, menu_cont));
// 遍历菜单node设置、生成node、插入dom
this.menuItemList.forEach(setting => this.elemGenerator(setting, menu_cont));
// 计时node
zhong_node.initTimer = zhong_node.querySelector('#wh-inittimer');
// 芜湖助手图标点击事件
@ -163,12 +174,13 @@ export default class ZhongIcon extends WuhuBase {
<p></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;
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.onclick = () => {
const textarea_node = document.createElement('textarea');
@ -191,7 +203,7 @@ export default class ZhongIcon extends WuhuBase {
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>`
);
popupMsg(html += '</table>', '节日');
new Popup(html += '</table>', '节日');
})
: el.addEventListener('click', null));
// 活动
@ -200,7 +212,7 @@ export default class ZhongIcon extends WuhuBase {
let html = '<table>';
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>`);
popupMsg(html += '</table><p>更多信息请关注群聊和公众号</p>', '活动');
new Popup(html += '</table><p>更多信息请关注群聊和公众号</p>', '活动');
})
: el.addEventListener('click', null));
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;
const date = new Date();
@ -270,7 +282,7 @@ export default class ZhongIcon extends WuhuBase {
let eventObj: EventWrapper = {
onEv: false,
daysLeft: Infinity,
events: EVENTS,
events: EVENTS.default,
};
menu_list.events = eventObj.events;
eventObj.events.forEach((obj, index) => {
@ -317,7 +329,8 @@ export default class ZhongIcon extends WuhuBase {
domText: '🌸 飞花库存',
clickFunc: async function (e) {
e.target.blur();
forStock().then();
// forStock().then();
TravelItem.getInstance().clickHandler().then();
},
});
// 一键起飞
@ -328,7 +341,7 @@ export default class ZhongIcon extends WuhuBase {
clickFunc: async function () {
if (window.hasWHQuickFlyOpt) return;
window.hasWHQuickFlyOpt = true;
Utils.addStyle(`#wh-quick-fly-opt{
CommonUtils.addStyle(`#wh-quick-fly-opt{
position:fixed;
left:64px;
top:64px;
@ -376,19 +389,7 @@ info{display:block;}
`);
const node = document.createElement('div');
node.id = 'wh-quick-fly-opt';
node.innerHTML = `
<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>
`;
node.innerHTML = QUICK_FLY_HTML;
const [dest_node, type_node] = node.querySelectorAll('select') as any as HTMLSelectElement[];
node.querySelector('button').addEventListener('click', () => {
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) => {
e.preventDefault();
forStock();
// forStock();
TravelItem.getInstance().clickHandler();
});
node.querySelector('input').addEventListener('click', (e) => {
node.classList.toggle('wh-quick-fly-opt-hide');
@ -433,7 +435,7 @@ info{display:block;}
type_node.addEventListener('change', showTime);
document.body.append(node);
showTime();
yaoCD.innerHTML = `药CD剩余${ Utils.getYaoCD() }`;
yaoCD.innerHTML = `药CD剩余${ CommonUtils.getYaoCD() }`;
},
});
// 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>
</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>`;
popupMsg(insert, 'NPC LOOT');
new Popup(insert, 'NPC LOOT');
},
tip: '显示5个可击杀NPC的开打时间',
});
@ -463,31 +465,10 @@ info{display:block;}
domText: '👮‍ 查看NNB',
clickFunc: function (e) {
e.target.blur();
const insert = `<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 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 insert = NNB_INFO_HTML
.replace('{{}}', localStorage.getItem('APIKey') || '不可用')
.replace('{{}}', glob.isPDA ? glob.PDA_APIKey : '不可用');
const popup = new Popup(insert, '查看NNB').getElement();
const select = popup.querySelector('input');
const node = popup.querySelector('p');
popup.querySelector('button').addEventListener('click', ev => {
@ -543,7 +524,7 @@ info{display:block;}
domText: '🔗 常用链接',
clickFunc: function (e) {
if (!this.styleAdded) {
Utils.addStyle(`
CommonUtils.addStyle(`
.wh-link-collection-cont a{
display: inline-block;
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 += '</p>'
let popup = popupMsg(insert, '常用链接');
popup.classList.add('wh-link-collection-cont');
popup.addEventListener('click', ev => {
let popup = new Popup(insert, '常用链接');
popup.getElement().classList.add('wh-link-collection-cont');
popup.getElement().addEventListener('click', ev => {
let target = ev.target as HTMLElement;
if (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'span') {
popup.close();
@ -648,7 +629,7 @@ background-size: 100% auto !important;
domText: '🐏 飞贼小助手',
clickFunc: function (e) {
e.target.blur();
loadGS(Utils.getScriptEngine());
loadGS(CommonUtils.getScriptEngine());
},
tip: '加载从PC端移植的伞佬的油猴版飞贼小助手',
});
@ -660,22 +641,14 @@ background-size: 100% auto !important;
clickFunc: function () {
const watcher_conf = WuhuConfig.get('priceWatcher');
const pre_str = JSON.stringify(watcher_conf);
const html = `<style>
#wh-popup-cont input{width:12em;}
#wh-popup-cont input[type="number"]{width:8em;}
</style>
<p>-1</p>
<p>APIKeyAPIKey为<br/>
<input readonly value="${ localStorage.getItem('APIKey') || '不可用' }">()<br/>
<input readonly value="${ glob.isPDA ? glob.PDA_APIKey : '不可用' }">(PDA)
</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"]'));
const html = PRICE_WATCHER_HTML
.replace('{{}}', localStorage.getItem('APIKey') || '不可用')
.replace('{{}}', glob.isPDA ? glob.PDA_APIKey : '不可用')
.replace('{{}}', watcher_conf['pt'] || -1)
.replace('{{}}', watcher_conf['xan'] || -1);
const popup = new Popup(html, '价格监视设置');
popup.getElement().querySelector('button').onclick = () => {
const [pt_node, xan_node] = Array.from(<NodeListOf<HTMLInputElement>>popup.getElement().querySelectorAll('input[type="number"]'));
watcher_conf.pt = (pt_node.value as any) | 0;
watcher_conf.xan = (xan_node.value as any) | 0;
if (JSON.stringify(watcher_conf) !== pre_str) WuhuConfig.set('priceWatcher', watcher_conf);
@ -691,8 +664,8 @@ background-size: 100% auto !important;
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 popup_insert = `<p>加载中请稍后${ Utils.loading_gif_html() }</p><div id="wh-quick-crime-if-container"></div>`;
const $popup = popupMsg(popup_insert, '小窗快速犯罪');
const popup_insert = `<p>加载中请稍后${ CommonUtils.loading_gif_html() }</p><div id="wh-quick-crime-if-container"></div>`;
const $popup = new Popup(popup_insert, '小窗快速犯罪').getElement();
// 运行状态node
let loading_node = $popup.querySelector('p:first-of-type');
// if容器
@ -737,15 +710,15 @@ background-size: 100% auto !important;
// 如果iframe内部未运行脚本
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条
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';
// 调整容器位置
Utils.elementReady('.content-wrapper', ifDocu).then(elem => {
CommonUtils.elementReady('.content-wrapper', ifDocu).then(elem => {
// 加入
elem.prepend(mobile_prepend_node);
elem.style.margin = '0px';
@ -759,7 +732,7 @@ background-size: 100% auto !important;
.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;
@ -797,16 +770,14 @@ background-size: 100% auto !important;
domText: '⚠️ 危险功能',
clickFunc: function (e) {
e.target.blur();
const insert = `<p>即将打开危险功能,使用这些功能可能会造成账号封禁。请自行考虑是否使用。</p>
<p><label><input type="checkbox" ${ WuhuConfig.get('dangerZone') ? 'checked ' : ' ' }/> </label></p>
<div><button disabled></button></div>`;
const popup = popupMsg(insert, '⚠️警告');
const warning_check = popup.querySelector('input');
const ok_btn = popup.querySelector('button');
const insert = DANGER_ZONE_HTML.replace('{{}}', WuhuConfig.get('dangerZone') ? 'checked ' : ' ');
const popup = new Popup(insert, '⚠️警告');
const warning_check = popup.getElement().querySelector('input');
const ok_btn = popup.getElement().querySelector('button');
warning_check.onchange = () => ok_btn.disabled = false;
ok_btn.onclick = () => {
WuhuConfig.set('dangerZone', warning_check.checked);
popup['close']();
popup.close();
window.location.reload();
};
},
@ -830,10 +801,10 @@ background-size: 100% auto !important;
// 更新历史
menu_list.push({
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/>',
'更新历史'
);
).getElement();
popup.classList.add('wh-changeLog');
let progressBar = document.createElement('div');
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;}`;
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%';
progressText.innerText = '解析中……';
let md = mdParse(update);
@ -866,9 +837,10 @@ background-size: 100% auto !important;
let $zhongNode = ZhongIcon.ZhongNode;
$zhongNode.setting_root = document.createElement('div');
$zhongNode.setting_root.classList.add('gSetting');
ZhongIcon.getSettingItems(glob).forEach(set => ZhongIcon.elemGenerator(set, $zhongNode.setting_root));
let pop = popupMsg('', '芜湖助手设置');
pop.appendChild($zhongNode.setting_root);
// ZhongIcon.getSettingItems(glob).forEach(set => ZhongIcon.elemGenerator(set, $zhongNode.setting_root));
this.settingItemList.forEach(set => this.elemGenerator(set, $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);
// 开发详情按钮
@ -883,8 +855,8 @@ background-size: 100% auto !important;
const insert = `<table id="wh-dev-info-tb">
<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>${ Utils.getDeviceType().toUpperCase() }</td></tr>
<tr><td></td><td>${ { 'gm': '油猴', 'raw': '直接运行', 'pda': 'TornPDA' }[Utils.getScriptEngine()] }</td></tr>
<tr><td></td><td>${ CommonUtils.getDeviceType().toUpperCase() }</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>${ glob.version }</td></tr>
<tr><td></td><td>${ os }</td></tr>
@ -899,7 +871,7 @@ color:black;
}
</style>`;
pop.close();
popupMsg(insert, '开发者详情');
new Popup(insert, '开发者详情');
};
(window.initializeTooltip) && (window.initializeTooltip('#wh-popup-cont', 'white-tooltip'));
},
@ -918,14 +890,17 @@ color:black;
},
});
this.menuItemList = menu_list;
return menu_list;
}
// 设置
static getSettingItems(glob: IGlobal): MenuItemConfig[] {
private setSettingItems(): MenuItemConfig[] {
const date = new Date();
let setting_list = [];
let { beer, popup_node } = ZhongIcon.glob;
let setting_list: MenuItemConfig[] = [];
// 12月时加入圣诞小镇选项
if (date.getMonth() === 11) {
@ -1149,7 +1124,7 @@ color:black;
tip: '每小时的整15分钟的倍数时通知提醒抢啤酒或者血包',
isHide: true,
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: '',
domText: '啤酒提醒状态',
clickFunc: function () {
new Alert(`啤酒提醒${ glob.beer.status() }`);
new Alert(`啤酒提醒${ beer.status() }`);
}
});
// 啤酒提醒时间
@ -1168,25 +1143,25 @@ color:black;
domText: '啤酒提醒时间设定',
// tip: '通知提前时间',
clickFunc: function () {
glob.popup_node.close();
let popup = popupMsg(`<label>提前提醒时间(秒)<input type="number" value="${ WuhuConfig.get('_15AlarmTime') }" /></label><p>区间为 1 ~ 60默认 50</p>`, '啤酒提醒时间设定');
popup_node.close();
let popup = new Popup(`<label>提前提醒时间(秒)<input type="number" value="${ WuhuConfig.get('_15AlarmTime') }" /></label><p>区间为 1 ~ 60默认 50</p>`, '啤酒提醒时间设定');
let confirm = document.createElement('button');
confirm.innerHTML = '确定';
confirm.style.float = 'right';
confirm.addEventListener('click', () => {
let input: HTMLInputElement = popup.querySelector('input');
let input: HTMLInputElement = popup.getElement().querySelector('input');
let num = (input.value as any) | 0;
if (num === WuhuConfig.get('_15AlarmTime')) return;
if (num < 1 || num > 60) num = 50;
input.value = num.toString();
WuhuConfig.set('_15AlarmTime', num);
// 之前的运行状态
let before_state = glob.beer.is_running();
glob.beer.set_time(num);
if (before_state) glob.beer.start();
let before_state = beer.is_running();
beer.set_time(num);
if (before_state) beer.start();
popup.close();
});
popup.appendChild(confirm);
popup.getElement().appendChild(confirm);
},
});
@ -1320,20 +1295,31 @@ color:black;
dictName: 'isDev',
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({
domType: 'button', domId: 'wh-otherBtn', domText: '更多设定', clickFunc: () => {
const html = `清空设置数据、请求通知权限、测试跨域请求`;
popupMsg(html, '更多设定');
domType: 'button', domId: 'wh-otherBtn', domText: '更多设定',
clickFunc: () => {
new Popup(`清空设置数据、请求通知权限、测试跨域请求`, '更多设定');
},
isHide: true,
});
this.settingItemList = setting_list;
return setting_list;
}
// 默认设置
static setDefaultSettings(): void {
private setDefaultSettings(): void {
Log.info('设置默认值:');
let count = 0;
[
@ -1405,8 +1391,8 @@ color:black;
}
interface MenuItemConfig {
tagName?: string;
domType: 'button' | 'plain' | 'checkbox' | 'select';
tagName?: string;
domId?: string;
domText?: string;
clickFunc?: (ev?) => void;
@ -1415,6 +1401,11 @@ interface MenuItemConfig {
dictName?: string;
changeEv?: (ev) => void;
domSelectOpt?: { domVal: string, domText: string }[];
/**
*
* @deprecated
*/
isHide?: boolean;
}
interface EventWrapper {

View File

@ -1,18 +1,24 @@
import Utils from "../utils/Utils";
import CommonUtils from "../utils/CommonUtils";
import Log from "../Log";
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 {
obj: any = null;
res: any = null;
private obj: any = null;
private res: any = null;
// private infoUtils: InfoUtils = InfoUtils.getInstance();
// private commonUtils: CommonUtils = CommonUtils.getInstance();
// TODO bug修复
// TODO bug修复
private constructor() {
super();
window.setInterval(async () => {
if (!TravelItem.glob.isWindowActive.get()) return;
Log.info('fetching https://yata.yt/api/v1/travel/export/');
const res = await Utils.COFetch('https://yata.yt/api/v1/travel/export/');
const res = await CommonUtils.COFetch('https://yata.yt/api/v1/travel/export/');
Log.info('fetch returned');
this.obj = JSON.parse(res);
}, 30 * 1000);
@ -26,6 +32,35 @@ export default class TravelItem extends WuhuBase {
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 {
protected instance;
// private instance: ExtendClass<{}>;
constructor() {
}

View File

@ -1,10 +1,12 @@
import Log from "../Log";
export default class Starter {
public static run(T): void {
try {
new T().main();
} catch (error) {
console.log(error);
console.log('trace: ', JSON.stringify({ error }));
Log.error(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 AjaxFetchOption from "../../interface/AjaxFetchOption";
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() {
let glob = Utils.glob;
let glob = CommonUtils.glob;
return glob.unsafeWindow ? UserScriptEngine.GM : glob.isPDA
? UserScriptEngine.PDA : UserScriptEngine.RAW;
}
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) => {
const engine = this.getScriptEngine();
Log.info('脚本引擎:' + engine);
switch (engine) {
case UserScriptEngine.RAW: {
Log.error(`跨域请求错误:${ UserScriptEngine.RAW }环境下无法进行跨域请求`);
@ -34,7 +34,7 @@ export default class Utils extends WuhuBase {
}
PDA_httpGet(url)
.then(res => {
Log.info('跨域获取数据成功');
Log.info('跨域获取数据成功, 耗时' + (performance.now() - start | 0) + 'ms');
resolve(res.responseText);
})
.catch(e => {
@ -58,7 +58,7 @@ export default class Utils extends WuhuBase {
break;
}
case UserScriptEngine.GM: {
let { GM_xmlhttpRequest } = Utils.glob;
let { GM_xmlhttpRequest } = CommonUtils.glob;
if (typeof GM_xmlhttpRequest !== 'function') {
Log.error('COFetch网络错误用户脚本扩展API错误');
reject('错误用户脚本扩展API错误');
@ -69,7 +69,7 @@ export default class Utils extends WuhuBase {
data: method === 'get' ? null : body,
headers: method === 'get' ? null : { 'content-type': 'application/json' },
onload: res => {
Log.info('跨域获取数据成功');
Log.info('跨域获取数据成功,耗时' + (performance.now() - start | 0) + 'ms');
resolve(res.response);
},
onerror: res => reject(`连接错误 ${ JSON.stringify(res) }`),
@ -175,6 +175,6 @@ export default class Utils extends WuhuBase {
}
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 ISidebarData from "../../interface/ISidebarData";
import Log from "../Log";
import Utils from "./Utils";
import CommonUtils from "./CommonUtils";
export default class InfoUtils extends WuhuBase {
/**
@ -35,7 +35,7 @@ export default class InfoUtils extends WuhuBase {
ret = JSON.parse(sessionStorage.getItem(field));
} else {
Log.info('无法从sessionStorage获取数据')
ret = await (await Utils.ajaxFetch({
ret = await (await CommonUtils.ajaxFetch({
url: window.addRFC('/sidebarAjaxAction.php?q=getSidebarData'),
method: 'POST',
})).json();

View File

@ -36,7 +36,7 @@ export default class NotificationUtils extends WuhuBase {
'show',
() => {
// 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 addActionBtn from "../utils/addActionBtn";
import ZhongIcon from "../../class/ZhongIcon";
import WuhuBase from "../../class/WuhuBase";
import WuhuConfig from "../../class/WuhuConfig";
import Utils from "../../class/utils/Utils";
import CommonUtils from "../../class/utils/CommonUtils";
import Log from "../../class/Log";
import Alert from "../../class/utils/Alert";
import MathUtils from "../../class/utils/MathUtils";
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
export default async function attackHelper(): Promise<null> {
let { href, device } = WuhuBase.glob;
let $zhongNode = ZhongIcon.ZhongNode;
// 攻击页面
if (href.contains(/loader\.php\?sid=attack/)) {
let stop_reload = false;
@ -19,7 +17,7 @@ export default async function attackHelper(): Promise<null> {
const attReload = WuhuConfig.get('attReload');
// 光速刷新按钮
addActionBtn('光速刷新', doAttackReload, $zhongNode);
ActionButtonUtils.getInstance().add('光速刷新', doAttackReload);
// 自刷新
let audio_played_flag;
@ -31,7 +29,7 @@ export default async function attackHelper(): Promise<null> {
'tablet': '',
};
const selector = selector_device_map[device];
Utils.elementReady(selector).then(elem => {
CommonUtils.elementReady(selector).then(elem => {
if (!elem.querySelector('button')) {
if (WuhuConfig.get('attReload') === 0 && stop_reload !== true) {
doAttackReload();
@ -64,7 +62,7 @@ export default async function attackHelper(): Promise<null> {
// 光速拔刀
if (quickAttIndex !== 6) {
const btn = await Utils.elementReady('div[class^="modal___"] button');
const btn = await CommonUtils.elementReady('div[class^="modal___"] button');
Log.info(btn);
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 button{width: 100%;margin:17px 0;height: 60px;}
`;
Utils.addStyle(css_rule);
CommonUtils.addStyle(css_rule);
document.body.classList.add('wh-move-btn');
// 绑定点击事件 联动【光速跑路】
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 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');
btn.onclick = () => {
if (WuhuConfig.get('quickFinishAtt') !== 3) {

View File

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

View File

@ -1,7 +1,7 @@
import UserScriptEngine from "../../enum/UserScriptEngine";
import addStyle from "../utils/@deprecated/addStyle";
import log from "../utils/@deprecated/log";
import Utils from "../../class/utils/Utils";
import CommonUtils from "../../class/utils/CommonUtils";
import Alert from "../../class/utils/Alert";
// gs loader
@ -35,7 +35,7 @@ z-index:100001;
_docu.head.innerHTML = '';
_docu.body.innerHTML = '';
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 => {
notify.close();
_window.eval(vuejs);
@ -51,7 +51,7 @@ z-index:100001;
_window.GM_xmlhttpRequest = function (opt) {
// 暂不适配pda post
if (opt.method.toLowerCase() === 'post') return;
Utils.COFetch(opt.url).then(res => {
CommonUtils.COFetch(opt.url).then(res => {
const obj = {
responseText: res
};
@ -59,7 +59,7 @@ z-index:100001;
});
};
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 => {
_window.eval(res.replace('http://222.160.142.50:8154/mugger', `https://api.ljs-lyt.com/mugger`));
_window.GM_setValue("gsp_x", 10);
@ -84,7 +84,7 @@ z-index:100001;
if (use === UserScriptEngine.GM) {
if (typeof window.Vue !== 'function') {
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 => {
window.eval(VueJS);
notify.close();
@ -100,7 +100,7 @@ z-index:100001;
};
// TODO
// 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 => {
window.eval(GSJS);
if (log.debug()) window.GM_setValue("gsp_showContent", true);

View File

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

View File

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

View File

@ -1,17 +1,19 @@
import UserScriptEngine from "../../enum/UserScriptEngine";
import WuhuBase from "../../class/WuhuBase";
import Utils from "../../class/utils/Utils";
import CommonUtils from "../../class/utils/CommonUtils";
import InfoUtils from "../../class/utils/InfoUtils";
import Popup from "../../class/utils/Popup";
import * as FILTER from "../../json/ForStockItemFilter.json";
// 海外库存
/**
* @deprecated
*/
export default async function forStock() {
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, '飞花库存');
} 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>`;
const dest = FILTER;
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 Popup from "../class/utils/Popup";
import Log from "../class/Log";
export default class Test extends WuhuBase {
public test(): void {
new Popup("123")
new Popup(Log.getLogs());
}
}

View File

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