更新
This commit is contained in:
parent
ec7b52aa92
commit
92c807aa86
@ -4,6 +4,14 @@
|
|||||||
|
|
||||||
# CHANGE
|
# CHANGE
|
||||||
|
|
||||||
|
## 0.7.7
|
||||||
|
|
||||||
|
2022年12月7日
|
||||||
|
|
||||||
|
### 添加
|
||||||
|
|
||||||
|
- 老虎机批量购买
|
||||||
|
|
||||||
## 0.7.6
|
## 0.7.6
|
||||||
|
|
||||||
2022年12月6日
|
2022年12月6日
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wuhu-torn-helper",
|
"name": "wuhu-torn-helper",
|
||||||
"version": "0.7.6",
|
"version": "0.7.7",
|
||||||
"description": "芜湖助手",
|
"description": "芜湖助手",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -20,6 +20,7 @@ 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
|
||||||
@ -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=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();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加左侧图标
|
* 添加左侧图标
|
||||||
*/
|
*/
|
||||||
|
|||||||
128
src/class/action/SlotsHelper.ts
Normal file
128
src/class/action/SlotsHelper.ts
Normal 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
|
||||||
|
}
|
||||||
@ -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());
|
||||||
|
|||||||
@ -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 = {
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user