GPlay虚拟农场助手

一键种植(需选中种子)、一键收菜、一键偷菜。PS:收菜有惊喜~

目前為 2016-11-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name         GPlay虚拟农场助手
// @encoding     utf-8
// @date         2016.11.12
// @version      V0.1
// @description  一键种植(需选中种子)、一键收菜、一键偷菜。PS:收菜有惊喜~
// @author       hain1orz
// @match        */gfarm-front.html
// @match        */plugin.php?id=gfarm:front
// @grant        none
// @namespace https://gf.qytechs.cn/users/79532
// ==/UserScript==

'use strict';
// 信息
var Info = {}, UserInput = null, DataInput = null, Lands = null, _planting = 0, _harvesting = 0, _stealing = 0;
// 刷新信息
var _flushInfo = function(){
    Info.formhash = document.getElementById('formhash').value; // 农场Hash
    Info.userid = UserInput.value; // 用户ID
    Info.dataid = DataInput.value; // 种子ID
    Lands = document.querySelectorAll('div.makeland+span'); // 耕地缓存
};
// 一键种植
var _plantAll = function(){
    if(_planting>0){ // 种植中
        return;
    }
    if(Info.userid != UserInput.value){
        _flushInfo();
    }
    if(Info.userid != discuz_uid ){ // 不是自己的耕地不能种植
        return;
    }
    if(!DataInput.value){ // 未选中种子
        return;
    }
    Info.dataid = DataInput.value; // 刷新种子ID
    let ids = []; // 耕地ID队列
    for(let sp of Lands){
        if(sp.childElementCount == 1 && sp.nextElementSibling.childElementCount == 0){
            ids.push(sp.id);
        }
    }
    let l = ids.length;
    if(l>0){
        _planting = l;
    }
    for(let i=0; i<l; i++){
        ajaxget('plugin.php?id=gfarm:front&mod=gfarm_ajax&depotid='+Info.dataid+'&formhash='+Info.formhash+'&act=germajax&landid='+ids[i],
            '', '', '', '', function(){
                _planting--;
            });
    }
};
// 一键收菜
var _harvestAll = function(){
    if(_harvesting>0){ // 收菜中
        return;
    }
    if(Info.userid != UserInput.value){
        _flushInfo();
    }
    if(Info.userid != discuz_uid ){ // 不是自己的耕地不能收菜
        return;
    }
    let ids = []; // 耕地ID队列
    for(let sp of Lands){
        if(sp.childElementCount == 1 && sp.nextElementSibling.childElementCount == 1){
            ids.push(sp.id);
        }
    }
    let l = ids.length;
    if(l>0){
        _harvesting = l;
    }
    for(let i=0; i<l; i++){
        ajaxget('plugin.php?id=gfarm:front&mod=gfarm_ajax&formhash='+Info.formhash+'&uid='+Info.userid+'&act=getcrop&landid='+ids[i],
            '', '', '', '', function(){
                _harvesting--;
            });
    }
};
// 一键偷菜
var _stealAll = function(){
    if(_stealing>0){ // 偷菜中
        return;
    }
    if(Info.userid != UserInput.value){
        _flushInfo();
    }
    if(Info.userid == discuz_uid ){ // 自己的耕地不能偷菜
        return;
    }
    let [ids, reg] = [[], new RegExp(/[^\d]/g)]; // 耕地ID队列
    for(let sp of Lands){
        if(sp.childElementCount == 1 && sp.nextElementSibling.childElementCount == 1){ // 判断是否有种子
            if(sp.nextElementSibling.children[0].id != 'cropimg'){ // 是否成熟
                continue;
            }
            if(parseInt(sp.nextElementSibling.nextElementSibling.nextElementSibling.innerText.replace(reg, ''), 10) > 11){ // 判断数量大于11的作物加入队列,提高偷菜效率
                ids.push(sp.id);
            }
        }
    }
    let l = ids.length;
    if(l>0){
        _stealing = l;
    }
    for(let i=0; i<l; i++){
        ajaxget('plugin.php?id=gfarm:front&mod=gfarm_ajax&formhash='+Info.formhash+'&uid='+Info.userid+'&act=stealcrop&landid='+ids[i],
            '', '', '', '', function(){
                _stealing--;
            });
    }
};

(function() {
    UserInput = document.getElementById('userid');
    DataInput = document.getElementById('dataid');
    _flushInfo(); // 初始化信息

    let [backland, toolbar, plantBtn, harvestBtn, stealBtn] = [document.getElementById('backland'), document.createElement('div'), document.createElement('button'), document.createElement('button'), document.createElement('button')];
    let tbs = [
        'position:absolute',
        'top:4px',
        'right:400px',
        'z-index:1'
    ];
    toolbar.setAttribute('style', tbs.join(';'));
    let bs = [
        'font:12px/1.4 Microsoft Yahei Light',
        'color:#fff',
        'background-color:#5cc15f',
        'border:2px solid #fff',
        'border-radius:6px',
        'margin:0 4px',
        'cursor:pointer'
    ];
    plantBtn.innerText = '一键种植';
    harvestBtn.innerText = '一键收菜';
    stealBtn.innerText = '一键偷菜';
    plantBtn.setAttribute('style', bs.join(';'));
    harvestBtn.setAttribute('style', bs.join(';').replace('#5cc15f', '#1081d2'));
    stealBtn.setAttribute('style', bs.join(';').replace('#5cc15f', '#c61a09'));
    plantBtn.onclick = function(){ _plantAll(); };
    harvestBtn.onclick = function(){ _harvestAll(); };
    stealBtn.onclick =  function(){ _stealAll(); };
    toolbar.appendChild(plantBtn);
    toolbar.appendChild(harvestBtn);
    toolbar.appendChild(stealBtn);
    backland.insertBefore(toolbar, backland.firstElementChild);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址