Last active
April 5, 2019 22:50
-
-
Save sokol815/a12b1c9c5c623b2d1f785a57b6cd6157 to your computer and use it in GitHub Desktop.
Automation for https://makiki99.github.io/prestige3/
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 Tower of Prestige 3 automation | |
// @namespace http://tampermonkey.net/* | |
// @version 1.0.0 | |
// @description Automates "playing" Tower of Prestige 3 | |
// @author sokol815 | |
// @match https://makiki99.github.io/prestige3/ | |
// @grant none | |
// ==/UserScript== | |
/* | |
This is just some silly code to automate a silly "incremental" (not really an incremental) | |
Pretty boring... | |
To apply, open the dev console at https://makiki99.github.io/prestige3/ and paste the contents of this file in the console. | |
To open the dev console in chrome: | |
on windows: CTRL + SHIFT + J | |
on mac: CMD + SHIFT + J | |
After you've pasted this code into the dev console, hit enter and it will automatically run. | |
Now sit back and do nothing. Each time you load the page, you'll have to re-apply this. | |
If you want to automatically apply it, use something like tampermonkey. | |
*/ | |
(function(){ | |
var execute = function(){ | |
var maxLayer = 9; | |
var maxXY = 9; | |
var buttons = []; | |
var rows = document.getElementById('buyables').children; | |
for( var i = 0; i < rows.length; i++ ) { | |
var row = rows[i].children; | |
for( var j = 0; j < row.length; j++ ) { | |
var button = row[j].children; | |
buttons.push(button[0]); | |
} | |
} | |
var script = { | |
type: 'text/css', style: document.createElement('style'), | |
content: ` | |
.colorize { | |
background-color: red; | |
-webkit-transition: opacity 0.5s ease-in-out; | |
-moz-transition: opacity 0.5s ease-in-out; | |
-ms-transition: opacity 0.5s ease-in-out; | |
-o-transition: opacity 0.5s ease-in-out; | |
} | |
`, | |
append: function() { | |
this.style.type = this.type; | |
this.style.appendChild(document.createTextNode(this.content)); | |
document.head.appendChild(this.style); | |
} | |
}; | |
script.append(); | |
var previous = document.getElementById('layer_prev'); | |
var next = document.getElementById('layer_next'); | |
var layerText = document.getElementById('layer'); | |
function getCurrentLayer(){ | |
return parseInt(layerText.innerText); | |
} | |
var animFrame = function(){ | |
doHighestUpgrade(); | |
}; | |
function applyClickAnim( button ) { | |
button.classList.add("colorize"); | |
setTimeout(function(){ | |
button.classList.remove("colorize"); | |
},500); | |
} | |
function doHighestUpgrade(){ | |
var bestId = {x:0,y:0,z:-1}; | |
var layers = data.prestiges; | |
var startLayer = maxLayer; | |
for( var layer = maxLayer; layer > -1; layer-- ) { | |
for( var x = maxXY; x > -1; x-- ) { | |
for( var y = maxXY; y > -1; y-- ) { | |
if( canActivatePrestige(x,y,layer) ) { | |
if( layer > bestId.z || (layer == bestId.z && Math.max(x,y) > Math.max(bestId.x,bestId.y))) { | |
bestId.z = layer; | |
bestId.x = x; | |
bestId.y = y; | |
layer = -1; | |
x = -1; | |
y = -1; | |
} | |
} | |
} | |
} | |
} | |
if( bestId.z > -1 ) { | |
var buttonId = (bestId.x * 10) + bestId.y; | |
var currentLayer = getCurrentLayer(); | |
if( currentLayer != bestId.z ) { | |
var diff = Math.abs(currentLayer - bestId.z); | |
var handle = setInterval( function(){ | |
if( bestId.z > currentLayer ) { | |
next.click(); | |
} else { | |
previous.click(); | |
} | |
diff--; | |
if( diff == 0 ) { | |
clearInterval( handle ); | |
buttons[buttonId].click(); | |
applyClickAnim( buttons[buttonId] ); | |
window.requestAnimationFrame(animFrame); | |
} | |
}, 50); | |
} else { | |
buttons[buttonId].click(); | |
applyClickAnim( buttons[buttonId] ); | |
window.requestAnimationFrame(animFrame); | |
} | |
} else { | |
setTimeout(function(){ | |
window.requestAnimationFrame(animFrame) | |
}, 100); | |
} | |
} | |
animFrame(); | |
}; | |
setTimeout( function(){ | |
console.log('automation loaded'); | |
execute(); | |
}, 300 ); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment