myHeroes

try to take over the world!myHeroes

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         myHeroes
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  try to take over the world!myHeroes
// @author       You
// @match        https://www.tampermonkey.net/scripts.php
// @include    *://play.bnbheroes.io/*
// @grant        none
// ==/UserScript==

(function() {
	function loginWallet() {
		return new Promise((resolve, reject) => {
			try {
				document
					.querySelector(".sc-eCApGN.cjAFRf.web3modal-provider-wrapper")
					.click();
				resolve("小狐狸选择成功");
			} catch (error) {
				reject(error);
			}
		});
	}

	loginWallet()
		.then(res => {
			try {
				console.log(res);
				document.querySelector(".float-end")
					.click();
				// 延时执行
				setTimeout(startFight, 10000);
			} catch (error) {
				console.log(error);
			}
		})
		.catch(err => {
			console.log(err);
		});

	function startFight() {
		//获取当前英雄血量
		let HP = document
			.querySelector(".hp-progress-detail")
			.getInnerHTML()
			.split(" ")[1]
			.split("/")[0];
		if (HP >= 200) {
			//右侧驼背
			let myHeroDom = document.querySelectorAll(
				".general-enemy.d-flex.flex-column.align-items-center.justify-content-center.p-2"
			)[1];
			//向右切换怪物箭头
			let rightArrow = myHeroDom.querySelector(".right-arrow");
			//切换到弓箭手方法
			function getArcher() {
				//获取怪兽名称
				let myHeroName = myHeroDom
					.querySelector(".text-white.fs-3.p-1")
					.getInnerHTML();
				if (myHeroName == "Red Skull Archer") {
					console.log("切换到弓箭手,开始战斗。。。");
					archerFight();
					return true;
				} else {
					rightArrow.click();
					getArcher();
				}
			}
			//弓箭手开始战斗的按钮组
			function archerFight() {
				let fightBtn = myHeroDom.querySelector(
					".btn.btn-yellow.pt-2.pb-3.ps-5.pe-5.w-auto"
				);
				console.log("战斗中...");
				fightBtn.click();
			}
			getArcher();
		} else {
			console.log(`当前英雄HP为${HP}不足200,准备切换英雄。。。`);
			//向右切换下一个英雄 (注意 获取的第一个后面不可以这样用)
			document.querySelector(".right-arrow")
				.click();
			console.log("已切换");
		}
	}

	setTimeout(loginWallet, 2000);
	//100s刷新页面获取最新HP
	setTimeout(() => {
		window.location.reload();
	}, 100000);
})();