修仙小游戏脚本
目前為
// ==UserScript==
// @name 我的文字修仙全靠刷 脚本
// @namespace http://tampermonkey.net/
// @version 2024.8.2 2.1.1
// @description 修仙小游戏脚本
// @author mj
// @match https://*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// @license MIT
// ==/UserScript==
var myPlayer = document.querySelector('.game-container-wrapper').__vue__._data.player;
var intervalId1 = null;
var intervalId2 = null;
var intervalId3 = null;
var attackInterval = null;
var fightIntervalId = null;
var restInterval = null;
var isAttacking = true;
function clearAllIntervals() {
if (intervalId1 !== null) {
clearInterval(intervalId1);
intervalId1 = null;
}
if (intervalId2 !== null) {
clearInterval(intervalId2);
intervalId2 = null;
}
if (attackInterval !== null) {
clearInterval(attackInterval);
attackInterval = null;
}
if (fightIntervalId !== null) {
clearInterval(fightIntervalId);
fightIntervalId = null;
}
if (restInterval !== null) {
clearInterval(restInterval);
restInterval = null;
}
isAttacking = true;
}
function startAutoTraining() {
var buttons = document.querySelectorAll('button');
buttons.forEach(function(button) {
var buttonText = button.textContent.trim();
if (buttonText === "开始修炼" || buttonText === "继续修炼" || buttonText === "突破境界") {
button.click();
} else if (buttonText === "杀敌证道") {
button.click();
clickFightButtons();
}
});
}
function attackTheWorldBoss() {
var buttons = document.querySelectorAll("button");
buttons.forEach(function (button) {
if (button.innerText === "世界BOSS" || button.innerText === "回到家里") {
button.click();
if (document.body.innerText.includes("BOSS还未刷新")) {
isAttacking = false;
return true;
}
}
});
buttons.forEach(function (button) {
if (button.innerText === "攻击BOSS") {
button.click();
}
});
if (myPlayer.health === 0) {
console.log("血量为0,停止攻击世界boss,三分钟后重试");
isAttacking = false;
buttons.forEach((button) => {
if (button.innerText === "返回家里") {
button.click();
}
});
return true;
}
buttons.forEach(function (button) {
if (button.innerText === "发起战斗") {
button.click();
}
});
return false;
}
function startAttackingWorldBoss() {
if (attackInterval !== null) return;
attackInterval = setInterval(() => {
if (isAttacking) {
let stop = attackTheWorldBoss();
if (stop) {
clearInterval(attackInterval);
attackInterval = null;
}
}
}, 10);
}
function clickExploreButton() {
var buttons = document.querySelectorAll("button");
if (myPlayer.level === 40 && isAttacking) {
console.log("攻击世界boss");
startAttackingWorldBoss();
return;
}
buttons.forEach(function (button) {
if (button.innerText === "继续探索" || button.innerText === "探索秘境") {
button.click();
clickFightButtons();
}
if (button.innerText === "发起战斗") {
clickFightButtons();
}
});
}
function loopClickExploreButton() {
if (intervalId2 !== null) return;
intervalId2 = setInterval(function () {
clickExploreButton();
}, 10);
}
function clickFightButtons() {
function innerClickFightButtons() {
if (myPlayer.health === 0) {
clearInterval(fightIntervalId);
fightIntervalId = null;
document.querySelectorAll("button").forEach((button) => {
if (button.innerText === "立马撤退") {
button.click();
if (!document.body.innerText.includes("撤退失败,请继续战斗。")) {
clearInterval(fightIntervalId);
fightIntervalId = null;
loopClickExploreButton();
}
}
});
}
if (myPlayer.health < myPlayer.maxHealth * 0.1) {
clearInterval(fightIntervalId);
fightIntervalId = null;
autoRest();
return;
}
var fightButtonClicked = false;
var buttons = document.querySelectorAll("button");
buttons.forEach(function (button) {
if (button.innerText === "发起战斗") {
button.click();
fightButtonClicked = true;
}
if (button.innerText === "回到家里") {
button.click();
}
});
if (fightButtonClicked) {
return;
}
}
if (fightIntervalId === null) {
fightIntervalId = setInterval(innerClickFightButtons, 10);
}
}
function autoRest() {
let healthValue = myPlayer.health;
let maxHealth = myPlayer.maxHealth;
if (restInterval !== null) return;
restInterval = setInterval(() => {
document.querySelectorAll("button").forEach((button) => {
if (button.innerText === "回到家里") {
button.click();
clearInterval(restInterval);
restInterval = null;
}
});
healthValue = myPlayer.health;
if (healthValue < maxHealth) {
document.querySelectorAll("button").forEach((button) => {
if (button.innerText === "打坐休息" || button.innerText === "继续打坐") {
button.click();
}
});
}
healthValue = myPlayer.health;
if (healthValue >= maxHealth) {
document.querySelectorAll("button").forEach((button) => {
if (button.innerText === "继续干他") {
button.click();
}
});
clearInterval(restInterval);
restInterval = null;
clickFightButtons();
}
if (clickButton("发起战斗")) {
while (clickButton("发起战斗")) {
return;
}
clickButton("回到家里");
}
}, 10);
}
function clickButton(buttonText) {
let buttons = document.querySelectorAll("button");
for (let button of buttons) {
if (button.innerText === buttonText) {
button.click();
return true;
}
}
return false;
}
async function autoGetPet() {
async function exploreAndCapture() {
if (clickButton("探索秘境")) {
await new Promise(resolve => setTimeout(resolve, 10));
if (clickButton("收服对方")) {
await new Promise(resolve => setTimeout(resolve, 10));
await keepFighting();
}
}
}
async function keepFighting() {
while (clickButton("发起战斗")) {
await new Promise(resolve => setTimeout(resolve, 10));
if (clickButton("回到家里")) {
return;
}
}
}
clickButton("回到家里");
await exploreAndCapture();
}
function resetVariable() {
isAttacking = true;
}
setInterval(resetVariable, 180000);
function initializeButtons() {
var gameContainer = document.querySelector('.game-container');
if (gameContainer) {
gameContainer.style.position = "relative";
var buttonContainer = document.createElement("div");
buttonContainer.style.position = "absolute";
buttonContainer.style.top = "10px";
buttonContainer.style.left = "50%";
buttonContainer.style.transform = "translateX(-50%)";
buttonContainer.style.display = "flex";
buttonContainer.style.gap = "10px";
buttonContainer.style.zIndex = "99999";
buttonContainer.style.backgroundColor = "rgba(255, 255, 255, 0.5)";
var button1 = document.createElement("button");
button1.innerHTML = "自动修炼";
button1.onclick = function () {
if (intervalId1 === null) {
if (myPlayer.level === 40) {
console.log("已经修炼到最高级,无法继续修炼");
return;
}
intervalId1 = setInterval(startAutoTraining, 10);
button1.innerHTML = "🟥停止修炼";
button2.disabled = true;
button3.disabled = true;
console.log("自动修炼功能正在运行");
} else {
clearAllIntervals();
button1.innerHTML = "自动修炼";
button2.disabled = false;
button3.disabled = false;
console.log("自动修炼功能已停止");
}
};
var button2 = document.createElement("button");
button2.innerHTML = "自动探索";
button2.onclick = function () {
if (intervalId2 === null) {
loopClickExploreButton();
button2.innerHTML = "🟥停止探索";
button1.disabled = true;
button3.disabled = true;
console.log("自动探索功能正在运行");
} else {
clearAllIntervals();
button2.innerHTML = "自动探索";
button1.disabled = false;
button3.disabled = false;
console.log("自动探索功能已停止");
}
};
var button3 = document.createElement("button");
button3.innerHTML = "自动收宠";
button3.onclick = function () {
if (intervalId3 === null) {
intervalId3 = setInterval(autoGetPet, 10);
button3.innerHTML = "🟥停止收宠";
button1.disabled = true;
button2.disabled = true;
console.log("自动收宠功能正在运行");
} else {
clearInterval(intervalId3);
intervalId3 = null;
button3.innerHTML = "自动收宠";
button1.disabled = false;
button2.disabled = false;
console.log("自动收宠功能已停止");
}
}
buttonContainer.appendChild(button1);
buttonContainer.appendChild(button2);
buttonContainer.appendChild(button3);
gameContainer.appendChild(buttonContainer);
} else {
console.log("脚本初始化失败");
}
}
initializeButtons();