Merge remote-tracking branch 'gitlab/dev' into dev

This commit is contained in:
李万一 2022-12-19 22:32:54 +08:00
commit 2e104654bd
176 changed files with 208 additions and 36 deletions

6
.gitignore vendored
View File

@ -1,4 +1,4 @@
/node_modules /node_modules
/bundle.min.js /.fleet
/bundle.js /src/dist/bundle.min.js
/.fleet /src/dist/bundle.js

View File

@ -4,6 +4,9 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.fleet" /> <excludeFolder url="file://$MODULE_DIR$/.fleet" />
<excludeFolder url="file://$MODULE_DIR$/misc" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludePattern pattern="release.min.user.js" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

View File

@ -4,6 +4,14 @@
# CHANGE # CHANGE
## 0.7.7
2022年12月7日
### 添加
- 老虎机批量购买
## 0.7.6 ## 0.7.6
2022年12月6日 2022年12月6日

View File

@ -2,6 +2,7 @@
* 此脚本用于加入userscript meta * 此脚本用于加入userscript meta
* 并生成日期时间与版本号 * 并生成日期时间与版本号
*/ */
let startTime = Date.now(); let startTime = Date.now();
let fs = require('fs'); let fs = require('fs');
@ -16,7 +17,7 @@ let metaData = `// ==UserScript==
// @description 托恩,起飞! // @description 托恩,起飞!
// @author Woohoo[2687093] Sabrina_Devil[2696209] // @author Woohoo[2687093] Sabrina_Devil[2696209]
// @match https://www.torn.com/* // @match https://www.torn.com/*
// @updateURL https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/release.min.user.js // @downloadURL https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/release.min.user.js
// @grant GM_xmlhttpRequest // @grant GM_xmlhttpRequest
// @grant unsafeWindow // @grant unsafeWindow
// @connect ljs-lyt.com // @connect ljs-lyt.com
@ -28,6 +29,6 @@ let metaData = `// ==UserScript==
// ==/UserScript== // ==/UserScript==
` `
const data = fs.readFileSync('./bundle.min.js', 'utf8'); const data = fs.readFileSync('./dist/bundle.min.js', 'utf8');
fs.writeFileSync('./release.min.user.js', metaData + data.replace('$$WUHU_DEV_VERSION$$', version), 'utf8'); fs.writeFileSync('./release.min.user.js', metaData + data.replace('$$WUHU_DEV_VERSION$$', version), 'utf8');
console.log(`版本 ${ version } 构建完成, build.js耗时${ Date.now() - startTime }ms`); console.log(`版本 ${ version } 构建完成, build.js耗时${ Date.now() - startTime }ms`);

View File

