Skip to content

Instantly share code, notes, and snippets.

@koutoftimer
Created September 20, 2018 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koutoftimer/1b516fbab0a0395d2947fa0c2db42f28 to your computer and use it in GitHub Desktop.
Save koutoftimer/1b516fbab0a0395d2947fa0c2db42f28 to your computer and use it in GitHub Desktop.
Computer Evolution automation
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();
@koutoftimer
Copy link
Author

koutoftimer commented Sep 20, 2018

This is automation script for https://www.kongregate.com/games/joao8991/computer-evolution

Press u to update apps list and s to start/stop autoclicking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment