更新
This commit is contained in:
parent
0797f498eb
commit
32462d2f10
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.5.4",
|
||||
"version": "0.5.5",
|
||||
"description": "芜湖助手",
|
||||
"dependencies": {},
|
||||
"scripts": {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -55,7 +55,14 @@ export default class Log {
|
||||
private static saveLogs(...o) {
|
||||
o.forEach(item => {
|
||||
if (typeof item === 'string') this.logs += item;
|
||||
else this.logs += ` [${ item.toString() }] [${ JSON.stringify(item) }] `;
|
||||
else {
|
||||
let json = '{}';
|
||||
try {
|
||||
json = JSON.stringify(item);
|
||||
} catch {
|
||||
}
|
||||
this.logs += ` [${ item.toString() }] [${ json }] `;
|
||||
}
|
||||
})
|
||||
this.logs += '\r\n';
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import ADD_BEER_HEAD_HTML from "../static/html/buyBeer/add_beer_head.html";
|
||||
import QUICK_CRIMES_HTML from "../static/html/quick_crimes.html";
|
||||
import RW_RIDER_HTML from "../static/html/rw_rider.html";
|
||||
import christmasTownHelper from "../func/module/christmasTownHelper";
|
||||
import LotteryHelper from "./action/LotteryHelper";
|
||||
|
||||
export default class UrlPattern extends WuhuBase {
|
||||
static resolve() {
|
||||
@ -265,5 +266,10 @@ export default class UrlPattern extends WuhuBase {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 彩票助手
|
||||
if (href.includes('loader.php?sid=lottery')) {
|
||||
LotteryHelper.getInstance().init();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -25,8 +25,8 @@ import QUICK_CRIMES_HTML from "../static/html/quick_crimes.html";
|
||||
import DEV_DETAILS_HTML from "../static/html/zhong/setting/dev_details.html";
|
||||
import QUICK_FLY_CSS from "../static/css/quick_fly.css";
|
||||
import QUICK_LINK_CSS from "../static/css/quick_link.css";
|
||||
import BuyBeerHelper from "./action/BuyBeerHelper";
|
||||
import MDUtils from "./utils/MDUtils";
|
||||
import InfoUtils from "./utils/InfoUtils";
|
||||
|
||||
export default class ZhongIcon extends WuhuBase {
|
||||
public static ZhongNode: MyHTMLElement = null;
|
||||
@ -765,9 +765,29 @@ export default class ZhongIcon extends WuhuBase {
|
||||
clickFunc: async function () {
|
||||
Log.info('测试开始');
|
||||
|
||||
try {
|
||||
|
||||
Log.info(ZhongIcon.getPool());
|
||||
|
||||
Log.info('is_running', BuyBeerHelper.getInstance().is_running());
|
||||
|
||||
// Log.info(await CommonUtils.ajaxFetch({
|
||||
// url: window.addRFC('https://www.torn.com/loader.php?sid=lotteryPlay&step=buyTicket&lotteryID=1'),
|
||||
// method: 'get',
|
||||
// referrer: '/loader.php?sid=lottery',
|
||||
// }));
|
||||
|
||||
} catch (e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
// window.setImmediate(async () => {
|
||||
let i = 0;
|
||||
while (i < 10) {
|
||||
await InfoUtils.getInstance().sleep(5000);
|
||||
Log.info(performance.now());
|
||||
i++;
|
||||
}
|
||||
// });
|
||||
|
||||
Log.info('测试结束');
|
||||
},
|
||||
|
||||
164
src/class/action/LotteryHelper.ts
Normal file
164
src/class/action/LotteryHelper.ts
Normal file
@ -0,0 +1,164 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import Log from "../Log";
|
||||
import InfoUtils from "../utils/InfoUtils";
|
||||
import MathUtils from "../utils/MathUtils";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
|
||||
export default class LotteryHelper extends WuhuBase {
|
||||
private loopFlag = true;
|
||||
|
||||
private container: HTMLElement = null;
|
||||
private title: HTMLElement = null;
|
||||
private radioDaily: HTMLInputElement = null;
|
||||
private radioWeekly: HTMLInputElement = null;
|
||||
private radioMonthly: HTMLInputElement = null;
|
||||
private time: HTMLInputElement = null;
|
||||
private startBtn: HTMLButtonElement = null;
|
||||
private stopBtn: HTMLButtonElement = null;
|
||||
private progressBar: HTMLElement = null;
|
||||
private status: HTMLElement = null;
|
||||
private desc: HTMLElement = null;
|
||||
|
||||
private readonly mathUtils = MathUtils.getInstance();
|
||||
|
||||
public init() {
|
||||
let startTime = performance.now();
|
||||
Log.info('彩票助手初始化开始');
|
||||
|
||||
this.container = document.createElement('div');
|
||||
this.title = document.createElement('div');
|
||||
let radioLabelDaily = document.createElement('label');
|
||||
let radioLabelWeekly = document.createElement('label');
|
||||
let radioLabelMonthly = document.createElement('label');
|
||||
this.radioDaily = document.createElement('input');
|
||||
this.radioWeekly = document.createElement('input');
|
||||
this.radioMonthly = document.createElement('input');
|
||||
this.time = document.createElement('input');
|
||||
this.startBtn = document.createElement('button');
|
||||
this.stopBtn = document.createElement('button');
|
||||
this.progressBar = document.createElement('div');
|
||||
this.status = document.createElement('div');
|
||||
this.desc = document.createElement('p');
|
||||
let {
|
||||
container,
|
||||
title,
|
||||
radioDaily,
|
||||
radioWeekly,
|
||||
radioMonthly,
|
||||
time,
|
||||
startBtn,
|
||||
stopBtn,
|
||||
progressBar,
|
||||
status,
|
||||
desc
|
||||
} = this;
|
||||
|
||||
container.classList.add('cont-gray', 'top-round');
|
||||
title.innerHTML = '彩票助手';
|
||||
title.classList.add('title-black', 'm-top10', 'top-round');
|
||||
title.style.marginBottom = '0.5em';
|
||||
radioDaily.type = 'radio';
|
||||
radioDaily.name = 'lottery_type';
|
||||
radioDaily.checked = true;
|
||||
radioWeekly.type = 'radio';
|
||||
radioWeekly.name = 'lottery_type';
|
||||
radioMonthly.type = 'radio';
|
||||
radioMonthly.name = 'lottery_type';
|
||||
time.type = 'number';
|
||||
time.placeholder = '填入购买数量';
|
||||
time.style.padding = '0.5em';
|
||||
time.style.margin = '0 0 0.5em 0.5em';
|
||||
startBtn.innerHTML = '开始';
|
||||
startBtn.addEventListener('click', () => this.start());
|
||||
startBtn.classList.add('torn-btn');
|
||||
stopBtn.innerHTML = '终止';
|
||||
stopBtn.disabled = true;
|
||||
stopBtn.addEventListener('click', () => this.stop());
|
||||
stopBtn.classList.add('torn-btn');
|
||||
progressBar.style.width = '0';
|
||||
progressBar.style.height = '1em';
|
||||
progressBar.style.backgroundColor = '#00ff00';
|
||||
status.innerHTML = '0/0';
|
||||
status.style.marginTop = '-1em';
|
||||
status.style.textAlign = 'center';
|
||||
desc.innerHTML = '批量买彩票';
|
||||
|
||||
radioLabelDaily.append(radioDaily);
|
||||
radioLabelDaily.append(' 日彩 $100');
|
||||
radioLabelDaily.style.marginLeft = '0.5em';
|
||||
radioLabelWeekly.append(radioWeekly);
|
||||
radioLabelWeekly.append(' 周彩 $10k');
|
||||
radioLabelMonthly.append(radioMonthly);
|
||||
radioLabelMonthly.append(' 月彩 $1m');
|
||||
|
||||
container.append(title,
|
||||
radioLabelDaily, radioLabelWeekly, radioLabelMonthly, document.createElement('br'),
|
||||
time, document.createElement('br'),
|
||||
startBtn, stopBtn,
|
||||
progressBar, status, desc);
|
||||
document.querySelector('#websocketConnectionData').after(container);
|
||||
|
||||
Log.info('彩票助手初始化结束,耗时:' + (performance.now() - startTime) + 'ms');
|
||||
}
|
||||
|
||||
private async start() {
|
||||
let startTime = performance.now();
|
||||
this.loopFlag = true;
|
||||
this.stopBtn.disabled = false;
|
||||
this.startBtn.disabled = true;
|
||||
let rsMsg = null;
|
||||
|
||||
let inputNumber = parseInt(this.time.value);
|
||||
if (inputNumber > 0) {
|
||||
let msg = document.querySelector('.info-msg-wrap .msg').innerText.trim().split(' ');
|
||||
let current = {
|
||||
money: (await InfoUtils.getInstance().getSessionData()).user.money.value,
|
||||
token: parseInt(msg[4])
|
||||
};
|
||||
let lotteryType = 1;
|
||||
if (this.radioWeekly.checked) lotteryType = 2;
|
||||
else if (this.radioMonthly.checked) lotteryType = 3;
|
||||
// 共计花费
|
||||
let totalCost = [null, 100, 10000, 1000000][lotteryType] * inputNumber;
|
||||
if (totalCost <= current.money && inputNumber <= current.token) {
|
||||
this.desc.innerHTML = '正在开始';
|
||||
this.status.innerHTML = `0/${ inputNumber }`;
|
||||
this.progressBar.style.width = '0';
|
||||
let i = 0;
|
||||
while (i < inputNumber) {
|
||||
if (!this.loopFlag) {
|
||||
rsMsg = `终止操作,已完成${ i }/${ inputNumber }`;
|
||||
break;
|
||||
}
|
||||
await CommonUtils.ajaxFetch({
|
||||
url: window.addRFC('https://www.torn.com/loader.php?sid=lotteryPlay&step=buyTicket&lotteryID=' + lotteryType),
|
||||
method: 'get',
|
||||
referrer: '/loader.php?sid=lottery',
|
||||
});
|
||||
await InfoUtils.getInstance().sleep(this.mathUtils.getRandomInt(20, 50));
|
||||
i++;
|
||||
this.desc.innerHTML = `已买${ i }张彩票`;
|
||||
this.status.innerHTML = `${ i }/${ inputNumber }`;
|
||||
this.progressBar.style.width = ((i / inputNumber * 100) | 0) + '%';
|
||||
}
|
||||
if (this.loopFlag) rsMsg = '批量购买完成';
|
||||
} else {
|
||||
rsMsg = '代币或现金不足';
|
||||
Log.warn({ totalCost, inputNumber });
|
||||
}
|
||||
} else {
|
||||
rsMsg = '输入有误';
|
||||
}
|
||||
|
||||
this.desc.innerHTML = '结束: ' + (rsMsg ? rsMsg + `<br/>耗时:${ (performance.now() - startTime) | 0 }ms` : '出错了');
|
||||
|
||||
this.stopBtn.disabled = true;
|
||||
this.startBtn.disabled = false;
|
||||
}
|
||||
|
||||
private stop() {
|
||||
this.loopFlag = false;
|
||||
this.stopBtn.disabled = true;
|
||||
this.startBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
@ -17,7 +17,7 @@ export default class TravelItem extends WuhuBase {
|
||||
if (!WindowActiveState.getInstance().get()) return;
|
||||
Log.info('fetching https://yata.yt/api/v1/travel/export/');
|
||||
const res = await CommonUtils.COFetch('https://yata.yt/api/v1/travel/export/');
|
||||
Log.info('fetch returned: ', res);
|
||||
Log.info({ 'fetch returned': res });
|
||||
this.obj = JSON.parse(res);
|
||||
}, 30 * 1000);
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ export default class InfoUtils extends WuhuBase {
|
||||
* @param {Number} ms 毫秒
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
private sleep(ms) {
|
||||
public sleep(ms) {
|
||||
let time = Math.max(ms, 10);
|
||||
return new Promise(resolve => setTimeout(() => resolve(null), time));
|
||||
}
|
||||
|
||||
6
src/class/utils/TornStyleBlock.ts
Normal file
6
src/class/utils/TornStyleBlock.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export default class TornStyleBlock {
|
||||
private elem: HTMLElement;
|
||||
|
||||
constructor(title: string) {
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import Starter from "./class/provider/Starter";
|
||||
import Application from "./class/Application";
|
||||
|
||||
(function () {
|
||||
// (function () {
|
||||
Starter.run(Application)
|
||||
})();
|
||||
// })();
|
||||
Loading…
x
Reference in New Issue
Block a user