forked from Ephenia/Pokeclicker-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleautofarmer.user.js
228 lines (197 loc) · 8.13 KB
/
simpleautofarmer.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// ==UserScript==
// @name [Pokeclicker] Simple Auto Farmer
// @namespace Pokeclicker Scripts
// @author Ephenia / Akwawa (update 1.5)
// @description It Add buttons to automatically plant any specific berry, harvest or mulch all berries. Make sure to have the berry selected that you want to auto plant & harvest before enabling it. This includes an auto Mulcher as well.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 1.5
// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
// @downloadURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/simpleautofarmer.user.js
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/simpleautofarmer.user.js
// @match https://www.pokeclicker.com/
// @icon https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant none
// @run-at document-idle
// ==/UserScript==
function initAutoFarm() {
var plantState;
var plantColor;
var autoPlantTimer;
var harvestState;
var harvestColor;
var autoHarvestTimer;
var mulchState;
var mulchColor;
var autoMulchTimer;
var shovelList = document.getElementById('shovelList');
var colorOn = "success";
var colorOff = "danger";
plantState = localStorage.getItem('autoPlantState');
harvestState = localStorage.getItem('autoHarvestState');
mulchState = localStorage.getItem('autoMulchState');
createMenu();
autoPlant(document.getElementById('auto-plant-start'), true);
autoHarvest(document.getElementById('auto-harvest-start'), true);
autoMulch(document.getElementById('auto-mulch-start'), true);
function createMenu() {
plantColor = (plantState === "OFF") ? colorOff : colorOn ;
harvestColor = (harvestState === "OFF") ? colorOff : colorOn ;
mulchColor = (mulchState === "OFF") ? colorOff : colorOn ;
var elemAF = document.createElement("div");
var divMenu = document.createElement("div");
var divBoutonAutoPlant = document.createElement("div");
var divBoutonAutoHarvest = document.createElement("div");
var divBoutonAutoMulch = document.createElement("div");
var buttonAutoPlant = document.createElement("bouton");
var buttonAutoHarvest = document.createElement("bouton");
var buttonAutoMulch = document.createElement("bouton");
divMenu.className = "row justify-content-center py-0";
divBoutonAutoPlant.className = "col-4 pr-0";
divBoutonAutoHarvest.className = "col-4 pr-0 pl-0";
divBoutonAutoMulch.className = "col-4 pl-0";
buttonAutoPlant.style.fontSize = "9pt";
buttonAutoPlant.className = "btn btn-block btn-" + plantColor;
buttonAutoPlant.setAttribute("id", "auto-plant-start");
buttonAutoPlant.textContent = " Auto Plant [" + plantState + "]";
buttonAutoPlant.onclick = function() { autoPlant(this); };
buttonAutoHarvest.style.fontSize = "9pt";
buttonAutoHarvest.className = "btn btn-block btn-" + harvestColor;
buttonAutoHarvest.setAttribute("id", "auto-harvest-start");
buttonAutoHarvest.textContent = " Auto Harvest [" + harvestState + "]";
buttonAutoHarvest.onclick = function() { autoHarvest(this); };
buttonAutoMulch.style.fontSize = "9pt";
buttonAutoMulch.className = "btn btn-block btn-" + mulchColor;
buttonAutoMulch.setAttribute("id", "auto-mulch-start");
buttonAutoMulch.textContent = " Auto Mulch [" + mulchState + "]";
buttonAutoMulch.onclick = function() { autoMulch(this); };
divBoutonAutoPlant.appendChild(buttonAutoPlant);
divBoutonAutoHarvest.appendChild(buttonAutoHarvest);
divBoutonAutoMulch.appendChild(buttonAutoMulch);
divMenu.appendChild(divBoutonAutoPlant);
divMenu.appendChild(divBoutonAutoHarvest);
divMenu.appendChild(divBoutonAutoMulch);
elemAF.appendChild(divMenu);
shovelList.before(elemAF);
}
// Plant - cmd, start, stop, do
function autoPlant(elt, init=false) {
if ( (init === true && plantState === "ON" ) || (init === false && plantState === "OFF") ) {
startPlant(elt);
} else {
stopPlant(elt);
}
}
function startPlant(elt) {
localStorage.setItem("autoPlantState", "ON");
plantState = "ON";
autoPlantTimer = setInterval(function () {
doPlant();
}, 1000); // Happens every 1 second
elt.innerText = "Auto Plant [" + plantState + "]";
elt.classList.remove('btn-danger');
elt.classList.add('btn-success');
}
function stopPlant(elt) {
localStorage.setItem("autoPlantState", "OFF");
plantState = "OFF";
elt.innerText = "Auto Plant [" + plantState + "]";
elt.classList.remove('btn-success');
elt.classList.add('btn-danger');
clearInterval(autoPlantTimer);
}
function doPlant() {
App.game.farming.plantAll(FarmController.selectedBerry());
}
// Harvest - cmd, start, stop, do
function autoHarvest(elt, init=false) {
if ( (init === true && harvestState === "ON" ) || (init === false && harvestState == "OFF") ) {
startHarvest(elt);
} else {
stopHarvest(elt);
}
}
function startHarvest(elt) {
localStorage.setItem("autoHarvestState", "ON");
harvestState = "ON";
autoHarvestTimer = setInterval(function () {
doHarvest();
}, 1000); // Happens every 1 second
elt.innerText = "Auto Harvest [" + harvestState + "]";
elt.classList.remove('btn-danger');
elt.classList.add('btn-success');
}
function stopHarvest(elt) {
localStorage.setItem("autoHarvestState", "OFF");
harvestState = "OFF";
elt.innerText = "Auto Harvest [" + harvestState + "]";
elt.classList.remove('btn-success');
elt.classList.add('btn-danger');
clearInterval(autoHarvestTimer);
}
function doHarvest() {
App.game.farming.harvestAll();
}
// Mulch - cmd, start, stop, do
function autoMulch(elt, init=false) {
if ( (init === true && mulchState === "ON" ) || (init === false && mulchState == "OFF") ) {
startMulch(elt);
} else {
stopMulch(elt);
}
}
function startMulch(elt) {
localStorage.setItem("autoMulchState", "ON");
mulchState = "ON";
autoMulchTimer = setInterval(function () {
doMulch();
}, 1000); // Happens every 1 second
elt.innerText = "Auto Mulch [" + mulchState + "]";
elt.classList.remove('btn-danger');
elt.classList.add('btn-success');
}
function stopMulch(elt) {
localStorage.setItem("autoMulchState", "OFF");
mulchState = "OFF";
elt.innerText = "Auto Mulch [" + mulchState + "]";
elt.classList.remove('btn-success');
elt.classList.add('btn-danger');
clearInterval(autoMulchTimer);
}
function doMulch() {
FarmController.mulchAll();
}
}
function loadScript() {
var oldInit = Preload.hideSplashScreen;
Preload.hideSplashScreen = function(){
var result = oldInit.apply(this, arguments);
initAutoFarm();
return result;
}
}
function initLocalStorage(param, value) {
if (localStorage.getItem(param) == null) {
localStorage.setItem(param, value);
}
}
initLocalStorage("autoPlantState", "OFF");
initLocalStorage("autoHarvestState", "OFF");
initLocalStorage("autoMulchState", "OFF");
var scriptName = 'simpleautofarmer';
if ( document.getElementById('scriptHandler') != undefined ) {
var scriptElement = document.createElement('div');
scriptElement.id = scriptName;
document.getElementById('scriptHandler').appendChild(scriptElement);
if ( localStorage.getItem(scriptName) != null ) {
if ( localStorage.getItem(scriptName) == 'true' ) {
loadScript();
}
} else {
localStorage.setItem(scriptName, 'true');
loadScript();
}
} else {
loadScript();
}