1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 谷歌浏览器chrome扩展插件-农名的世界脚本

谷歌浏览器chrome扩展插件-农名的世界脚本

时间:2018-10-23 05:51:52

相关推荐

谷歌浏览器chrome扩展插件-农名的世界脚本

farmersworld 游戏比较火,写个简单的自动收获的插件。

脚本支持 手锯、电锯、挖掘机、渔船的自动收获。

能量、持久度不够了自动修复。

manifest.json

{"manifest_version": 3, "name": "农民世界","description": "农民世界辅助脚本","version": "0.0.1","permissions": ["contextMenus","activeTab"],"content_scripts": [{"matches": ["https://play.farmersworld.io/*"],"js": ["js/jquery-3.4.1.min.js","bg.js"],"css": []}],"icons": {"16": "imgs/ico_128.png","32": "imgs/ico_32.png","48": "imgs/ico_128.png","128": "imgs/ico_128.png"}}

bg.js

var timer_loaded = 0, timer_countdown = 0, timer_ok_btn = 0;//最低需要的能量, 比如少于30个,斧子就无法使用var min_energy = 200, min_durability = 50;//是否正在操作var flag_operating = false; var flag_login_btn_click = false, flag_login_btn_choose = false;//工具 {name: 'xxx', energy: 30, durability: 15}// var tools = [];var tools = ['手锯', '电锯', '挖掘机', '渔船', '未知'];var vip_card_click = false;var timer_vip = 0, vip_nth = 6;function init(){if($(".login-modal-button").length > 0 && !flag_login_btn_choose){log('选择第一个选择,登录');$(".login-modal-button:first").click();//选贼第一个选择,登录flag_login_btn_choose = true;}if($(".login-button").length > 0 && $("#RPC-Endpoint").val() == '0' && !flag_login_btn_click){log('点击登录');$(".login-button").click();//点击登录flag_login_btn_click = true;}//检查是否已加载到游戏主画面var check_load_ready = $(".resource-number").length > 0;if(!check_load_ready) return;create_panel_show();get_gold_food_energy();clearInterval(timer_loaded);timer_countdown = setInterval("reget_data()", 1000 * 5);}//重新获取下数据function reget_data(){check_tools_countdown();$("#energy_span").text(get_energy());$("#durability_span").text(get_durability());var energy = get_energy();if(energy < min_energy && (!(energy == 0 && get_meat() == 0)) && !flag_operating){flag_operating = true;//点击去增加能量log('能量不足,添加按钮去增加');$('.resource-energy--plus:first').click(); add_energy();}var durability = get_durability();if(durability < min_durability && !flag_operating){log('需要修复持久度');flag_operating = true;add_durability();}if(!$(".plain-button:first").hasClass("disabled") && ($(".plain-button:first").text() == 'Mine')){to_work();}}//增加能量function add_energy(){if($('.button-section.full-width').length < 1) return; //如果没找到操作的按钮也退出log('-----------------------\n');log('准备增加能量');var add_count = $(".modal-input").attr("max");add_count = Math.min(add_count, get_meat() * 5);if(add_count < 1) return;// var add_count = 30;//为了测试方便, 每次增加30个能量log('增加能量数量:' + $(".modal-input").attr("max") + " " + get_meat() * 5 + " 最终选择增加: " + add_count);var energy_val = parseInt($(".modal-input").val());log('上次填写的能量数值: ' + energy_val);log('需要点击减少次数: ' + parseInt(energy_val / 5));log('需要点击增加次数: ' + parseInt(add_count / 5));for(var i = 0; i < parseInt(energy_val / 5); i++){$(".image-button[alt='Minus Icon']").click();}for(var i = 0; i < parseInt(add_count / 5); i++){$(".image-button[alt='Plus Icon']").click();}log('增加能量按钮点击');$('.button-section.full-width').click();flag_operating = false;get_gold_food_energy();}//增加耐久度function add_durability(){if($('.button-section.set-height:nth(1)').hasClass("disabled")) return; //如果没找到操作的按钮也退出$('.button-section.set-height:nth(1)').click();log(get_active_tool() + '耐久度修复');flag_operating = false;get_gold_food_energy();}function check_tools_countdown(){var tools_panel = [];$(".wood__cards-container").children().children().each(function(){tools_panel.push($(this).text());});var chainsaw = tools_panel.pop(); //最后买的,放在最后$(".gold__cards-container").children().children().each(function(){tools_panel.push($(this).text());});$(".food__cards-container").children().children().each(function(){tools_panel.push($(this).text());});var food_last = tools_panel.pop();tools_panel.push(chainsaw);tools_panel.push(food_last);for(var i = 0; i < tools_panel.length; i++){var _time = tools_panel[i];var _time_arr = _time.split(":");if(_time_arr[1] == '00' && parseInt(_time_arr[2]) < 10){$(".vertical-carousel-container").children(":nth(" + i + ")").click();break;}}}//自定点击function to_work(){if(flag_operating){return;}log(get_active_tool() + '自动收获。');$(".plain-button:first").click();clearInterval(timer_countdown);//等3秒钟, 点击确定timer_ok_btn = setInterval("confim_ok()", 3000);}//点击确定function confim_ok(){if($(".button-section.full-width").length < 1){return;}log(get_active_tool() + "收获完成"); var value = $(".mid").text().match(/[\d\.]+/)[0];log("收获:" + value);$(".button-section.full-width").click();clearInterval(timer_ok_btn);timer_countdown = setInterval("reget_data()", 1000 * 5); }//获取当前选中的工具function get_active_tool(){return tools[$(".carousel__img--item.active").attr('alt')];}function run(){timer_loaded = setInterval("init()", 1000 * 3);// setInterval("vip()", 1000 * 60 );vip();setTimeout(function(){window.location.reload();}, 1000 * 60 * 10);}//创建显示信息概要的面板function create_panel_show(){var s = "<div style='position:absolute;top:100px;left:10px;width:280px;padding:30px 20px;border:1px solid #99A;background:#FFF;font-size:20px;font-family;微软雅黑'>";s += "<p>能量:<span id='energy_span'></span></p>";s += "<p>耐久度:<span id='durability_span'></span></p>";s += "<p></p>";s += "<div id='log' style='height:300px;overflow:auto;border:1px solid #aaa; padding:20px 10px; margin:20px -12px;font-size:14px;'></div>"s += "</div>";$("body").append(s);}function get_gold_food_energy(){log("能量:" + get_energy() + ",肉:" + get_meat() + ",黄金:" + get_gold() + ",木材:" + get_wood());}//获取能量function get_energy(){return parseInt($(".resource-number:nth-child(3)").find("div:first").text());}//获取耐久度function get_durability(){return parseInt($(".card-number:first div.content").text().split("/")[0]);}//获取肉function get_meat(){return parseInt($(".resource-number:nth(2)").find("div:first").text());}function get_gold(){return parseInt($(".resource-number:nth(0)").find("div:first").text());}function get_wood(){return parseInt($(".resource-number:nth(1)").find("div:first").text());}function vip(){setInterval("vip_check()", 1000 * 10);}function vip_check(){if(vip_nth > 8){vip_nth = 6;}$(".vertical-carousel-container").children(":nth(" + vip_nth + ")").click();timer_vip = setInterval(function(){if(time == "00:00:00"){vip_click();clearInterval(timer_vip);}}, 1000 * 1);var time = $(".card-container--time").text();vip_nth ++;}function vip_click(){if($(".plain-button.semi-short.true").length< 1){return;}log("[" + vip_nth + "]会员加成点击完成"); $(".plain-button.semi-short.true").length.click();}function log(str){var date = new Date();var time_str = date.toLocaleDateString().replace(/\//g, "-") + " " + date.toTimeString().substr(0, 8);if(!str.startsWith('---')){str = "[" + time_str + "] " + str;}// $('#log').prepend(str + "<br />");$('#log').append(str + "<br />");$('#log').scrollTop($('#log').height());console.log(str);}$(function(){run();});

上面代码即可实现自动收获功能。

需要自己先在本机登录过一次,脚本直接点击登录,不使用密码的。

chrome插件的用法:谷歌浏览器chrome 自己写的插件使用教程_wwwarewow的博客-CSDN博客

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。