Created
September 20, 2018 20:57
-
-
Save koutoftimer/1b516fbab0a0395d2947fa0c2db42f28 to your computer and use it in GitHub Desktop.
Computer Evolution automation
This file contains hidden or 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
window.bot = function() { | |
let bot = {}; | |
bot.init = function init() { | |
let selectButton = document.createElement('button') | |
, selectEl = document.createElement('select'); | |
initElements(); | |
appendBody(); | |
addEvents(); | |
console.log('Init done'); | |
function appendBody() { | |
document.body.appendChild(bot.selectButton); | |
document.body.appendChild(bot.selectEl); | |
} | |
function addEvents() { | |
document.addEventListener('keydown', triggerHandler); | |
selectButton.addEventListener('click', updateHandler); | |
} | |
function initElements() { | |
selectButton.textContent = 'Update select'; | |
bot.startHandler = startHandler; | |
bot.stopHandler = stopHandler; | |
bot.triggerHandler = triggerHandler; | |
bot.selectButton = selectButton; | |
bot.selectEl = selectEl; | |
} | |
function initSelect() { | |
let apps = document.getElementById('programs').children; | |
for (let i = 0; i < apps.length - 1; ++i) { | |
let app = apps[i] | |
, id = app.attributes.onclick.value | |
, name = app.children[4].innerHTML; | |
id = parseInt(id.substr(8, id.length - 9)); | |
let option = document.createElement('option'); | |
option.value = id; | |
option.innerHTML = name; | |
selectEl.appendChild(option); | |
} | |
} | |
function stopHandler() { | |
clearInterval(bot.timer); | |
bot.timer = null; | |
} | |
function startHandler() { | |
stopHandler(); | |
let value = parseInt(selectEl.options[selectEl.selectedIndex].value); | |
bot.timer = setInterval(app.run, 50, value); | |
} | |
function triggerHandler(e) { | |
if (e.key === 's') { | |
bot.timer ? stopHandler() : startHandler(); | |
} | |
else if (e.key == 'u') { | |
updateHandler(); | |
} | |
} | |
function updateHandler() { | |
selectEl.innerHTML = null; | |
initSelect(); | |
} | |
} | |
return bot; | |
}(); | |
window.bot.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is automation script for https://www.kongregate.com/games/joao8991/computer-evolution
Press
u
to update apps list ands
to start/stop autoclicking.