// ==UserScript== // @name GPlay虚拟农场助手 // @encoding utf-8 // @date 2016.11.12 // @namespace https://greasyfork.org/users/79532 // @version V0.5 // @description 一键种植(需选中种子)、一键收菜、一键偷菜。PS:收菜时可跳过成长周期,直接成熟。 // @author hain1orz // @match */gfarm-front.html // @match */plugin.php?id=gfarm:front // @run-at document-end // @grant GM_addStyle // @grant GM_log // @downloadURL none // ==/UserScript== 'use strict'; // 信息 var Info = {}, UserInput = null, DataInput = null, Lands = null, _planting = 0, _harvesting = 0, _stealing = 0; // 刷新信息 var _log = function(){ let _c = window.console || {}; _c.log = _c.log || function(){}; _c.log.apply(this, arguments); }; // 刷新信息 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){ // 种植中 _log('种植中,请稍后...', _planting); 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; }else{ return; } _log('种植开始,队列信息:', ids.join(',')); for(let i=0; i0){ // 收菜中 _log('收菜中,请稍后...', _harvesting); 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; }else{ return; } _log('收菜开始,队列信息:', ids.join(',')); for(let i=0; i0){ // 偷菜中 _log('偷菜中,请稍后...', _stealing); 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; }else{ return; } _log('偷菜开始,队列信息:', ids.join(',')); for(let i=0; i