吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 562|回复: 7
上一主题 下一主题
收起左侧

[其他原创] 中国移动丝路绿洲农场自动助手2.0

[复制链接]
跳转到指定楼层
楼主
寒墨轩 发表于 2026-5-13 14:11 回帖奖励
仅限甘肃移动用户参加,不是的不用往下看了
这个是甘肃移动的农场活动,通过种植农作物出售换取金豆,可以兑换流量和话费券


参加方式:
浏览器打开地址:https://wap.gs.10086.cn/ability/ ... LY6&subChannel=flzx
登录后丝路绿洲农场助手获取到当前具体农作物就表示已经加载完成了


农场助手:
蓝奏云:https://dufq.lanzouq.com/iwXf33pccnef
使用方法:
将压缩包解压,然后在扩展程序中选择加载已解压的扩展程序,不会操作看这个https://blog.csdn.net/chouchoubuchou/article/details/146294436
部分代码:
(function() {
    'use strict';
    console.log('[农场助手] Content Script 加载中...');

    let config = {
        autoHarvest: true,
        autoPlant: true,
        autoBuySeeds: true,
        harvestInterval: 5000,
        maxBuyAmount: 50,
        minGoldReserve: 100,
        enabled: true
    };
    
    let isRunning = false;
    let checkInterval = null;
    let isInitialized = false;
    let isProcessing = false;

    let farmApi = null;
    let farmData = null;
    let plantData = null;


    function injectAndGetApi() {
        return new Promise((resolve, reject) => {
            console.log('[农场助手] 开始注入外部脚本获取API...');
            
            const script = document.createElement('script');
            script.src = chrome.runtime.getURL('inject.js');
            script.onload = function() {
                console.log('[农场助手] 注入脚本已加载');

                setTimeout(() => {
                    const api = window.__FARM_BOT_API__;
                    const data = window.__FARM_BOT_DATA__;
                    const plants = window.__FARM_BOT_PLANTS__;
                    
                    if (api && data) {
                        resolve({ success: true, apiRequest: api, jsonData: data, plantData: plants });
                    } else {
                        resolve({ success: false, apiRequest: null, jsonData: null, plantData: null });
                    }
                }, 500);
            };
            script.onerror = function(e) {
                console.error('[农场助手] 脚本加载失败:', e);
                reject(e);
            };
            
            document.head.appendChild(script);
        });
    }

    function listenForInjection() {
        return new Promise((resolve) => {
            const handleComplete = (event) => {
                document.removeEventListener('__farmBotInjectComplete__', handleComplete);
                const detail = event.detail || {};
                console.log('[农场助手] 注入完成:', detail);
                if (detail.success) {
                    farmApi = window.__FARM_BOT_API__;
                    farmData = window.__FARM_BOT_DATA__;
                    plantData = window.__FARM_BOT_PLANTS__;
                    resolve({ success: true, apiRequest: farmApi, jsonData: farmData, plantData: plantData });
                } else {
                    resolve({ success: false });
                }
            };
            
            document.addEventListener('__farmBotInjectComplete__', handleComplete);

            setTimeout(() => {
                document.removeEventListener('__farmBotInjectComplete__', handleComplete);
                resolve({ success: false, timeout: true });
            }, 5000);
        });
    }

    function waitForPageReady() {
        return new Promise((resolve) => {
            if (document.readyState === 'complete') {
                resolve();
            } else {
                window.addEventListener('load', resolve, { once: true });
            }
        });
    }

    async function init() {
        try {
            console.log('[农场助手] 开始初始化...');
            
            await waitForPageReady();
            console.log('[农场助手] 页面已加载');

            await new Promise(r => setTimeout(r, 2000));
            
            console.log('[农场助手] 正在获取API引用...');

            const [injectResult] = await Promise.all([
                injectAndGetApi(),
                listenForInjection()
            ]);
            
            if (!injectResult.success || !window.__FARM_BOT_API__) {

                const retry = await injectAndGetApi();
                if (!retry.success) {
                    throw new Error('无法获取农场API。请刷新页面重试。');
                }
            }

            farmApi = window.__FARM_BOT_API__;
            farmData = window.__FARM_BOT_DATA__;
            plantData = window.__FARM_BOT_PLANTS__;
            
            if (!farmApi || !farmData) {
                throw new Error('API未正确加载');
            }
            
            console.log('[农场助手] ✅ API获取成功!', {
                methods: Object.keys(farmApi).slice(0, 10),
                landCount: farmData.length
            });
            
            isInitialized = true;

            chrome.runtime.sendMessage({ action: 'getConfig' }, (response) => {
                if (response?.config) {
                    config = { ...config, ...response.config };
                }
                startAutomation();
            });

            chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
                handleMessage(request);
                sendResponse({ received: true });
                return true;
            });
            
            log('助手已启动 ✓');
            addVisualIndicator();
            
        } catch (error) {
            console.error('[农场助手] ❌ 初始化失败:', error);
            log('初始化失败: ' + error.message);
        }
    }

    function startAutomation() {
        if (isRunning) return;
        isRunning = true;
        mainLoop();
        checkInterval = setInterval(() => {
            if (config.enabled && !isProcessing) mainLoop();
        }, config.harvestInterval);
        log('自动化已启动 ✓');
    }

    function stopAutomation() {
        isRunning = false;
        if (checkInterval) {
            clearInterval(checkInterval);
            checkInterval = null;
        }
    }

    function handleMessage(request) {
        switch (request.action) {
            case 'forceHarvest':
                log('执行强制采摘...');
                harvestAllMature();
                break;
            case 'forcePlant':
                log('执行强制种植...');
                plantAllEmptyLands();
                break;
            case 'configUpdated':
                config = { ...config, ...request.config };
                break;
        }
    }

    async function mainLoop() {
        if (!config.enabled || isProcessing || !isInitialized) return;
        isProcessing = true;
        try {
            if (config.autoHarvest) await harvestAllMature();
            if (config.autoPlant) await plantAllEmptyLands();
            if (config.autoBuySeeds) await checkAndBuySeeds();
        } catch (error) {
            console.error('[农场助手] 主循环错误:', error);
        } finally {
            isProcessing = false;
        }
    }

    async function harvestAllMature() {
        if (!farmApi?.harvest || !farmData) return;
        
        const matureLands = farmData.filter(land => {
            if (!land || land.landState !== 1 || !land.seedType) return false;
            return isLandMature(land);
        });
        
        if (matureLands.length === 0) return;
        
        log(`发现 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$${matureLands.length} 块成熟作物,采摘中...`);
        
        for (const land of matureLands) {
            try {
                await farmApi.harvest(land.id);
                land.landState = 0;
                land.seedType = null;
                land.plantTime = null;
                await delay(500);
            } catch (e) {
                console.error(`采摘失败:`, e);
            }
        }
        log('采摘完成 ✓');
    }

    async function plantAllEmptyLands() {
        if (!farmApi?.plant || !farmData) return;
        
        const emptyLands = farmData.filter(land => {
            return land && land.landState !== 0 && (!land.seedType || land.seedType === null);
        });
        
        if (emptyLands.length === 0) return;
        
        let seeds = await getAvailableSeeds();
        if (seeds.length === 0) {
            await checkAndBuySeeds();
            seeds = await getAvailableSeeds();
            if (seeds.length === 0) return;
        }
        
        log(`发现 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$${emptyLands.length} 块空地,种植中...`);
        
        for (const land of emptyLands) {
            const available = await getAvailableSeeds();
            if (available.length === 0) break;
            const seed = selectBestSeed(available);
            if (seed) {
                try {
                    await farmApi.plant(land.id, seed.id);
                    land.landState = 1;
                    land.seedType = seed.itemId;
                    land.plantTime = new Date().toISOString();
                    await delay(500);
                } catch (e) {
                    console.error(`种植失败:`, e);
                }
            }
        }
        log('种植完成 ✓');
    }

    async function getAvailableSeeds() {
        if (!farmApi?.queryUserInventory) return [];
        try {
            const inventory = await farmApi.queryUserInventory();
            return inventory?.seedList?.filter(s => s.quantity > 0) || [];
        } catch (e) {
            return [];
        }
    }


    function selectBestSeed(seeds) {
        if (!seeds?.length) return null;
        return seeds[0];
    }


    async function checkAndBuySeeds() {
        if (!farmApi?.getShopItemList || !farmApi?.purchaseItem) return;
        
        const goldEl = document.querySelector('.goldCoins__text-exp');
        const currentGold = parseInt(goldEl?.textContent) || 0;
        if (currentGold < config.minGoldReserve) return;
        
        const seeds = await getAvailableSeeds();
        if (seeds.length > 0) return;
        

        try {
            const inventory = await farmApi.queryUserInventory();
            if (inventory?.fruitList?.length) {
                for (const fruit of inventory.fruitList) {
                    if (fruit.quantity > 0) {
                        try {
                            await farmApi.sellFruits([{ itemId: fruit.itemId, quantity: fruit.quantity }]);
                        } catch (e) {}
                    }
                }
            }
        } catch (e) {}
        

        const newGold = parseInt(document.querySelector('.goldCoins__text-exp')?.textContent) || 0;
        const available = newGold - config.minGoldReserve;
        if (available <= 0) return;
        
        try {
            const shop = await farmApi.getShopItemList();
            const seedItems = shop?.filter(i => !i.locked) || [];
            if (seedItems.length === 0) return;
            seedItems.sort((a, b) => a.priceAmount - b.priceAmount);
            const toBuy = seedItems[0];
            const amount = Math.min(Math.floor(available / toBuy.priceAmount), config.maxBuyAmount);
            if (amount > 0) {
                await farmApi.purchaseItem(toBuy.shopItemId, amount);
                log(`购买 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$${amount} 粒种子成功 ✓`);
            }
        } catch (e) {}
    }


    function isLandMature(land) {
        if (!land?.plantTime) return false;
        const elapsed = Date.now() - new Date(land.plantTime).getTime();
        const maturityTime = (land.maturityTime || 60) * 1000;
        return elapsed >= maturityTime;
    }


    function delay(ms) {
        return new Promise(r => setTimeout(r, ms));
    }


    function log(message) {
        console.log(`[农场助手] $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$${message}`);
        try {
            chrome.runtime.sendMessage({ action: 'addLog', log: message });
        } catch (e) {}
    }


    function addVisualIndicator() {
        const existing = document.getElementById('farm-bot-indicator');
        if (existing) existing.remove();
        
        const indicator = document.createElement('div');
        indicator.id = 'farm-bot-indicator';
        indicator.innerHTML = `
            <div style="color:white;font-size:12px;padding:5px;">
                🌾 农场助手
                <div id="bot-status">初始化中...</div>
            </div>
        `;
        indicator.style.cssText = `
            position:fixed;bottom:100px;right:20px;
            background:linear-gradient(135deg,#667eea,#764ba2);
            padding:10px 15px;border-radius:10px;
            z-index:99999;box-shadow:0 4px 15px rgba(0,0,0,0.3);
        `;
        document.body.appendChild(indicator);
        
        setInterval(() => {
            const statusEl = document.getElementById('bot-status');
            if (statusEl) {
                if (!isInitialized) {
                    statusEl.textContent = '初始化中...';
                } else if (config.enabled && isRunning) {
                    statusEl.textContent = '运行中 ✓';
                } else {
                    statusEl.textContent = '已暂停';
                }
            }
        }, 500);
    }

    console.log('[农场助手] 文档状态:', document.readyState);
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', () => setTimeout(init, 2000));
    } else {
        setTimeout(init, 2000);
    }
})();
存在的问题:
出售接口调用有误,暂时没有时间去调试,源代码都在压缩包,感兴趣的可以试试,不影响使用,可以手动去出售

我设定的规则是当种子的数量低于阙值时会触发自动购买足量种子数,前提是你的金豆余额充足,所以要及时出售仓库的果实

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
289051401 发表于 2026-5-13 14:28
其它地区的用户接口不同吗
3#
third1979 发表于 2026-5-13 14:20
4#
 楼主| 寒墨轩 发表于 2026-5-13 14:23 |楼主
third1979 发表于 2026-5-13 14:20
有没有那种能够自动抽流量 做任务的?

看地区,每个地区的活动不一样,我目前有摇一摇、转盘是每日活动,这个一般手动了,没必要自动去搞
5#
 楼主| 寒墨轩 发表于 2026-5-13 14:33 |楼主
289051401 发表于 2026-5-13 14:28
其它地区的用户接口不同吗

应该是各个地区为了业绩推广的活动不一样,你可以看看你的移动APP中福利活动有什么
6#
third1979 发表于 2026-5-13 14:39
我都是APP里自己手动签到、抽奖的。
7#
mobei5200001 发表于 2026-5-13 14:40
虽然不是甘肃的,但是技术是值得赞赏的,点赞&#128077;
8#
d8lost 发表于 2026-5-13 17:28
楼主那个公众号模板抓取是不是下架了?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-5-14 06:01

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表