Greasy Fork

Greasy Fork is available in English.

我的文字修仙全靠刷 脚本

修仙小游戏脚本

当前为 2024-08-05 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         我的文字修仙全靠刷 脚本
// @namespace    http://tampermonkey.net/
// @version      2024.8.5-4.1
// @description  修仙小游戏脚本
// @author       mj
// @match        https://*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// @license MIT
// ==/UserScript==
const myPlayer = document.querySelector('.game-container-wrapper').__vue__.$store.state.player
let currentRoutingObject = document.querySelector('.game-container-wrapper').__vue__.$router.currentRoute.matched[0].instances.default
let myTips = currentRoutingObject.$notify
var intervalId1 = null;
var intervalId2 = null;
var intervalId3 = null;
var attackInterval = null;
var fightIntervalId = null;
var restInterval = null;
var restartIntervalId = null;
var automaticSaleOfEquipmentId = null;
var petIntervalId = null;
var boosIntervalId = null;
var boosStart = true;

setInterval(() => {
    boosStart = true;  
}, 2 * 60 * 1000);  

(function() {
    const originalSetInterval = window.setInterval;
    const intervalIds = [];
    window.setInterval = function(callback, delay) {
        const id = originalSetInterval(callback, delay);
        intervalIds.push(id);
        return id;
    };
    function clearAllIntervals() {
        intervalIds.forEach(id => clearInterval(id));
        intervalIds.length = 0;
    }
    window.clearAllIntervals = clearAllIntervals;
})();

function specifyRoutingObject(path) {
    const routerOptions = document.querySelector('.game-container-wrapper').__vue__.$router.options.routes
    return routerOptions.find(route => route.path === path).component
}

function clickButton(buttonText) {
    let buttons = document.querySelectorAll("button");
    for (let button of buttons) {
        if (button.innerText === buttonText) {
            button.click();
            return true;
        }
    }
    return false;
}

function clickButtonAndWaitForDOMUpdate(buttonName, callback) {
    if (!clickButton(buttonName)) {
        console.error(`按钮 "${buttonName}" 未找到`);
        return;
    }
    const observer = new MutationObserver((mutationsList, observer) => {
        for (let mutation of mutationsList) {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                callback();
                observer.disconnect();
                break;
            }
        }
    });
    observer.observe(document.body, { childList: true, subtree: true });
}

function createRouteListener(callback) {
    if (typeof callback !== 'function') {
      throw new Error('Callback must be a function');
    }
  
    (function(history) {
      var pushState = history.pushState;
      var replaceState = history.replaceState;
  
      history.pushState = function(state, title, url) {
        var result = pushState.apply(history, arguments);
        window.dispatchEvent(new Event('pushstate'));
        window.dispatchEvent(new Event('locationchange'));
        return result;
      };
  
      history.replaceState = function(state, title, url) {
        var result = replaceState.apply(history, arguments);
        window.dispatchEvent(new Event('replacestate'));
        window.dispatchEvent(new Event('locationchange'));
        return result;
      };
  
      window.addEventListener('popstate', function(event) {
        window.dispatchEvent(new Event('locationchange'));
      });
    })(window.history);
  
    window.addEventListener('locationchange', function() {
      setTimeout(function() {
        callback(window.location.pathname);
      }, 0);
    });
}
createRouteListener(function() {
    var wrapper = document.querySelector('.game-container-wrapper');
    if (wrapper && wrapper.__vue__) {
        currentRoutingObject = wrapper.__vue__.$router.currentRoute.matched[0].instances.default;
    } else {
        console.log('当前路由对象未定义');
    }
});

function cultivateUntilMax() {
        currentRoutingObject.startCultivate();
        currentRoutingObject.startCultivate();
        currentRoutingObject.startCultivate();
        if(document.body.innerText.includes("当前境界修为已满")) {  
            if (currentRoutingObject.stopCultivate) {
                currentRoutingObject.stopCultivate();
                clearAllIntervals();
            }
            clickButtonAndWaitForDOMUpdate("返回家里", () => {
                cultivateExplore();
            }); 
        }
}

function cultivateExplore() {
    clickButton("探索秘境");
    function checkFightStatus() {
        if (document.body.innerText.includes("恭喜你突破了")) {
            clearAllIntervals();
            document.querySelector('.game-container-wrapper').__vue__.$router.push('/')
            setTimeout(() => {
                clickButtonAndWaitForDOMUpdate("开始修炼", () => {
                    intervalId1 = setInterval(() => {
                        cultivateUntilMax();
                    }, 1000);
            }, 500)});
            return;
        }
        if (document.body.innerText.includes("被击败")) {
            clickButtonAndWaitForDOMUpdate("回家疗伤", () => {
                clearInterval(fightIntervalId);
                clearInterval(automaticSaleOfEquipmentId);
                cultivateExplore();
            });
        } else if (document.body.innerText.includes("你击败")||document.body.innerText.includes("你输了")) {
            clickButton("继续探索");
        } else {
            if (currentRoutingObject.startFight) {
                currentRoutingObject.startFight();
            }
        }
    }
    automaticSaleOfEquipmentId = setInterval(() => {
        myAutoSellEquipment();
    }, 5000);
    fightIntervalId = setInterval(checkFightStatus, 100);
}

