This commit is contained in:
李万一 2022-10-26 01:37:54 +08:00
parent 8b22f3615b
commit d7e678b6dd
4 changed files with 46 additions and 32 deletions

View File

@ -4,6 +4,14 @@
# CHANGE # CHANGE
## 0.6.5
2022年10月26日
### 修改
- 寻找木桩逻辑优化
## 0.6.4 ## 0.6.4
2022年10月25日 2022年10月25日

View File

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

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,7 @@ import Log from "../Log";
import CommonUtils from "../utils/CommonUtils"; import CommonUtils from "../utils/CommonUtils";
import XUNZHAOMUZHUANG_CSS from "../../static/css/xunzhaomuzhuang.css"; import XUNZHAOMUZHUANG_CSS from "../../static/css/xunzhaomuzhuang.css";
import TornStyleBlock from "../utils/TornStyleBlock"; import TornStyleBlock from "../utils/TornStyleBlock";
import MathUtils from "../utils/MathUtils";
/** /**
* *
@ -40,20 +41,20 @@ export default class XZMZ extends WuhuBase {
this.counter = this.IDList.length; this.counter = this.IDList.length;
const tips = this.tips; const tips = this.tips;
tips.innerText = "---寻找中,长按目标名字弹出迷你档案---"; tips.innerText = "---寻找中,长按目标名字弹出迷你档案---";
for (const id of this.IDList) { window.setTimeout(async () => {
this.SearchDeadman(id); for (const id of this.IDList) {
} await this.SearchDeadman(id);
}
}, 1);
} }
private SearchDeadman(id) { private async SearchDeadman(id) {
CommonUtils.ajaxFetch({ CommonUtils.ajaxFetch({
url: window.addRFC('https://www.torn.com/profiles.php?step=getProfileData&XID=' + id), url: window.addRFC('https://www.torn.com/profiles.php?step=getProfileData&XID=' + id),
method: 'GET' method: 'GET'
}).then((res) => }).then((o) => {
res.json() this.counterHandler();
) o.json().then((res) => {
.then((res) => {
this.counter--;
if (res.userStatus.status.type === 'ok') { if (res.userStatus.status.type === 'ok') {
this.addRow({ this.addRow({
player_id: res.user.userID, player_id: res.user.userID,
@ -61,22 +62,11 @@ export default class XZMZ extends WuhuBase {
level: res.userInformation.level level: res.userInformation.level
}); });
} }
if (this.counter === 0) { }).catch(e => {
this.tips.innerText = "---寻找结束,等待60秒后重试---"; Log.error('[XZMZ] [CommonUtils.ajaxFetch]错误: ', e.message, '错误堆栈: ', e.stack);
let countdown = 60;
let timer = window.setInterval(() => {
this.btn.innerHTML = (countdown--).toString();
if (countdown === 0) {
window.clearInterval(timer);
this.btn.disabled = false;
this.btn.innerHTML = '重新寻找';
}
}, 1000)
}
})
.catch(e => {
Log.error(e)
}); });
})
await CommonUtils.getInstance().sleep(MathUtils.getInstance().getRandomInt(100, 200));
} }
private addRow(data) { private addRow(data) {
@ -88,4 +78,20 @@ export default class XZMZ extends WuhuBase {
$node += '<td style="border: 1px solid darkgray;padding:5px;text-align:center;"><a href="https://www.torn.com/loader.php?sid=attack&user2ID=' + data.player_id + '" target="_blank" class="torn-btn">攻击</a></td>' $node += '<td style="border: 1px solid darkgray;padding:5px;text-align:center;"><a href="https://www.torn.com/loader.php?sid=attack&user2ID=' + data.player_id + '" target="_blank" class="torn-btn">攻击</a></td>'
$parentNode.insertAdjacentHTML('beforeend', $node) $parentNode.insertAdjacentHTML('beforeend', $node)
} }
private counterHandler(): void {
this.counter--;
if (this.counter === 0) {
this.tips.innerText = "---寻找结束,等待60秒后重试---";
let countdown = 60;
let timer = window.setInterval(() => {
this.btn.innerHTML = (countdown--).toString();
if (countdown === 0) {
window.clearInterval(timer);
this.btn.disabled = false;
this.btn.innerHTML = '重新寻找';
}
}, 1000)
}
}
} }