午安农场挂机版 1.0

如标题所示,添加该脚本后,再配置好你的openid,就可以挂机了

图片表情

话不多说,上代码

// ==UserScript==
// @name         午安农场1.0(BY baba22222)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  try to take over the world!
// @author       You
// @match        https://game.yuis.cc/
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    let isXJ = false;//是否宵禁
    let buyList = {};//商品
    let proNum = 0;//最佳商品数量
    let info = {};//用户信息
    let areaInfo = [];//良田信息
    let openid= "你的openid"

    function send(data,type){
        fetch('https://meta-backend.yuimeta.com/api/openFarm', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        })
            .then(response => response.text())
            .then(resdata => {
            let res = JSON.parse(resdata);
            if(res.code == 200){
                if(type == 'buyList'){
                    //获取经验最多
                    let maxAgeElement = res.data.reduce((max, current) => {
                        return (max.exp*max.base_yield > current.exp*max.base_yield) ? max : current;
                    });
                    buyList = maxAgeElement;
                    //nsole.log("商店菜单",buyList);
                }
                if(type == 'info'){
                    info = res.data.farm_data;
                    //nsole.log("用户信息",info);
                }
                if(type == 'areaInfo'){
                    areaInfo = res.data;
                    //nsole.log("良田信息",areaInfo);

                }
            }else if(res.code == 400){
                //nsole.log(data,type);
                //nsole.log(res.msg);
            }
        })
            .catch(error => console.error(error));
    }

    // 获取商店菜单
    function getBuyMenu(){
        let obj = {
            url: "/store",
            openid: openid,
            method: "GET",
        };
        send(obj,'buyList')
    }
    getBuyMenu();
    // 获取用户信息
    function getInfo(){
        let obj = {
            url: "/login",
            openid: openid,
            method: "POST",
        };
        send(obj,'info')
    }
    getInfo();
    // 获取良田信息
    function getAreaInfo(type){
        let obj = {
            url: "/farms/view_farm",
            openid: openid,
            method: "GET",
        };
        send(obj,type || 'areaInfo')
    }
    getAreaInfo();

    // 扩建农田
    function expand_plot(){
        let obj = {
            url: "/farms/expand_plot",
            openid: openid,
            method: "GET",
        };
        send(obj)
    }

    // 购买商品
    function buyPro(num){
        let obj = {
            data: {name: buyList.name, num:num || 1},
            method: "POST",
            openid: openid,
            url: "/store"
        };
        send(obj);
    }

    // 收菜
    function getPlot(num){
        let obj = {
            data: {plot_id: Number(num)},
            method: "POST",
            openid: openid,
            url: "/farms/harvest_crop"
        };
        send(obj,'caicai')
    }
    // 种菜
    function setPlot(num){
        let obj = {
            data: {plot_id: Number(num),crop_id: buyList.name},
            method: "POST",
            openid: openid,
            url: "/farms/plant_crop"
        };
        send(obj,'caicai')
    }

    // 种地循环
    function zdActive(){
        let obj = {
            url: "/farms/view_farm",
            openid: openid,
            method: "GET",
        };

        fetch('https://meta-backend.yuimeta.com/api/openFarm', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(obj)
        })
            .then(response => response.text())
            .then(resdata => {
            let res = JSON.parse(resdata);
            if(res.code == 200){
                areaInfo = res.data;
                //背包最佳商品数量
                let obj = res.data.warehouse.seeds.find(pro => {
                    return pro.name == buyList.name;
                });
                proNum = obj?.num;
          
                console.log("背包中"+buyList.name+"的数量为"+proNum);
                //农田
                let arr = res.data.plots;
                let isFinished = true;
                arr.map((item,i)=>{
                    if(item.plot_status == '可收获'){
                        setTimeout(function(){getPlot(item.plot_number);},i*100 + 100);
                        isFinished = false;
                        console.log("cai1 可收获 序号为"+item.plot_number);

                    }else if(item.plot_status == '未种植'){
                        setTimeout(function(){setPlot(item.plot_number);},i*200 + 100);
                        isFinished = false;
                        console.log("cai1 可种植 序号为"+item.plot_number);
                    }
                });
                if(!isFinished){
                    if(proNum<areaInfo.plots.length){
                        buyPro(areaInfo.plots.length);
                    }
                }else{
                    //nsole.log("cai1 种植完成!!!");
                };
            }else if(res.code == 400){
                //nsole.log(data,type);
                //nsole.log(res.msg);
            }
        })
            .catch(error => console.error(error));

    }

    let setInterval1 =  setInterval(()=>{
        if(!isXJ){
            zdActive();
        }
    },2000);

    let setInterval2 =setInterval(()=>{
        //-1.查询商店
        getBuyMenu();
        //0.扩建农田
        expand_plot();
    },60000);

    function runDailyAt(time, callback) {
        // 解析传入的时间字符串
        const [hour, minute] = time.split(':').map(Number);

        // 获取当前日期时间
        let now = new Date();
        let targetTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hour, minute, 0, 0);

        // 如果今天没过目标时间
        if (targetTime > now) {
            if(time == '08:00') {
                isXJ = true;
                clearInterval(setInterval1);
                clearInterval(setInterval2);
            }
        }

        // 如果今天已经过了目标时间,则跳到明天
        if (targetTime < now) {
            targetTime.setDate(targetTime.getDate() + 1);
            if(time =='19:30') {
                isXJ = true;
                clearInterval(setInterval1);
                clearInterval(setInterval2);
            }
        }

        // 计算距离目标时间的毫秒数
        const delay = targetTime - now;

        // 设置定时器,在目标时间执行回调
        const timeoutId = setTimeout(() => {
            callback(); // 执行回调函数

            // 递归调用自身,以确保每天都会执行
            runDailyAt(time, callback);
        }, delay);
    }

    // 使用示例
    runDailyAt('08:00', () => {
        isXJ = false;

    });

    // 使用示例
    runDailyAt('19:30', () => {
        isXJ = true;
        clearInterval(setInterval1);
        clearInterval(setInterval2);
    });

    //10分钟刷新一次页面
    setInterval(()=>{
        location.reload();
    },6000000)

})();