Skip to content

Commit

Permalink
🚀 v1.7.2
Browse files Browse the repository at this point in the history
- Cookie Storm cookies no longer go flying up the screen (oops)
- Shimmers fit stock ticker boxes in all languages correctly
- Cookie Stonks options show up in all languages
- Shimmers now use CSS instead of PNG's so they can fill the boxes without hardcoded sizes
- No need to check for Insugar Trading anymore
- Deals gradient works again (they changed the text format I got the number of brokers from)
  • Loading branch information
worldwidewaves committed Jun 1, 2022
1 parent 3d912a2 commit eb30167
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 66 deletions.
4 changes: 2 additions & 2 deletions info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"ID": "Cookie Stonks",
"Author": "Sui",
"Description": "Cookie Clicker Stock Market Helper",
"ModVersion": "1.7.1",
"ModVersion": "1.7.2",
"GameVersion": 2.043,
"Date": "01/06/2022",
"Dependencies": [],
"Disabled": 1,
"AllowSteamAchievs": 1
}
}
84 changes: 20 additions & 64 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.1
// @version 1.7.2
// @description Cookie Clicker Stock Market Helper
// @author Sui
// @match https://orteil.dashnet.org/cookieclicker/
Expand Down Expand Up @@ -36,27 +36,18 @@
init: function() {
// Style
let styleSheet = `
.restingElement {
.restingElementCS {
background-color: grey;
padding: 5px;
font-size: 12px;
}
.shimmer {
position: relative;
width: 128px;
height: 128px;
top: 0;
left: 0;
}
.canvases {
width: 180px;
height: 83px;
.canvasesCS {
position: absolute;
padding-left: -10;
padding-right: -10;
margin-left: -1px;
margin-top: -82px;
display: block;
top: -1px;
left: -1px;
width: calc(100% + 2px);
height: calc(100% + 2px);
z-index: 100;
pointer-events: none;
}
`
Expand Down Expand Up @@ -146,7 +137,7 @@
let restingElementDiff = document.createElement('span')
let difference = getRestingDifference(id, ele.innerText, bankLevel)
restingElementDiff.innerText = difference + '%'
restingElementDiff.className = 'restingElement'
restingElementDiff.className = 'restingElementCS'
restingElementDiff.id = 'restingElementDiff-' + id

let overhead = getOverhead(brokers)
Expand Down Expand Up @@ -187,23 +178,18 @@
prevCanvas.remove()
}

// Add new shimmer
let canvas = document.createElement('canvas')
canvas.style.zIndex = 100
canvas.className = 'canvases'
if (insugarTradingFound) {
canvas.style.height = '98px'
canvas.style.marginTop = '-97px'
}
canvas.className = 'canvasesCS'
canvas.id = 'shimmerCanvas' + id
let ctx = canvas.getContext('2d')
let imageAppend = document.getElementById('bankGood-' + id)
let shimmer = document.createElement('img')

imageAppend.append(canvas)
if (difference >= topDiff && key1) {
ctx.drawImage(shimmerGolden, 0, 0, 264, 150)
canvas.style.boxShadow = 'inset 0 0 16px #ffc35f'
} else if (difference <= bottomDiff && key2) {
ctx.drawImage(shimmerWrath, 0, 0, 264, 150)
canvas.style.boxShadow = 'inset 0 0 16px #c62813'
}
}
}
Expand All @@ -214,12 +200,7 @@
// Callback function to execute when mutations are observed
async function callback(mutationsList) {
let bankLevel = parseInt(document.getElementById('productLevel5').innerText.replace('lvl ', ''))
let brokers
if (document.getElementById('bankBrokersText').innerText == 'no brokers') {
brokers = 0
} else {
brokers = parseInt(document.getElementById('bankBrokersText').innerText.replace('brokers ', ''))
}
let brokers = Game.Objects['Bank'].minigame.brokers;
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

Expand Down Expand Up @@ -520,26 +501,14 @@
return divOptions
}

function checkForInsugarTrading(tries, maxTries) {
if (document.getElementById('bankGood-1') && document.getElementById('bankGood-1').firstChild && document.getElementById('bankGood-1').firstChild.childNodes[4] && document.getElementById('bankGood-1').firstChild.childNodes[4].innerText && document.getElementById('bankGood-1').firstChild.childNodes[4].innerText.slice(0,9) == 'Quantile:') {
insugarTradingFound = true
document.getElementById('bankGood-1-val').id = 'bankGood-1-val' // Force update of shimmers
} else if (tries < maxTries) {
setTimeout(function() {
checkForInsugarTrading(tries + 1, maxTries)
}, 100)
}
return
}

function callbackMenu(mutationsList) {
observerMenu.disconnect() // So the change we make isn't detected as a mutation and we enter an infinite loop

let mainMenu = document.getElementById('menu')
let sectionMenu = document.getElementsByClassName('section')[0]
let menu = document.getElementsByClassName('subsection')[0]
if (mainMenu && menu && sectionMenu && sectionMenu.innerText == 'Options') {
document.getElementsByClassName('subsection')[document.getElementsByClassName('subsection').length - 1].innerText == 'Mods\nManage mods Check mod data Publish mods' ? document.getElementsByClassName('subsection')[document.getElementsByClassName('subsection').length - 1].insertBefore(createOptionsElements(), document.getElementsByClassName('subsection')[document.getElementsByClassName('subsection').length - 1].lastChild.nextSibling) : document.getElementsByClassName('subsection')[document.getElementsByClassName('subsection').length - 1].insertBefore(createOptionsElements(), document.getElementsByClassName('subsection')[document.getElementsByClassName('subsection').length - 1].lastChild)
if (mainMenu && Game.onMenu == 'prefs') {
let menuElements = document.getElementsByClassName('subsection')
let lastMenuElement = menuElements[menuElements.length - 1]
lastMenuElement.insertBefore(createOptionsElements(), lastMenuElement.lastChild.nextSibling)
document.getElementById('centerArea').scrollTop = scroll
}

Expand All @@ -564,12 +533,7 @@
let shimmerState = localStorage['shimmerState'] || 'on'
let goldenShimmer = localStorage['goldenShimmer'] || 150
let wrathShimmer = localStorage['wrathShimmer'] || 50
let shimmerGolden = document.createElement('img')
shimmerGolden.src = 'img/shadedBordersGold.png'
let shimmerWrath = document.createElement('img')
shimmerWrath.src = 'img/shadedBordersRed.png'
let scroll = 0
let insugarTradingFound = false

// Run
async function run() {
Expand Down Expand Up @@ -608,12 +572,7 @@

// Add actual elements
let bankLevel = parseInt(document.getElementById('productLevel5').innerText.replace('lvl ', ''))
let brokers
if (document.getElementById('bankBrokersText').innerText == 'no brokers') {
brokers = 0
} else {
brokers = parseInt(document.getElementById('bankBrokersText').innerText.replace('brokers ', ''))
}
let brokers = Game.Objects['Bank'].minigame.brokers;

for (let i = 0; i < numStocks; i++) {
let elemToEdit = document.getElementById('bankGood-' + i + '-val')
Expand All @@ -630,11 +589,8 @@
observerBrokers.observe(document.getElementById('bankBrokersText'), { attributes: true, childList: true, characterData: true })
// Notify mod loaded
Game.Notify('Cookie Stonks loaded!', 'Buy low, sell high!', [31, 8], 6)

// Check for Insugar Trading to change the Shimmer size
checkForInsugarTrading(1, 300)
}
run()
}
})
})()
})()

1 comment on commit eb30167

@worldwidewaves
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix #10
Fix #9

Please sign in to comment.