forked from Ephenia/Pokeclicker-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleautofarmer.js
142 lines (129 loc) · 4.68 KB
/
simpleautofarmer.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
// ==UserScript==
// @name [Pokeclicker] Simple Auto Farmer
// @namespace Pokeclicker Scripts
// @match https://www.pokeclicker.com/
// @grant none
// @version 1.4
// @author Ephenia
// @description Adds buttons to automatically plant and harvest all of any specific berry. Make sure to have the berry selected that you want to auto plant & harvest before enabling it. This includes an auto Mulcher as well.
// ==/UserScript==
var farmState;
var mulchState;
var farmColor;
var mulchColor;
var autoFarmTimer;
var awaitAutoFarm;
var newSave;
var trainerCards;
var shovelList = document.getElementById('shovelList');
function initAutoFarm() {
if (farmState == "ON") {
autoFarmTimer = setInterval(function () {
doPlantHarvest();
}, 1000);
}
if (farmState == "OFF") {
farmColor = "danger"
} else {
farmColor = "success"
}
if (mulchState == "OFF") {
mulchColor = "danger"
} else {
mulchColor = "success"
}
var elemAF = document.createElement("div");
elemAF.innerHTML = `<div class="row justify-content-center py-0">
<div class="col-6 pr-0">
<button id="auto-farm-start" class="btn btn-`+ farmColor + ` btn-block" style="font-size:9pt;">
Auto Farm [`+ farmState + `]
</button>
</div>
<div class="col-6 pl-0">
<button id="auto-mulch-start" class="btn btn-`+ mulchColor + ` btn-block" style="font-size:9pt;">
Auto Mulch [`+ mulchState + `]
</button>
</div>
</div>`
shovelList.before(elemAF)
$("#auto-farm-start").click(startAutoFarm);
$("#auto-mulch-start").click(autoMulch);
function startAutoFarm() {
if (farmState == "OFF") {
localStorage.setItem("autoFarmState", "ON");
farmState = "ON"
autoFarmTimer = setInterval(function () {
doPlantHarvest();
}, 1000); // Happens every 1 second
document.getElementById('auto-farm-start').innerText = `Auto Farm [` + farmState + `]`
document.getElementById("auto-farm-start").classList.remove('btn-danger');
document.getElementById("auto-farm-start").classList.add('btn-success');
} else {
endAutoFarm();
}
}
function doPlantHarvest() {
App.game.farming.plantAll(FarmController.selectedBerry())
if (mulchState == "ON") {
FarmController.mulchAll()
}
App.game.farming.harvestAll()
}
function autoMulch() {
if (mulchState == "OFF") {
localStorage.setItem("autoMulchState", "ON");
mulchState = "ON"
document.getElementById('auto-mulch-start').innerText = `Auto Mulch [` + mulchState + `]`
document.getElementById("auto-mulch-start").classList.remove('btn-danger');
document.getElementById("auto-mulch-start").classList.add('btn-success');
} else {
localStorage.setItem("autoMulchState", "OFF");
mulchState = "OFF"
document.getElementById('auto-mulch-start').innerText = `Auto Mulch [` + mulchState + `]`
document.getElementById("auto-mulch-start").classList.remove('btn-success');
document.getElementById("auto-mulch-start").classList.add('btn-danger');
}
}
function endAutoFarm() {
localStorage.setItem("autoFarmState", "OFF");
farmState = "OFF"
document.getElementById('auto-farm-start').innerText = `Auto Farm [` + farmState + `]`
document.getElementById("auto-farm-start").classList.remove('btn-success');
document.getElementById("auto-farm-start").classList.add('btn-danger');
clearInterval(autoFarmTimer)
}
}
if (localStorage.getItem('autoFarmState') == null) {
localStorage.setItem("autoFarmState", "OFF");
}
if (localStorage.getItem('autoMulchState') == null) {
localStorage.setItem("autoMulchState", "OFF");
}
farmState = localStorage.getItem('autoFarmState');
mulchState = localStorage.getItem('autoMulchState');
function loadScript(){
var oldInit = Preload.hideSplashScreen
Preload.hideSplashScreen = function(){
var result = oldInit.apply(this, arguments)
initAutoFarm()
return result
}
}
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();
}