@ -1,15 +1,11 @@
{ {
"name": "wuhu-torn-helper", "name": "wuhu-torn-helper",
"version": "0.7.6", "version": "0.7.7",
"description": "芜湖助手", "description": "芜湖助手",
"dependencies": {}, "dependencies": {},
"scripts": { "scripts": {
"release": "rollup -c rollup-prod.config.js && node build.js # 发布", "release": "rollup -c rollup-prod.config.js && node build.js",
"build": "rollup -c # 调试编译", "watch": "rollup -c -w"
"rollup_watch": "rollup -c -w # 监控",
"minify": "uglifyjs misc/wuhu-torn-helper.js -o release.min.user.js -m # 弃用",
"serve": "# 弃用",
"compile": "tsc --outDir output # 弃用"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",

File diff suppressed because one or more lines are too long

View File

@ -4,9 +4,9 @@ import { string } from "rollup-plugin-string";
import { uglify } from "rollup-plugin-uglify"; import { uglify } from "rollup-plugin-uglify";
export default { export default {
input: 'src/index.ts', input: 'src/ts/index.ts',
output: { output: {
file: 'bundle.min.js', file: 'dist/bundle.min.js',
format: 'iife', format: 'iife',
}, },
plugins: [ plugins: [

View File

@ -4,9 +4,9 @@ import json from "@rollup/plugin-json";
import { string } from "rollup-plugin-string"; import { string } from "rollup-plugin-string";
export default { export default {
input: 'src/index.ts', input: 'src/ts/index.ts',
output: { output: {
file: 'bundle.js', file: 'dist/bundle.js',
format: 'iife', format: 'iife',
}, },
plugins: [ plugins: [

View File

@ -12,6 +12,9 @@ import FetchUtils from "./utils/FetchUtils";
import ZhongIcon from "./ZhongIcon"; import ZhongIcon from "./ZhongIcon";
import Alert from "./utils/Alert"; import Alert from "./utils/Alert";
/**
*
*/
export class Common extends WuhuBase { export class Common extends WuhuBase {
className = 'Common'; className = 'Common';
@ -80,6 +83,11 @@ export class Common extends WuhuBase {
// 现金变动提醒 // 现金变动提醒
if (WuhuConfig.get('CashChangeAlert')) CommonUtils.elementReady("#user-money").then(userMoney => { if (WuhuConfig.get('CashChangeAlert')) CommonUtils.elementReady("#user-money").then(userMoney => {
new MutationObserver((mutations, observer) => { new MutationObserver((mutations, observer) => {
if (!WuhuConfig.get('CashChangeAlert')) {
observer.disconnect();
new Alert('现金变动提醒已关闭', { sysNotify: true });
return;
}
Log.info("现金变动提醒", mutations); Log.info("现金变动提醒", mutations);
mutations.forEach(item => { mutations.forEach(item => {
if (item.attributeName === 'data-money') { if (item.attributeName === 'data-money') {

View File

@ -20,8 +20,11 @@ import XZMZ from "./action/XZMZ";
import ProfileHelper from "./action/ProfileHelper"; import ProfileHelper from "./action/ProfileHelper";
import SearchHelper from "./action/SearchHelper"; import SearchHelper from "./action/SearchHelper";
import TornStyleSwitch from "./utils/TornStyleSwitch"; import TornStyleSwitch from "./utils/TornStyleSwitch";
import SlotsHelper from "./action/SlotsHelper";
/** /**
*
*
* TODO jq * TODO jq
*/ */
export default class UrlPattern extends WuhuBase { export default class UrlPattern extends WuhuBase {
@ -261,6 +264,9 @@ export default class UrlPattern extends WuhuBase {
// 彩票助手 // 彩票助手
if (href.includes('loader.php?sid=lottery')) LotteryHelper.getInstance().init(); if (href.includes('loader.php?sid=lottery')) LotteryHelper.getInstance().init();
// 老虎机助手
if (href.includes('loader.php?sid=slots')) SlotsHelper.getInstance().init();
// 搜索助手 // 搜索助手
if (href.includes('page.php?sid=UserList')) SearchHelper.getInstance().init(); if (href.includes('page.php?sid=UserList')) SearchHelper.getInstance().init();
} }

View File

@ -37,4 +37,4 @@ export default class WuhuBase extends Provider {
return this.className; return this.className;
} }
} }

View File

@ -7,6 +7,9 @@ import Log from "./Log";
import WuhuConfig from "./WuhuConfig"; import WuhuConfig from "./WuhuConfig";
import COMMON_CSS from "../static/css/common.css"; import COMMON_CSS from "../static/css/common.css";
/**
*
*/
export default class WuHuTornHelper extends WuhuBase { export default class WuHuTornHelper extends WuhuBase {
className = 'WuHuTornHelper'; className = 'WuHuTornHelper';

View File

@ -43,6 +43,15 @@ export default class ZhongIcon extends WuhuBase {
Log.info('设置图标结束, ZhongIcon初始化结束'); Log.info('设置图标结束, ZhongIcon初始化结束');
} }
public updateCashView(content: string): void {
if (!this.cashView || !ZhongIcon.ZhongNode.contains(this.cashView)) {
this.cashView = document.createElement('div');
this.cashView.id = 'wh-cash-monitor';
ZhongIcon.ZhongNode.append(this.cashView);
}
this.cashView.innerText = content;
}
private static setPosition(x: number, y: number) { private static setPosition(x: number, y: number) {
if (!(x && y)) return; if (!(x && y)) return;
if (x > 0 && x < document.documentElement.offsetWidth - 100) { if (x > 0 && x < document.documentElement.offsetWidth - 100) {
@ -53,15 +62,6 @@ export default class ZhongIcon extends WuhuBase {
} }
} }
public updateCashView(content: string): void {
if (!this.cashView || !ZhongIcon.ZhongNode.contains(this.cashView)) {
this.cashView = document.createElement('div');
this.cashView.id = 'wh-cash-monitor';
ZhongIcon.ZhongNode.append(this.cashView);
}
this.cashView.innerText = content;
}
/** /**
* *
*/ */

View File

@ -0,0 +1,128 @@
import WuhuBase from "../WuhuBase";
import TornStyleBlock from "../utils/TornStyleBlock";
import InfoUtils from "../utils/InfoUtils";
import Log from "../Log";
import FetchUtils from "../utils/FetchUtils";
import CommonUtils from "../utils/CommonUtils";
import MathUtils from "../utils/MathUtils";
/**
*
*/
export default class SlotsHelper extends WuhuBase {
className = "SlotsHelper";
private block = new TornStyleBlock("芜湖助手");
// 载入
public init() {
this.block.insert2Dom();
let nodes = this.createNodes();
this.block.append(nodes.root);
this.block.getBase().insertAdjacentHTML(
'beforeend',
'<style>#wh-slots-cont input{padding:0.5em;}' +
'#wh-slots-cont select{margin:0.5em;min-width: 3em;}</style>'
)
}
private createNodes(): SlotsHelperNodes {
let root = document.createElement('div');
root.id = 'wh-slots-cont';
// 购买数量输入框
let counterInput = document.createElement('input');
counterInput.type = 'number';
// counterInput.value = '1';
counterInput.placeholder = '数量';
// 老虎机按钮类型 对应单价
let select = document.createElement('select');
['10', '100', '1k', '10k', '100k', '1m', '10m'].forEach(option => select.innerHTML += `<option>${ option }</option>`);
// 开始按钮
let goBtn = document.createElement('button');
goBtn.innerHTML = ' GO ';
goBtn.classList.add('torn-btn');
// 消息框
let msgBox = document.createElement('div');
root.append(counterInput, select, goBtn, msgBox);
let ret = { root, counterInput, select, goBtn, msgBox };
goBtn.addEventListener('click', async ev => {
goBtn.disabled = true;
try {
await this.goBtnHandler(ev, ret)
} catch (e) {
Log.error(e.stack || e);
}
goBtn.disabled = false;
});
return ret;
}
// 按键点击处理方法
private async goBtnHandler(ev: MouseEvent, nodes: SlotsHelperNodes) {
let { counterInput, select, msgBox } = nodes;
// 现金
let cash = (await InfoUtils.getInstance().getSessionData())?.user?.money?.value;
msgBox.innerText = '等待加载中';
// 代币
let tokens: number = parseInt((await CommonUtils.querySelector('.player-info-cont #tokens')).innerText);
// 输入的购买数量
let count = parseInt(counterInput.value);
// 用户选中的单价
let price = [10, 100, 1000, 10000, 100000, 1000000, 10000000][select.selectedIndex];
if (cash < count * price || tokens < count) {
msgBox.innerText = '现金或代币不足';
throw new Error("现金或代币不足");
}
if (!count) {
msgBox.innerText = '输入有误';
throw new Error("输入有误");
}
// 总赢
let wonTotal = 0;
// 实际购买数量
let i: number;
for (i = 0; i < count; i++) {
let res: SlotsResponse = await (await FetchUtils.getInstance().ajaxFetch({
url: window.addRFC("https://www.torn.com/loader.php?sid=slotsInterface&step=play&stake=" + price),
referrer: "/loader.php?sid=slots",
method: "GET"
})).json();
wonTotal += res.moneyWon;
msgBox.innerText = `当前第${ i + 1 }轮, 共赢 $${ wonTotal }`;
if (res.tokens === 0) {
msgBox.innerHTML += '<br/>代币不足';
break;
}
await CommonUtils.getInstance().sleep(MathUtils.getInstance().getRandomInt(1800, 2400));
}
// 利润
let profit = wonTotal - i * price;
// 大于10m
let bang = Math.abs(profit) > 10000000;
msgBox.innerHTML += '<br/>已停止, ';
msgBox.innerHTML += bang ? '血' : '小';
msgBox.innerHTML += profit > 0 ? '赚' : '亏';
Log.info("[goBtnHandler]结束", { cash, tokens, count, price, wonTotal });
}
}
interface SlotsHelperNodes {
root: HTMLDivElement,
counterInput: HTMLInputElement,
select: HTMLSelectElement,
goBtn: HTMLButtonElement,
msgBox: HTMLDivElement
}
// 返回格式
interface SlotsResponse {
moneyWon: number,
tokens: number
}

View File

@ -12,8 +12,8 @@ export default class Provider {
constructor() { constructor() {
} }
// 返回继承类的实例
public static getInstance<T extends typeof Provider>(this: T): InstanceType<T> { public static getInstance<T extends typeof Provider>(this: T): InstanceType<T> {
// return this.instance ||= new this();
if (!this.instance) { if (!this.instance) {
let startTime = performance.now(); let startTime = performance.now();
this.instance = new this(); this.instance = new this();

View File

@ -164,7 +164,7 @@ export default class CommonUtils extends WuhuBase {
resolve(element as HTMLElement); resolve(element as HTMLElement);
}); });
}); });
setTimeout(() => { window.setTimeout(() => {
observer.disconnect(); observer.disconnect();
Log.error(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs()); Log.error(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs());
reject(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs()); reject(`等待元素超时! [${ selectors }]\n${ content.documentElement.tagName }, 耗时` + timer.getTimeMs());

View File

@ -26,6 +26,15 @@ export default class FetchUtils extends WuhuBase {
}); });
} }
/**
* jquery ajax xhr, X-Requested-With: XMLHttpRequest
* return fetch
* @param opt
* @param opt.url
* @param opt.referrer : /
* @param opt.method POST|GET
* @param opt.body ?
*/
public ajaxFetch(opt: AjaxFetchOption) { public ajaxFetch(opt: AjaxFetchOption) {
let { url, referrer = '/', method, body = null } = opt; let { url, referrer = '/', method, body = null } = opt;
let req_params: RequestInit = { let req_params: RequestInit = {

View File

@ -25,6 +25,9 @@ export default class InfoUtils extends WuhuBase {
} }
} }
/**
*
*/
public async getSessionData(): Promise<ISidebarData> { public async getSessionData(): Promise<ISidebarData> {
let field: string = 'sidebarData' + this.getPlayerInfo().userID; let field: string = 'sidebarData' + this.getPlayerInfo().userID;
let ret: ISidebarData = {}; let ret: ISidebarData = {};
@ -49,11 +52,18 @@ export default class InfoUtils extends WuhuBase {
}); });
} }
/**
* gym crimes
*/
public async getSidebarData() { public async getSidebarData() {
return (await this.getSessionData()).areas; return (await this.getSessionData()).areas;
} }
/**
*
* {status: string, isLoggedIn: boolean, isDonator: boolean, isTravelling: boolean, isAbroad: boolean}
*/
public async getUserState() { public async getUserState() {
return (await this.getSessionData()).headerData.user.state; return (await this.getSessionData()).headerData.user.state;
} }
} }

Some files were not shown because too many files have changed in this diff Show More