function myAutoSellEquipment() {
    const inventory = myPlayer.inventory;
    const sellingEquipmen = myPlayer.sellingEquipmentData;
    const selling = inventory.filter(item => sellingEquipmen.includes(item.quality) && !item.lock);
    if (!selling.length) {
        return;
    }
    const strengtheningStoneTotal = selling.reduce((total, i) => {
        let level = i.level + i.level * myPlayer.reincarnation / 10;
        level = Number(level) || 0;
        return total + Math.floor(level);
    }, 0);
    myPlayer.strengtheningStone += strengtheningStoneTotal;
    myPlayer.inventory = inventory.filter(item => !sellingEquipmen.includes(item.quality) || item.lock);
    document.querySelector('.game-container-wrapper').__vue__.$store.commit('setPlayer', myPlayer);
    myTips({ title: '背包装备出售提示', message: `背包内所有非锁定装备已成功出售, 你获得了${strengtheningStoneTotal}个炼器石` });
}

function autoExplore() {
    function fightLoop() {
        if(myPlayer.level===40 && boosStart === true) {
            clickButton("世界BOSS");
            boosIntervalId = setInterval(fightBossAndCheck, 100);
            waitForIntervalToFinish();
            return;
        }
        clickButton("探索秘境");
        function checkFightStatus() {
            if (document.body.innerText.includes("被击败")) {
                clickButton("回家疗伤");
                clearInterval(fightIntervalId);
                if (!restartIntervalId) {
                    restartIntervalId = setInterval(() => {
                        fightLoop();
                        clearInterval(restartIntervalId);
                        restartIntervalId = null;
                    }, 500);
                }
            } else if (document.body.innerText.includes("你击败")|| document.body.innerText.includes("你输了")) {
                clickButton("继续探索");
            } else {
                currentRoutingObject.startFight();
            }
        }
        automaticSaleOfEquipmentId = setInterval(() => {
            myAutoSellEquipment();
        }, 5000);
        fightIntervalId = setInterval(checkFightStatus, 10);
    }
    fightLoop();
}
function waitForIntervalToFinish() {
    const checkInterval = setInterval(() => {
        if (boosStart === false) {
            clearInterval(checkInterval);
            autoExplore();
        }
    }, 100);
}

function fightBossAndCheck() {
    currentRoutingObject.fightBoss();
    let pageText = document.body.innerText;
    if (pageText.includes("太弱被击败了") || pageText.includes("你击败") ) {
        clickButton("回家疗伤");
        clearInterval(boosIntervalId);
        if (boosStart === true) {
            boosStart = false;
        }
    }
}

function autoPet() {
    if (myPlayer.health === 0) {
        document.querySelector('.game-container-wrapper').__vue__.$router.push('/');
        return;
    }
    clickButton("探索秘境")
    clickButton("收服对方")
    const failText = document.body.innerText.includes("失败");
    if (failText) {
        clickButton("发起战斗")
    }
    const successText = document.body.innerText.includes("成功");
    if (successText) {
        clickButton("继续探索")
    }
    const defeatText = document.body.innerText.includes("击败");
    if (defeatText) {
        clickButton("继续探索")
    }
}

