Greasy Fork

Greasy Fork is available in English.

Gooboo辅助

循环学习、参加考试、使用装备

当前为 2023-12-06 提交的版本,查看 最新版本

// ==UserScript==
// @name         Gooboo辅助
// @license      MIT
// @namespace    http://tampermonkey.net/
// @homepage     http://greasyfork.icu/zh-CN/scripts/481441-gooboo辅助
// @version      2.0
// @description  循环学习、参加考试、使用装备
// @author       jasmineamber
// @match        https://gityxs.github.io/gooboo/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=github.io
// @require       https://cdn.jsdelivr.net/npm/[email protected]/bignumber.min.js
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_notification
// ==/UserScript==

(function() {
    'use strict';

    // 菜单列表
    var menu_ALL = [
        ['menu_study_math', '[学校]数学-学习', '[学校]数学-学习', false, math, '1'],
        ['menu_study_literature', '[学校]文学-学习', '[学校]文学-学习', false, literature, '2'],
        ['menu_exam_math', '[学校]数学-考试', '[学校]学习数学-考试', "other", exam_math, '3'],
        ['menu_exam_literature', '[学校]文学-考试', '[学校]文学-考试', "other", exam_literature, '4'],
        ['menu_auto_skill', '[部落]使用技能', '[部落]使用技能', false, auto_skill, 'a'],
        ['menu_auto_harvest', '[农场]循环播种', '[农场]循环播种', false, auto_harvest, 'z'],
    ], menu_ID = [];

    registerMenuCommand();

    // 注册脚本菜单
    function registerMenuCommand() {
        for (let i=0;i<menu_ID.length;i++){
            GM_unregisterMenuCommand(menu_ID[i]);
        }
        for (let i=0;i<menu_ALL.length;i++){ // 循环注册脚本菜单
            let icon = '✅'
            if (menu_ALL[i][3] == 'other') {
                icon = 'ℹ️'
            }
            menu_ID[i] = GM_registerMenuCommand(`${menu_ALL[i][3]?icon:'❌'} ${menu_ALL[i][1]}`, async function(){
                if (!(menu_ALL[i][3] == 'other')) {
                    menu_ALL[i][3] = !menu_ALL[i][3]
                    menu_switch(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`,`${menu_ALL[i][2]}`);
                }
                await menu_ALL[i][4]()
            }, menu_ALL[i][5]);
        }
    }

    // 菜单开关
    function menu_switch(menu_status, Name, Tips, Title="Gooboo辅助") {
        if (menu_status == 'true'){
            GM_notification({title: Title, text: `已开启 ${Tips} 功能`, timeout: 3500});
        }else{
            GM_notification({title: Title, text: `已停止 ${Tips} 功能`, timeout: 3500});
        }
        registerMenuCommand(); // 重新注册脚本菜单
    };

    // 返回菜单信息
    function get_menu_info(menuName) {
        for (let menu of menu_ALL) {
            if (menu[0] == menuName) {
                return menu
            }
        }
    }

    // 返回菜单值
    function get_menu_value(menuName) {
        return get_menu_info(menuName)[3]
    }

    // 还原科学计数法,格式设置
    BigNumber.config({ EXPONENTIAL_AT: 1e+9 })

    // 延时函数
    function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    // 数学,自动计算
    async function auto_calc() {
        let id
        let question = null
        id = setInterval(function() {
            let answer = ""
            let next_question = document.querySelector(".question-text")
            if (next_question == null) {
                clearInterval(id);
                return
            }
            if (question === next_question.innerText) {
                return
            }
            question = next_question.innerText

            let input = document.querySelector("#answer-input-math")
            input.value = ""
            input.dispatchEvent(new Event("input"))
            if(question.indexOf("^") > 0){
                const nums = question.split("^")
                answer = Math.pow(nums[0], nums[1])
            } else if (question.startsWith("√")) {
                answer = eval(question.replace("√", ""))
                answer = Math.sqrt((answer))
            } else if (question.indexOf("e") > 0) {
                let x = BigNumber(question.split(" ")[0]);
                let y = BigNumber(question.split(" ")[2]);
                if (question.indexOf(" + ") > 0) {
                    answer = x.plus(y).toString()
                } else {
                    answer = x.minus(y).toString()
                }
            } else {
                answer = eval(question)
            }
            input.value = answer
            input.dispatchEvent(new Event("input"))
            let btn = [...document.querySelectorAll(".v-btn__content")].find(item=>item.innerText === "答题")
            btn.click()
        }, 200)
    }

    // 文学,自动输入
    function auto_writing() {
        let id
        id = setInterval(function() {
            let input = document.querySelector(".answer-input input")
            let text = ''
            let nodes = document.querySelector(".question-text .mx-2")
            if (nodes == null) {
                clearInterval(id);
                return
            }
            nodes = nodes.querySelectorAll("span")
            for (let i of nodes) {
                text += i.innerText
            }
            input.value = text
            input.dispatchEvent(new Event('input'))
        }, 200)
    }

    // 学习,定时ID
    let id_study

    // 数学 学习
    async function math(is_first=true) {
        clearInterval(id_study)
        let menu_name = "menu_study_math"
        let menu_info = get_menu_info(menu_name)
        if (!get_menu_value(menu_name)) {
            return
        }
        let target = [...document.querySelectorAll(".v-card__title")].find(item => item.innerText === "数学")
        if (!target) {
            if (is_first) {
                alert("请解锁数学科目后再使用")
                menu_info[3] = !menu_info[3]
                menu_switch(`${menu_info[3]}`,`${menu_info[0]}`,`${menu_info[2]}`);
            }
            return
        }
        let btn_study = [...target.parentNode.querySelectorAll(".v-btn__content")].find(item => item.innerText === "学习")
        if (btn_study) {
            btn_study.click()
            await sleep(2000)
            auto_calc()
        }
        id_study = setInterval(function(){math(false)}, 5000)
    }

    // 数学 考试
    async function exam_math() {
        let target = [...document.querySelectorAll(".v-card__title")].find(item => item.innerText === "数学")
        if (!target) {
            alert("请解锁数学科目后再使用")
            return
        }
        let ticket = document.querySelector(".mdi-ticket-account").nextElementSibling.querySelector(".v-progress-linear__content span").innerText
        if (ticket === "0") {
            alert("考试次数不足")
            return
        }
        let id
        let btn_exam = [...target.parentNode.querySelectorAll(".v-btn__content")].find(item => item.innerText === "参加考试")
        if (btn_exam) {
            btn_exam.click()
            await sleep(2000)
            auto_calc()
        }
    }

    // 文学
    async function literature(is_first=true) {
        clearInterval(id_study)
        let menu_name = "menu_study_literature"
        let menu_info = get_menu_info(menu_name)
        if (!get_menu_value(menu_name)) {
            return
        }
        let target = [...document.querySelectorAll(".v-card__title")].find(item => item.innerText === "文学")
        if (!target) {
            if (is_first) {
                alert("请解锁文学科目后再使用")
                menu_info[3] = !menu_info[3]
                menu_switch(`${menu_info[3]}`,`${menu_info[0]}`,`${menu_info[2]}`);
            }
            return
        }
        let btn_study = [...target.parentNode.querySelectorAll(".v-btn__content")].find(item => item.innerText === "学习")
        if (btn_study) {
            btn_study.click()
            await sleep(2000)
            auto_writing()
        }
        id_study = setInterval(function(){literature(false)}, 5000)
    }

    // 文学 考试
    async function exam_literature() {
        let target = [...document.querySelectorAll(".v-card__title")].find(item => item.innerText === "文学")
        if (!target) {
            alert("请解锁文学科目后再使用")
            return
        }
        let ticket = document.querySelector(".mdi-ticket-account").nextElementSibling.querySelector(".v-progress-linear__content span").innerText
        if (ticket === "0") {
            alert("考试次数不足")
            return
        }
        let id
        let btn_exam = [...target.parentNode.querySelectorAll(".v-btn__content")].find(item => item.innerText === "参加考试")
        if (btn_exam) {
            btn_exam.click()
            await sleep(2000)
            auto_writing()
        }
    }

    // 部落 使用装备
    async function auto_skill() {
        let menu_name = "menu_auto_skill"
        let menu_info = get_menu_info(menu_name)
        if (!get_menu_value(menu_name)) {
            return
        }
        let id
        let is_first = true
        id = setInterval(function() {
            let player = [...document.querySelectorAll("div")].find(item => item.innerText === "玩家");
            if (is_first) {
                if (player == null) {
                    alert("请在部落页面使用此功能")
                    menu_info[3] = !menu_info[3]
                    menu_switch(`${menu_info[3]}`,`${menu_info[0]}`,`${menu_info[2]}`);
                    clearInterval(id);
                    return
                } else {
                    is_first = false
                }
            } else {
                if (player == null) {
                    menu_info[3] = !menu_info[3]
                    menu_switch(`${menu_info[3]}`,`${menu_info[0]}`,`${menu_info[2]}`);
                    clearInterval(id);
                    return
                }
            }
            let skill_bar = player.parentNode.previousElementSibling
            let skills = skill_bar.querySelectorAll(".v-icon");
            [...skills].forEach(item => {
                item.click()
            })
        }, 1000)
    }
    // 农场 循环播种
    async function auto_harvest() {
        let menu_name = "menu_auto_harvest"
        let menu_info = get_menu_info(menu_name)
        if (!get_menu_value(menu_name)) {
            return
        }
        let id
        let is_first = true
        id = setInterval(function() {
            let btn_refresh = document.querySelector(".mdi-refresh");
            if (is_first) {
                if (btn_refresh == null) {
                    alert("请在农场页面使用此功能")
                    menu_info[3] = !menu_info[3]
                    menu_switch(`${menu_info[3]}`,`${menu_info[0]}`,`${menu_info[2]}`);
                    clearInterval(id);
                    return
                } else {
                    is_first = false
                }
            } else {
                if (btn_refresh == null) {
                    menu_info[3] = !menu_info[3]
                    menu_switch(`${menu_info[3]}`,`${menu_info[0]}`,`${menu_info[2]}`);
                    clearInterval(id);
                    return
                }
            }
            btn_refresh.click()
        }, 1000)
    }
})();