forked from ephymew/Pokeclicker-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautobattleitems.user.js
More file actions
128 lines (113 loc) · 5.31 KB
/
autobattleitems.user.js
File metadata and controls
128 lines (113 loc) · 5.31 KB
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
// ==UserScript==
// @name [Pokeclicker] Auto Battle Items
// @namespace Pokeclicker Scripts
// @author Ephenia
// @description Automates the usage of Battle Items as effectively and efficiently as possible. Now includes which items you would like to automate specifically and being able to toggle them.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 1.1
// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
// @downloadURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/autobattleitems.user.js
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/autobattleitems.user.js
// @match https://www.pokeclicker.com/
// @icon https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant none
// @run-at document-idle
// ==/UserScript==
var battleItemState;
var itemABLoop;
var ItemABPrefs;
function initAutoBattleItems() {
const battleItemDisplay = document.getElementById('battleItemContainer');
battleItemDisplay.querySelector('.card-header').outerHTML += `<button id= "auto-battle-items" class="btn btn-sm btn-${battleItemState ? 'success' : 'danger'}" style="position: absolute;left: 0px;top: 0px;width: 65px;height: 41px;font-size: 7pt;">
Auto Use [${battleItemState ? 'ON' : 'OFF'}]
</button>`
document.getElementById('auto-battle-items').addEventListener('click', event => { switchABItems(event); });
//Specific Battle Items Toggling
const battleItemTop = battleItemDisplay.querySelectorAll('.amount.p-0');
for (let i = 0; i < battleItemTop.length; i++) {
battleItemTop[i].setAttribute('data-src', i);
backColor(ItemABPrefs[i], battleItemTop[i]);
battleItemTop[i].addEventListener('click', event => { toggleABItems(event); });
}
function toggleABItems(event) {
const element = event.target;
const index = +element.getAttribute('data-src');
ItemABPrefs[index] = !ItemABPrefs[index];
backColor(ItemABPrefs[index], element);
localStorage.setItem("toggleABItems", JSON.stringify(ItemABPrefs));
}
function backColor(boolean, element) {
boolean ? element.style.background = 'yellowgreen' : element.style.background = 'salmon';
}
function switchABItems(event) {
const element = event.target;
battleItemState = !battleItemState;
battleItemState ? ABItems() : clearInterval(itemABLoop);
element.setAttribute('class', `btn btn-${battleItemState ? 'success' : 'danger'}`);
element.textContent = `Auto Use [${battleItemState ? 'ON' : 'OFF'}]`;
localStorage.setItem('autoBattleItems', JSON.stringify(battleItemState));
}
function ABItems() {
itemABLoop = setInterval(() => {
//In order the towns required to be unlocked for each Battle Item
const townReqs = ['Viridian City','Pewter City','Lavender Town'].flatMap(i => [i,i]);
const battleItems = GameHelper.chunk(6, Object.keys(ItemList).filter(i=>ItemList[i].constructor.name == 'BattleItem'))[0];
for (let i = 0; i < battleItems.length; i++) {
if (ItemABPrefs[i]) {
const itemAmnt = player.itemList[battleItems[i]]();
const effectActive = player.effectList[battleItems[i]]();
const townUnlocked = TownList[townReqs[i]].isUnlocked();
if (townUnlocked) {
const getMoney = App.game.wallet.currencies[GameConstants.Currency.money]();
const basePrice = ItemList[battleItems[i]].basePrice;
const price = ItemList[battleItems[i]].price();
if (itemAmnt == 0 && basePrice == price && price <= getMoney) {
ItemList[battleItems[i]].buy(1);
}
}
if (itemAmnt != 0 && effectActive <= 1) {
ItemHandler.useItem(battleItems[i], 1);
}
}
}
}, 500);
}
if (battleItemState) { ABItems(); }
}
if (!localStorage.getItem('autoBattleItems')) {
localStorage.setItem("autoBattleItems", false);
}
if (!localStorage.getItem('toggleABItems')) {
const prefArray = new Array(6).fill(false, 0, 6);
localStorage.setItem("toggleABItems", JSON.stringify(prefArray));
}
battleItemState = JSON.parse(localStorage.getItem('autoBattleItems'));
ItemABPrefs = JSON.parse(localStorage.getItem('toggleABItems'));
function loadScript(){
var oldInit = Preload.hideSplashScreen
Preload.hideSplashScreen = function(){
var result = oldInit.apply(this, arguments)
initAutoBattleItems()
return result
}
}
var scriptName = 'autobattleitems'
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();
}