import WuhuBase from "../WuhuBase"; import XUNZHAOMUZHUANG_HTML from "../../static/html/xunzhaomuzhuang/index.html"; import * as MUZHUANG_ID_LIST_JSON from "../../static/json/muzhuang_id_list.json"; import Log from "../Log"; import CommonUtils from "../utils/CommonUtils"; import XUNZHAOMUZHUANG_CSS from "../../static/css/xunzhaomuzhuang.css"; import TornStyleBlock from "../utils/TornStyleBlock"; /** * 寻找木桩 * /item.php?temp=4#xunzhaomuzhuang */ export default class XZMZ extends WuhuBase { className = 'XZMZ'; private readonly mainRoleContainer: HTMLElement; private readonly IDList: number[]; private readonly btn: HTMLButtonElement; private readonly tips: HTMLElement; private counter: number; public constructor() { super(); CommonUtils.addStyle(XUNZHAOMUZHUANG_CSS); this.mainRoleContainer = document.querySelector('div[role="main"]'); let block = new TornStyleBlock('寻找木桩'); block.setContent(XUNZHAOMUZHUANG_HTML); this.mainRoleContainer.append(block.getBase()); this.IDList = MUZHUANG_ID_LIST_JSON.default; this.btn = block.querySelector('#deadman-start-btn') as HTMLButtonElement; this.tips = block.querySelector('#deadman_tips'); block.querySelector('#deadman-start-btn').addEventListener('click', () => { this.mainRoleContainer.querySelector('#table-body').innerHTML = ''; this.btn.disabled = true; this.StartSearch(); }); } private StartSearch() { this.counter = this.IDList.length; const tips = this.tips; tips.innerText = "---寻找中,长按目标名字弹出迷你档案---"; for (const id of this.IDList) { this.SearchDeadman(id); } } private SearchDeadman(id) { CommonUtils.ajaxFetch({ url: window.addRFC('https://www.torn.com/profiles.php?step=getProfileData&XID=' + id), method: 'GET' }).then((res) => res.json() ) .then((res) => { this.counter--; if (res.userStatus.status.type === 'ok') { this.addRow({ player_id: res.user.userID, name: res.userInformation.name, level: res.userInformation.level }); } 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) } }) .catch(e => { Log.error(e) }); } private addRow(data) { let $parentNode = this.mainRoleContainer.querySelector('#table-body'), $node = ''; $node += '' + data.player_id + '' $node += `${ data.name }`; $node += '' + data.level + '' $node += '攻击' $parentNode.insertAdjacentHTML('beforeend', $node) } }