|
/* |
|
* Stimulation Clicker Automator |
|
* by Brian Sinclair (@brianarn) |
|
* MIT License, do whatever |
|
*/ |
|
window._stimAuto = (function () { |
|
const intervalMS = 10; |
|
let intervalID = null; |
|
|
|
const titleSelector = ".title-screen"; |
|
const oceanAttr = '[src$="ocean.webp"]'; |
|
const oceanEnabled = `.upgrade:not(.upgrade-disabled) > .upgrade-icon${oceanAttr}`; |
|
const buttonSelectors = [ |
|
".main-btn", // The main button |
|
".collect", // Collecting the leveling reward |
|
".press-collect", // Collecting the hydraulic press |
|
".press-btn", // Start the hydraulic press |
|
".loot-box-target", // Loot boxes |
|
".question-choice", // Duolingo options |
|
".action-btn", // Feed the chicken |
|
".egg", // Collect the kinder eggs |
|
]; |
|
|
|
// Upgrade buttons are special, since they don't use -hide but have a -disabled parent |
|
// Also, we don't want to select the ocean button, as we never want to click that automatically |
|
const upgradeButtonSelector = `.upgrade:not(.upgrade-disabled) .upgrade-icon:not(${oceanAttr})`; |
|
|
|
// There are also powerups that we want to click on |
|
const powerupSelector = "img.powerup"; |
|
|
|
// Given our selectors, make our main query |
|
const buttonsQuery = `${buttonSelectors |
|
.map((item) => `${item}:not(${item}-hide)`) |
|
.join(", ")}, ${upgradeButtonSelector}, ${powerupSelector}`; |
|
|
|
function clickEverything() { |
|
document.querySelectorAll(buttonsQuery).forEach((button) => { |
|
button.click(); |
|
}); |
|
} |
|
|
|
function startAutomation(stopAtOcean = true) { |
|
if (intervalID) { |
|
console.log("Trying to start automation but it's already running"); |
|
return; |
|
} |
|
|
|
console.log("Starting automation..."); |
|
intervalID = setInterval(() => { |
|
if (document.querySelector(titleSelector)) { |
|
console.log("Title screen detected, stopping"); |
|
clearAutomationInterval(); |
|
return; |
|
} |
|
|
|
if (stopAtOcean && document.querySelector(oceanEnabled)) { |
|
console.log("The ocean button is enabled, stopping."); |
|
console.log("If you wish to restart while still skipping the ocean, run _stimAuto.start(false)"); |
|
clearAutomationInterval(); |
|
return; |
|
} |
|
|
|
clickEverything(); |
|
}, intervalMS); |
|
} |
|
|
|
function clearAutomationInterval() { |
|
console.log("Clearing automation interval"); |
|
clearInterval(intervalID); |
|
intervalID = null; |
|
} |
|
|
|
// The object that exposes our public methods |
|
const stimAuto = { |
|
start: startAutomation, |
|
stop: clearAutomationInterval, |
|
}; |
|
|
|
stimAuto.start(); |
|
|
|
return stimAuto; |
|
})(); |