function startAutoPet() {
    intervalId3 = setInterval(autoPet, 100);
}

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 = "0px";
        buttonContainer.style.left = "50%";
        buttonContainer.style.transform = "translateX(-50%)";
        buttonContainer.style.display = "flex";
        buttonContainer.style.gap = "10px";
        buttonContainer.style.zIndex = "99999";
        buttonContainer.style.borderRadius = "10px";
        var button1 = document.createElement("button");
        button1.innerHTML = "修炼";
        styleButton(button1);
        button1.onclick = function () {
            if (intervalId1 === null) {
                if (myPlayer.level === 40) {
                    myTips({title:'修炼提示',message:"已经修炼到最高级,无法继续自动修炼!"});
                    return;
                }
                clickButton("开始修炼");
                button1.innerHTML = "🟥修炼";
                disableOtherButtons(button2);
                disableOtherButtons(button3);
                disableOtherButtons(button4);
                console.log("自动修炼功能正在运行");
                myTips({title:'修炼提示',message:"自动修炼过程中会自动出售装备,请调整出售装备设置!"});
                intervalId1 = setInterval(() => {
                    cultivateUntilMax();
                }, 100);
            } else {
                intervalId1 = null;
                clearAllIntervals();
                button1.innerHTML = "修炼";
                enableAllButtons(button2);
                enableAllButtons(button3);
                enableAllButtons(button4);
                console.log("自动修炼功能已停止");
            }
        };
        var button2 = document.createElement("button");
        button2.innerHTML = "探索";
        styleButton(button2);
        button2.onclick = function () {
            if (intervalId2 === null) {
                intervalId2 = true;
                myTips({title:'探索提示',message:"自动探索将自动出售装备,请调整出售装备设置!"});
                currentRoutingObject.sellingEquipmentShow=true;
                const checkPopupInterval = setInterval(() => {
                    if (!currentRoutingObject.sellingEquipmentShow) {
                        button2.innerHTML = "🟥探索";
                        disableOtherButtons(button1);
                        disableOtherButtons(button3);
                        disableOtherButtons(button4);
                        console.log("自动探索功能正在运行");
                        autoExplore();
                        clearInterval(checkPopupInterval);
                    }
                }, 100);
            } else {
                intervalId2 = null;
                clearAllIntervals();
                button2.innerHTML = "探索";
                document.querySelector('.game-container-wrapper').__vue__.$router.push('/')
                enableAllButtons(button1);
                enableAllButtons(button3);
                enableAllButtons(button4);
                console.log("自动探索功能已停止");
            }
        };
        var button3 = document.createElement("button");
        button3.innerHTML = "收宠";
        styleButton(button3);
        button3.onclick = function () {
            if (intervalId3 === null) {
                myTips({title:'收宠提示',message:"自动收宠将自动出售装备,请调整出售装备设置!"});
                currentRoutingObject.sellingEquipmentShow=true;
                const checkPopupInterval = setInterval(() => {
                    if (!currentRoutingObject.sellingEquipmentShow) {
                        button3.innerHTML = "🟥收宠";
                        disableOtherButtons(button1);
                        disableOtherButtons(button2);
                        disableOtherButtons(button4);
                        console.log("自动收宠功能正在运行");
                        startAutoPet();
                        clearInterval(checkPopupInterval);
                    }
                }, 100);
            } else {
                clearAllIntervals();
                intervalId3 = null;
                button3.innerHTML = "收宠";
                enableAllButtons(button1);
                enableAllButtons(button2);
                enableAllButtons(button4);
                console.log("自动收宠功能已停止");
            }
        }
        var button4 = document.createElement("button");
        button4.innerHTML = "放宠";
        styleButton(button4);
        button4.onclick = function () {
            let confirmRelease = confirm("确定要放生所有未出战灵宠吗?");
            if (confirmRelease) {
                myPlayer.pets = [];
                document.querySelector('.game-container-wrapper').__vue__.$store.commit('setPlayer', myPlayer);
                myTips({title:'放宠提示',message:"已成功放生所有未出战灵宠!"});
                return;
            }
        }
        buttonContainer.appendChild(button1);
        buttonContainer.appendChild(button2);
        buttonContainer.appendChild(button3);
        buttonContainer.appendChild(button4);
        gameContainer.appendChild(buttonContainer);
        myTips({title:'脚本初始化',message:"脚本初始化成功!",type:"success"});
    } else {
        myTips({title:'脚本初始化',message:"脚本初始化失败,请刷新页面后重试!",type:"error"});
    }
}

function styleButton(button) {
    button.style.padding = "5px 10px";
    button.style.border = "none";
    button.style.borderRadius = "5px";
    button.style.backgroundColor = "#007bff";
    button.style.color = "white";
    button.style.fontSize = "16px";
    button.style.cursor = "pointer";
    button.style.transition = "background-color 0.3s, transform 0.3s";
    button.onmouseover = function() {
        if (!button.disabled) {
            button.style.backgroundColor = "#0056b3";
            button.style.transform = "scale(1.05)";
        }
    };
    button.onmouseout = function() {
        if (!button.disabled) {
            button.style.backgroundColor = "#007bff";
            button.style.transform = "scale(1)";
        }
    };
    button.onmousedown = function() {
        if (!button.disabled) {
            button.style.backgroundColor = "#004494";
        }
    };
    button.onmouseup = function() {
        if (!button.disabled) {
            button.style.backgroundColor = "#0056b3";
        }
    };
}

function disableOtherButtons(activeButton) {
    activeButton.disabled = true;
    activeButton.style.backgroundColor = "darkgray";
    activeButton.style.cursor = "not-allowed";
}

function enableAllButtons(activeButton) {
    activeButton.disabled = false;
    activeButton.style.backgroundColor = "#007bff";
    activeButton.style.cursor = "pointer";
}

initializeButtons();