Skip to content

Commit

Permalink
Support more stocks
Browse files Browse the repository at this point in the history
Supports the new building's stock in v2.048 as well as future stocks that may be added with more buildings.
Ideally would use Game.Objects["Bank"].minigame.goods to get the number of different stocks, but that doesn't seem to work with the load order.
  • Loading branch information
Nnnes authored Jun 1, 2022
1 parent 222cee9 commit b6a52f7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions main.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Cookie Stonks
// @namespace cookiestonks
// @version 1.7.0
// @version 1.7.1
// @description Cookie Clicker Stock Market Helper
// @author Sui
// @match https://orteil.dashnet.org/cookieclicker/
Expand Down Expand Up @@ -208,6 +208,9 @@
}
}

// Number of different stocks
let numStocks = Game.ObjectsN - 2

// Callback function to execute when mutations are observed
async function callback(mutationsList) {
let bankLevel = parseInt(document.getElementById('productLevel5').innerText.replace('lvl ', ''))
Expand All @@ -217,7 +220,7 @@
} else {
brokers = parseInt(document.getElementById('bankBrokersText').innerText.replace('brokers ', ''))
}
for (let i = 0; i <= 15; i++) {
for (let i = 0; i < numStocks; i++) {
observer[i].disconnect() // So the change we make isn't detected as a mutation and we enter an infinite loop

let elemToEdit = document.getElementById('bankGood-' + i + '-val')
Expand Down Expand Up @@ -339,7 +342,7 @@
shimmerButton.className = 'option off'
shimmerButton.innerText = 'OFF'
// Remove all canvases/shimmers
for (let id = 0; id <= 15; id++) {
for (let id = 0; id < numStocks; id++) {
let prevCanvas = document.getElementById('shimmerCanvas' + id)
if (prevCanvas) {
prevCanvas.remove()
Expand Down Expand Up @@ -457,7 +460,7 @@
perSliderGolden.innerText = '>=' + goldenShimmer + '%'
localStorage['goldenShimmer'] = goldenShimmer
// Remove all canvases/shimmers
for (let id = 0; id <= 15; id++) {
for (let id = 0; id < numStocks; id++) {
let prevCanvas = document.getElementById('shimmerCanvas' + id)
if (prevCanvas) {
prevCanvas.remove()
Expand Down Expand Up @@ -505,7 +508,7 @@
perSliderWrath.innerText = '<=' + wrathShimmer + '%'
localStorage['wrathShimmer'] = wrathShimmer
// Remove all canvases/shimmers
for (let id = 0; id <= 15; id++) {
for (let id = 0; id < numStocks; id++) {
let prevCanvas = document.getElementById('shimmerCanvas' + id)
if (prevCanvas) {
prevCanvas.remove()
Expand Down Expand Up @@ -612,7 +615,7 @@
brokers = parseInt(document.getElementById('bankBrokersText').innerText.replace('brokers ', ''))
}

for (let i = 0; i <= 15; i++) {
for (let i = 0; i < numStocks; i++) {
let elemToEdit = document.getElementById('bankGood-' + i + '-val')
let elemStockAmount = document.getElementById('bankGood-' + i + '-stock').innerText.replace(',', '')
let elemStockMax = document.getElementById('bankGood-' + i + '-stockMax').innerText.replace('/', '').replace(',', '')
Expand Down

0 comments on commit b6a52f7

Please sign in to comment.