-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathomegaproteingains.user.js
More file actions
117 lines (107 loc) · 4.53 KB
/
omegaproteingains.user.js
File metadata and controls
117 lines (107 loc) · 4.53 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
// ==UserScript==
// @name [Pokeclicker] Omega Protein Gains
// @namespace Pokeclicker Scripts
// @author Ephenia
// @description Removes the cap on the amount of Proteins that you can use on Pokémon which effectively makes them infinite use.
// @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/custom/omegaproteingains.user.js
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/custom/omegaproteingains.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 vitaminTable;
var awaitvitaminTable;
var awaitOmegaProtein;
var newSave;
var trainerCards;
var vitaminType = {
"Protein": 0,
"Calcium": 1,
"Carbos": 2
}
var vitaminName;
function initOmegaProtein() {
// Didn't find any better for now... Will need to be edited each time a new vitamin is added to the game
var tmp = document.querySelectorAll("#itemBag>div>div>div");
divs = [tmp[0], tmp[1], tmp[2]];
for (var i = 0; i < divs.length; i++) {
divs[i].addEventListener('click', initProtein, true);
}
function initProtein(event) {
// We need this to get the name of the vitamin to use
vitaminName = event.target.closest('img');
if (vitaminName === null) vitaminName = event.target.querySelector('img');
if (vitaminName === null) vitaminName = event.target.previousElementSibling;
vitaminName = vitaminName.src.split('/');
vitaminName = vitaminName[vitaminName.length - 1].split('.')[0];
//This setInterval is one of the few required ones because this table does not exist until loaded once
awaitvitaminTable = setInterval(function () {
var vitaminTable = document.querySelectorAll('#pokemonVitaminModal table>tbody')
if (vitaminTable.length != 0) {
clearInterval(awaitvitaminTable);
vitaminTable[0].addEventListener('click', bypassProtein, true);
}
}, 50);
}
}
function bypassProtein(event) {
// Use the built-in functions to get the sorted list
var child = event.target.closest('tr').rowIndex - 1;
var pokemonList = PartyController.vitaminSortedList.sort(PartyController.compareBy(Settings.getSetting('vitaminSort').observableValue(), Settings.getSetting('vitaminSortDirection').observableValue()))[child];
// Get the amount of vitamin owned
var vitaminAmount = player.itemList[vitaminName]();
var setVitamin = VitaminController.getMultiplier()
var usedVitamin = vitaminAmount - setVitamin;
// Get how many of these have been used until now
var pokeVitamin = pokemonList.vitaminsUsed[vitaminType[vitaminName]]();
if (setVitamin == Infinity && vitaminAmount > 0) {
// Set the new amount of vitamin used
pokemonList.vitaminsUsed[vitaminType[vitaminName]](pokeVitamin + vitaminAmount)
// Remove as much as used
player.itemList[vitaminName](0)
} else if (usedVitamin >= 0) {
// Set the new amount of vitamin used
pokemonList.vitaminsUsed[vitaminType[vitaminName]](pokeVitamin + setVitamin)
// Remove as much as used
player.itemList[vitaminName](usedVitamin)
} else {
// No vitamin of this type left, time to buy some !
Notifier.notify({
message: `You don't have any ` + vitaminName + ` left...`,
type: NotificationConstants.NotificationOption.danger,
});
}
event.stopImmediatePropagation();
}
function loadScript() {
var oldInit = Preload.hideSplashScreen
Preload.hideSplashScreen = function () {
var result = oldInit.apply(this, arguments)
initOmegaProtein()
return result
}
}
var scriptName = 'omegaproteingains'
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();
}