Instantly share code, notes, and snippets.
Last active
September 3, 2024 14:06
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save sudofox/df32c4f53516b37e6295adbef734948b to your computer and use it in GitHub Desktop.
Track and graph the change in prestige level over time in Cookie Clicker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Cookie Clicker ΔPrestige Tracker | |
// @namespace http://tampermonkey.net/ | |
// @version 1.4 | |
// @description Track and graph the change in prestige level over time in Cookie Clicker. | |
// @author sudofox | |
// @match http*://orteil.dashnet.org/cookieclicker/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let prestigeHistory = []; | |
const pollInterval = 1000; | |
const maxDataPoints = 60; | |
let lastPrestige = 0; | |
let prestigeChart = null; | |
function getCurrentPrestige() { | |
const ascendNumber = document.querySelector('#ascendNumber'); | |
if (ascendNumber) { | |
return parseFloat(ascendNumber.innerText.replace(/[^0-9.-]+/g, "")); | |
} | |
return 0; | |
} | |
function updatePrestigeHistory() { | |
const currentPrestige = getCurrentPrestige(); | |
const deltaPrestige = currentPrestige - lastPrestige; | |
if (lastPrestige !== 0) { | |
prestigeHistory.push(deltaPrestige); | |
} | |
lastPrestige = currentPrestige; | |
if (prestigeHistory.length > maxDataPoints) { | |
prestigeHistory.shift(); | |
} | |
updateGraph(); | |
} | |
function updateGraph() { | |
if (prestigeChart) { | |
prestigeChart.data.labels = prestigeHistory.map((_, i) => i); | |
prestigeChart.data.datasets[0].data = prestigeHistory; | |
prestigeChart.update(); | |
} else { | |
const ctx = document.getElementById('prestigeGraph').getContext('2d'); | |
prestigeChart = new Chart(ctx, { | |
type: 'line', | |
data: { | |
labels: prestigeHistory.map((_, i) => i), | |
datasets: [{ | |
label: 'ΔPrestige Level Over Time', | |
data: prestigeHistory, | |
borderColor: 'rgba(75, 192, 192, 1)', | |
borderWidth: 1, | |
fill: false | |
}] | |
}, | |
options: { | |
scales: { | |
x: { | |
display: true, | |
title: { | |
display: true, | |
text: 'Time (seconds)' | |
} | |
}, | |
y: { | |
type: 'logarithmic', | |
display: true, | |
title: { | |
display: true, | |
text: 'ΔPrestige Level' | |
}, | |
ticks: { | |
callback: function(value) { | |
return Number(value.toString()); | |
} | |
} | |
} | |
}, | |
animation: { | |
duration: 0 | |
} | |
} | |
}); | |
} | |
} | |
function createGraphElement() { | |
const graphContainer = document.createElement('div'); | |
graphContainer.id = 'prestigeGraphContainer'; | |
graphContainer.style.position = 'fixed'; | |
graphContainer.style.bottom = '10px'; | |
graphContainer.style.left = '50px'; | |
graphContainer.style.width = '300px'; | |
graphContainer.style.height = '150px'; | |
graphContainer.style.zIndex = '9999'; | |
graphContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.8)'; | |
graphContainer.style.border = '1px solid #000'; | |
graphContainer.style.padding = '10px'; | |
const canvas = document.createElement('canvas'); | |
canvas.id = 'prestigeGraph'; | |
canvas.width = 280; | |
canvas.height = 130; | |
graphContainer.appendChild(canvas); | |
document.body.appendChild(graphContainer); | |
} | |
const script = document.createElement('script'); | |
script.src = 'https://cdn.jsdelivr.net/npm/chart.js'; | |
script.onload = function() { | |
createGraphElement(); | |
setInterval(updatePrestigeHistory, pollInterval); | |
}; | |
document.head.appendChild(script); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment