This commit is contained in:
Liwanyi 2022-12-07 17:32:37 +08:00
parent ec7b52aa92
commit 92c807aa86
9 changed files with 178 additions and 19 deletions

View File

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

View File

@ -1,6 +1,6 @@
{
"name": "wuhu-torn-helper",
"version": "0.7.6",
"version": "0.7.7",
"description": "芜湖助手",
"dependencies": {},
"scripts": {

File diff suppressed because one or more lines are too long

View File

@ -20,6 +20,7 @@ import XZMZ from "./action/XZMZ";
import ProfileHelper from "./action/ProfileHelper";
import SearchHelper from "./action/SearchHelper";
import TornStyleSwitch from "./utils/TornStyleSwitch";
import SlotsHelper from "./action/SlotsHelper";
/**
* TODO jq
@ -261,6 +262,9 @@ export default class UrlPattern extends WuhuBase {
// 彩票助手
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();
}

View File

@ -43,6 +43,15 @@ export default class ZhongIcon extends WuhuBase {
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) {
if (!(x && y)) return;
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

@ -164,7 +164,7 @@ export default class CommonUtils extends WuhuBase {
resolve(element as HTMLElement);
});
});
setTimeout(() => {
window.setTimeout(() => {
observer.disconnect();
Log.error(`等待元素超时! [${ 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) {
let { url, referrer = '/', method, body = null } = opt;
let req_params: RequestInit = {

View File

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