更新
This commit is contained in:
parent
bba1335130
commit
7e236f7cd0
11
CHANGELOG.md
11
CHANGELOG.md
@ -4,7 +4,16 @@
|
||||
|
||||
# CHANGE
|
||||
|
||||
## 0.6.0
|
||||
## 0.6.2
|
||||
|
||||
2022年10月20日
|
||||
|
||||
### 添加
|
||||
|
||||
- 公司助手-火车检测开关
|
||||
- jQuery载入问题临时解决
|
||||
|
||||
## 0.6.1
|
||||
|
||||
2022年10月19日
|
||||
|
||||
|
||||
3
build.js
3
build.js
@ -16,6 +16,7 @@ let metaData = `// ==UserScript==
|
||||
// @description 托恩,起飞!
|
||||
// @author Woohoo[2687093] Sabrina_Devil[2696209]
|
||||
// @match https://www.torn.com/*
|
||||
// @updateURL https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/release.min.user.js
|
||||
// @grant GM_xmlhttpRequest
|
||||
// @grant unsafeWindow
|
||||
// @connect ljs-lyt.com
|
||||
@ -29,4 +30,4 @@ let metaData = `// ==UserScript==
|
||||
|
||||
const data = fs.readFileSync('./bundle.min.js', 'utf8');
|
||||
fs.writeFileSync('./release.min.user.js', metaData + data.replace('$$WUHU_DEV_VERSION$$', version), 'utf8');
|
||||
console.log(`新版本 ${ version } 构建完成, 耗时${ Date.now() - startTime }ms`);
|
||||
console.log(`版本 ${ version } 构建完成, build.js耗时${ Date.now() - startTime }ms`);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.6.1",
|
||||
"version": "0.6.2",
|
||||
"description": "芜湖助手",
|
||||
"dependencies": {},
|
||||
"scripts": {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -6,6 +6,7 @@ import UrlPattern from "./UrlMatch";
|
||||
import WuhuConfig from "./WuhuConfig";
|
||||
import translateMain from "../func/translate/translateMain";
|
||||
import Global from "./Global";
|
||||
import CommonUtils from "./utils/CommonUtils";
|
||||
|
||||
export default class Application {
|
||||
|
||||
@ -15,12 +16,17 @@ export default class Application {
|
||||
// 初始化
|
||||
WuHuTornHelper.getInstance();
|
||||
|
||||
// 插件设置默认值
|
||||
WuhuConfig.setDefaults();
|
||||
|
||||
// 插件图标和设置菜单
|
||||
ZhongIcon.getInstance();
|
||||
|
||||
// TODO 临时关闭光速跑路
|
||||
WuhuConfig.set('quickFinishAtt', 3);
|
||||
|
||||
// TODO 临时检测jquery
|
||||
if (typeof $ === "function") {
|
||||
// 所有页面通用
|
||||
Common.getInstance().resolve();
|
||||
|
||||
@ -29,5 +35,17 @@ export default class Application {
|
||||
|
||||
// 翻译
|
||||
if (WuhuConfig.get('transEnable')) translateMain(Global.getInstance().href);
|
||||
} else {
|
||||
CommonUtils.getInstance().jQueryReady().then(() => {
|
||||
// 所有页面通用
|
||||
Common.getInstance().resolve();
|
||||
|
||||
// URL匹配
|
||||
UrlPattern.getInstance().resolve();
|
||||
|
||||
// 翻译
|
||||
if (WuhuConfig.get('transEnable')) translateMain(Global.getInstance().href);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,12 +65,12 @@ export class Common extends WuhuBase {
|
||||
* 清除多余的脚本
|
||||
* TODO 无效、弃用
|
||||
*/
|
||||
if (WuhuConfig.get('removeScripts') && false) {
|
||||
document.querySelectorAll('script[src*="google"]').forEach(item => item.remove());
|
||||
document.querySelectorAll('#gtm_tag').forEach(item => item.remove());
|
||||
document.querySelectorAll('script[src*="chat/gonline"]').forEach(item => item.remove());
|
||||
document.querySelectorAll('head script[nonce]').forEach(item => item.remove());
|
||||
}
|
||||
// if (WuhuConfig.get('removeScripts') && false) {
|
||||
// document.querySelectorAll('script[src*="google"]').forEach(item => item.remove());
|
||||
// document.querySelectorAll('#gtm_tag').forEach(item => item.remove());
|
||||
// document.querySelectorAll('script[src*="chat/gonline"]').forEach(item => item.remove());
|
||||
// document.querySelectorAll('head script[nonce]').forEach(item => item.remove());
|
||||
// }
|
||||
|
||||
// 存钱相关
|
||||
depoHelper();
|
||||
|
||||
@ -18,8 +18,12 @@ import StackHelper from "./action/StackHelper";
|
||||
import BuyBeerHelper from "./action/BuyBeerHelper";
|
||||
import XZMZ from "./action/XZMZ";
|
||||
|
||||
/**
|
||||
* TODO 去除jq
|
||||
*/
|
||||
export default class UrlPattern extends WuhuBase {
|
||||
className = 'UrlPattern';
|
||||
|
||||
public resolve(): void {
|
||||
let href = window.location.href;
|
||||
// 捡垃圾助手
|
||||
@ -93,13 +97,13 @@ export default class UrlPattern extends WuhuBase {
|
||||
});
|
||||
CommonUtils.elementReady('#go-to-top-btn button').then(e => e.style.display = 'none');
|
||||
}
|
||||
const $$ = document.querySelector('.content-wrapper');
|
||||
const element = document.querySelector('.content-wrapper');
|
||||
const OB = new MutationObserver(() => {
|
||||
OB.disconnect();
|
||||
// titleTrans();
|
||||
// contentTitleLinksTrans();
|
||||
trans();
|
||||
OB.observe($$, {
|
||||
OB.observe(element, {
|
||||
characterData: true,
|
||||
attributes: true,
|
||||
subtree: true,
|
||||
@ -108,8 +112,8 @@ export default class UrlPattern extends WuhuBase {
|
||||
});
|
||||
const trans = () => {
|
||||
const dom = QUICK_CRIMES_HTML;
|
||||
const is_wh_translate = $$.querySelector('.wh-translate') !== null;
|
||||
const is_captcha = $$.querySelector('div#tab-menu.captcha') !== null;
|
||||
const is_wh_translate = element.querySelector('.wh-translate') !== null;
|
||||
const is_captcha = element.querySelector('div#tab-menu.captcha') !== null;
|
||||
const $title = $('div.content-title');
|
||||
const $info = $('.info-msg-cont');
|
||||
if (!is_wh_translate && !is_captcha) {
|
||||
@ -118,7 +122,7 @@ export default class UrlPattern extends WuhuBase {
|
||||
}
|
||||
};
|
||||
trans();
|
||||
OB.observe($$, {
|
||||
OB.observe(element, {
|
||||
characterData: true,
|
||||
attributes: true,
|
||||
subtree: true,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import IGlobal from "../interface/IGlobal";
|
||||
import IWHSettings from "../interface/IWHSettings";
|
||||
import Provider from "./provider/Provider";
|
||||
import Log from "./Log";
|
||||
|
||||
export default class WuhuBase extends Provider {
|
||||
public static glob: IGlobal = null;
|
||||
@ -10,7 +11,14 @@ export default class WuhuBase extends Provider {
|
||||
* 获取 localStorage 中的 wh_trans_settings 值 (json),以对象形式返回
|
||||
*/
|
||||
public static getLocal(): IWHSettings {
|
||||
return JSON.parse(localStorage.getItem('wh_trans_settings')) || {};
|
||||
let localObject = {};
|
||||
try {
|
||||
localObject = JSON.parse(localStorage.getItem('wh_trans_settings'));
|
||||
} catch (e) {
|
||||
Log.error('解析localStorage对象出错', e);
|
||||
localStorage.setItem('wh_trans_settings', '{}');
|
||||
}
|
||||
return localObject;
|
||||
}
|
||||
|
||||
public static conditionInterrupt() {
|
||||
|
||||
@ -27,10 +27,90 @@ export default class WuhuConfig extends WuhuBase {
|
||||
config[key] = val;
|
||||
localStorage.setItem('wh_trans_settings', JSON.stringify(config));
|
||||
|
||||
if (isNotify)
|
||||
new Alert('已保存设置')
|
||||
if (isNotify) new Alert('已保存设置')
|
||||
new Promise(() => callback()).then();
|
||||
Log.info(`值变更:[${ key }] ${ prev } -> ${ val }`);
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查类型不符合时设置为默认值
|
||||
*/
|
||||
public static setDefaults(): void {
|
||||
Log.info('设置默认值开始');
|
||||
let count = 0;
|
||||
[
|
||||
// 开启翻译
|
||||
{ key: 'transEnable', val: false },
|
||||
// 快速犯罪
|
||||
{ key: 'quickCrime', val: true },
|
||||
// 任务助手
|
||||
{ key: 'missionHint', val: true },
|
||||
// 小镇攻略
|
||||
{ key: 'xmasTownWT', val: true },
|
||||
// 小镇提醒
|
||||
{ key: 'xmasTownNotify', val: true },
|
||||
// 起飞爆e
|
||||
{ key: 'energyAlert', val: true },
|
||||
// 飞行闹钟
|
||||
{ key: 'trvAlarm', val: true },
|
||||
// 啤酒提醒
|
||||
{ key: '_15Alarm', val: true },
|
||||
// 捡垃圾助手
|
||||
{ key: 'cityFinder', val: false },
|
||||
// 叠E保护
|
||||
{ key: 'SEProtect', val: false },
|
||||
// PT一键购买
|
||||
{ key: 'ptQuickBuy', val: false },
|
||||
// 光速拔刀 6-关闭
|
||||
{ key: 'quickAttIndex', val: 2 },
|
||||
// 光速跑路 0-leave 1-mug 2-hos 3-关闭
|
||||
{ key: 'quickFinishAtt', val: 3 },
|
||||
// 自动开打和结束
|
||||
{ key: 'autoStartFinish', val: false },
|
||||
/**
|
||||
* @deprecated 废弃
|
||||
*/
|
||||
{ key: 'attRelocate', val: true },
|
||||
// 攻击自刷新 0-无间隔 1-5s 6-关闭
|
||||
{ key: 'attReload', val: 6 },
|
||||
// 价格监视
|
||||
{ key: 'priceWatcher', val: { xan: -1, pt: -1 } },
|
||||
// 开发者模式
|
||||
{ key: 'isDev', val: false },
|
||||
// 啤酒提醒时间
|
||||
{ key: '_15AlarmTime', val: 50 },
|
||||
// 4条转跳
|
||||
{ key: 'barsRedirect', val: true },
|
||||
// 浮动存钱框
|
||||
{ key: 'floatDepo', val: true },
|
||||
// 公司转跳存钱
|
||||
{ key: 'companyRedirect', val: true },
|
||||
// 收起公司冰蛙效率表
|
||||
{ key: 'companyBWCollapse', val: true },
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
{ key: 'removeScripts', val: true },
|
||||
// 海外警告
|
||||
{ key: 'abroadWarning', val: true },
|
||||
// 落地转跳
|
||||
{ key: 'landedRedirect', val: '' },
|
||||
// 任何位置一键存钱
|
||||
{ key: 'companyDepositAnywhere', val: false },
|
||||
// 火车提醒时间
|
||||
{ key: 'CHTrainsDetect', val: 0 },
|
||||
// 火车提醒开关
|
||||
{ key: 'CHTrainsDetectSwitch', val: true },
|
||||
|
||||
// 危险行为⚠️
|
||||
{ key: 'dangerZone', val: false },
|
||||
].forEach(df => {
|
||||
if (typeof WuhuConfig.get(df.key) !== typeof df.val) {
|
||||
WuhuConfig.set(df.key, df.val);
|
||||
count++;
|
||||
}
|
||||
});
|
||||
Log.info('设置默认值结束,新:' + count);
|
||||
}
|
||||
}
|
||||
@ -40,8 +40,7 @@ export default class ZhongIcon extends WuhuBase {
|
||||
public constructor() {
|
||||
Log.info('ZhongIcon初始化, 设置图标开始');
|
||||
super();
|
||||
this.setDefaultSettings()
|
||||
.constructWuhuSettingList()
|
||||
this.constructWuhuSettingList()
|
||||
.constructMenuList()
|
||||
.insert2Dom();
|
||||
Log.info('设置图标结束, ZhongIcon初始化结束');
|
||||
@ -1013,6 +1012,14 @@ export default class ZhongIcon extends WuhuBase {
|
||||
dictName: 'companyDepositAnywhere',
|
||||
tip: '在所有页面显示一键存钱按钮,Torn OK状态下可用,此功能未完全测试无害,使用请慎重',
|
||||
});
|
||||
// 火车检测开关
|
||||
list.push({
|
||||
domType: 'checkbox',
|
||||
domId: null,
|
||||
domText: '火车检测',
|
||||
dictName: 'CHTrainsDetectSwitch',
|
||||
tip: '检测明日火车是否会超出上限,需要系统通知权限'
|
||||
});
|
||||
|
||||
// 啤酒
|
||||
list.push({
|
||||
@ -1242,78 +1249,6 @@ export default class ZhongIcon extends WuhuBase {
|
||||
Log.info('构造设置列表结束' + timer.getTimeMs());
|
||||
return this;
|
||||
}
|
||||
|
||||
// 默认设置
|
||||
private setDefaultSettings(): ZhongIcon {
|
||||
Log.info('设置默认值开始');
|
||||
let count = 0;
|
||||
[
|
||||
// 开启翻译
|
||||
{ key: 'transEnable', val: false },
|
||||
// 快速犯罪
|
||||
{ key: 'quickCrime', val: true },
|
||||
// 任务助手
|
||||
{ key: 'missionHint', val: true },
|
||||
// 小镇攻略
|
||||
{ key: 'xmasTownWT', val: true },
|
||||
// 小镇提醒
|
||||
{ key: 'xmasTownNotify', val: true },
|
||||
// 起飞爆e
|
||||
{ key: 'energyAlert', val: true },
|
||||
// 飞行闹钟
|
||||
{ key: 'trvAlarm', val: true },
|
||||
// 啤酒提醒
|
||||
{ key: '_15Alarm', val: true },
|
||||
// 捡垃圾助手
|
||||
{ key: 'cityFinder', val: false },
|
||||
// 叠E保护
|
||||
{ key: 'SEProtect', val: false },
|
||||
// PT一键购买
|
||||
{ key: 'ptQuickBuy', val: false },
|
||||
// 光速拔刀 6-关闭
|
||||
{ key: 'quickAttIndex', val: 2 },
|
||||
// 光速跑路 0-leave 1-mug 2-hos 3-关闭
|
||||
{ key: 'quickFinishAtt', val: 3 },
|
||||
// 自动开打和结束
|
||||
{ key: 'autoStartFinish', val: false },
|
||||
// 废弃
|
||||
{ key: 'attRelocate', val: true },
|
||||
// 攻击自刷新 0-无间隔 1-5s 6-关闭
|
||||
{ key: 'attReload', val: 6 },
|
||||
// 价格监视
|
||||
{ key: 'priceWatcher', val: { xan: -1, pt: -1 } },
|
||||
// 开发者模式
|
||||
{ key: 'isDev', val: false },
|
||||
// 啤酒提醒时间
|
||||
{ key: '_15AlarmTime', val: 50 },
|
||||
// 4条转跳
|
||||
{ key: 'barsRedirect', val: true },
|
||||
// 浮动存钱框
|
||||
{ key: 'floatDepo', val: true },
|
||||
// 公司转跳存钱
|
||||
{ key: 'companyRedirect', val: true },
|
||||
// 收起公司冰蛙效率表
|
||||
{ key: 'companyBWCollapse', val: true },
|
||||
// 清除多余的脚本
|
||||
{ key: 'removeScripts', val: true },
|
||||
// 海外警告
|
||||
{ key: 'abroadWarning', val: true },
|
||||
// 落地转跳
|
||||
{ key: 'landedRedirect', val: '' },
|
||||
// 任何位置一键存钱
|
||||
{ key: 'companyDepositAnywhere', val: false },
|
||||
|
||||
// 危险行为⚠️
|
||||
{ key: 'dangerZone', val: false },
|
||||
].forEach(df => {
|
||||
if (typeof WuhuConfig.get(df.key) !== typeof df.val) {
|
||||
WuhuConfig.set(df.key, df.val);
|
||||
count++;
|
||||
}
|
||||
});
|
||||
Log.info('设置默认值结束,新:' + count);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
interface MenuItemConfig {
|
||||
|
||||
@ -14,7 +14,7 @@ export default class CompanyHelper extends WuhuBase {
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
this.trainsDetect().then();
|
||||
WuhuConfig.get('CHTrainsDetectSwitch') && this.trainsDetect().then();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -136,7 +136,7 @@ export default class LotteryHelper extends WuhuBase {
|
||||
method: 'GET',
|
||||
referrer: '/loader.php?sid=lottery',
|
||||
});
|
||||
await InfoUtils.getInstance().sleep(this.mathUtils.getRandomInt(20, 50));
|
||||
await CommonUtils.getInstance().sleep(this.mathUtils.getRandomInt(20, 50));
|
||||
i++;
|
||||
this.desc.innerHTML = `已买${ i }张彩票`;
|
||||
this.status.innerHTML = `${ i }/${ inputNumber }`;
|
||||
|
||||
@ -11,8 +11,8 @@ export default class Starter {
|
||||
try {
|
||||
T.main();
|
||||
} catch (e) {
|
||||
Log.error('加载出错');
|
||||
Log.error('[Starter]', e.message || JSON.stringify(e));
|
||||
Log.error('[Starter]加载出错信息: ' + e.message);
|
||||
Log.info('错误堆栈: ', e.stack);
|
||||
}
|
||||
let runTime: number = (performance.now() - started) | 0;
|
||||
Log.info(`芜湖脚本完成加载, 耗时${ runTime }ms`);
|
||||
|
||||
@ -6,6 +6,7 @@ import AjaxFetchOption from "../../interface/AjaxFetchOption";
|
||||
import Alert from "./Alert";
|
||||
import LOADING_IMG_HTML from "../../static/html/loading_img.html";
|
||||
import Timer from "./Timer";
|
||||
import FetchUtils from "./FetchUtils";
|
||||
|
||||
export default class CommonUtils extends WuhuBase {
|
||||
className = 'CommonUtils';
|
||||
@ -218,4 +219,32 @@ export default class CommonUtils extends WuhuBase {
|
||||
nowUtc.setMilliseconds(0);
|
||||
return nowUtc > tar;
|
||||
}
|
||||
|
||||
public jQueryReady(): Promise<null> {
|
||||
Log.info('等待jQuery加载中...');
|
||||
FetchUtils.getInstance().fetchText('/js/script/lib/jquery-1.8.2.js?v=f9128651g')
|
||||
.then(res => window.eval(res));
|
||||
let intervalId = window.setInterval(() => {
|
||||
Log.info('仍在等待jQuery加载中...');
|
||||
}, 1000);
|
||||
return new Promise(async resolve => {
|
||||
while (true) {
|
||||
if (typeof window.$ === 'function') break;
|
||||
await this.sleep(100);
|
||||
}
|
||||
window.clearInterval(intervalId);
|
||||
Log.info('jQuery已加载');
|
||||
resolve(null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待毫秒数
|
||||
* @param {Number} ms 毫秒
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public sleep(ms: number): Promise<null> {
|
||||
let time = Math.max(ms, 10);
|
||||
return new Promise(resolve => setTimeout(() => resolve(null), time));
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@ import CommonUtils from "./CommonUtils";
|
||||
|
||||
export default class InfoUtils extends WuhuBase {
|
||||
className = 'InfoUtils';
|
||||
|
||||
/**
|
||||
* 返回玩家信息的对象 { playername: string, userID: number }
|
||||
* @return {PlayerInfo} rs
|
||||
@ -30,7 +31,7 @@ export default class InfoUtils extends WuhuBase {
|
||||
let c = 0;
|
||||
while (!sessionStorage.getItem(field) && c < 50) {
|
||||
c++;
|
||||
await this.sleep(10);
|
||||
await CommonUtils.getInstance().sleep(10);
|
||||
}
|
||||
if (sessionStorage.getItem(field)) {
|
||||
ret = JSON.parse(sessionStorage.getItem(field));
|
||||
@ -54,14 +55,4 @@ export default class InfoUtils extends WuhuBase {
|
||||
public async getUserState() {
|
||||
return (await this.getSessionData()).headerData.user.state;
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待毫秒数
|
||||
* @param {Number} ms 毫秒
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public sleep(ms) {
|
||||
let time = Math.max(ms, 10);
|
||||
return new Promise(resolve => setTimeout(() => resolve(null), time));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user