Skip to content

Instantly share code, notes, and snippets.

@Olical
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save Olical/3a0687838fd1ce3559eb to your computer and use it in GitHub Desktop.

Select an option

Save Olical/3a0687838fd1ce3559eb to your computer and use it in GitHub Desktop.
var elements = {
button: document.getElementById('thebutton'),
title: document.querySelector('.thebutton-form > h1'),
times: [
'10s',
'1s',
'100ms',
'10ms'
].map(function (id) {
return document.getElementById('thebutton-s-' + id);
})
};
var targetTime = 850; // As in, 0850. Accounting for latency, should just about make it. (if nobody beats me to it...)
function getTime() {
return parseInt(elements.times.map(function (element) {
return element.innerHTML;
}).join(''), 10);
}
function clickTheButton() {
elements.button.click();
}
function setTitle(message) {
elements.title.innerText = message;
}
function conditionallyClickRecur() {
var time = getTime();
if (time < targetTime) {
clickTheButton();
setTitle('CLICKED THE BUTTON AT ' + time);
}
else {
setTitle('NOT CLICKING YET AT ' + time);
requestAnimationFrame(conditionallyClickRecur);
}
}
@Olical

Olical commented Apr 12, 2015

Copy link
Copy Markdown
Author

Paste it into your browser's console (it won't run right away!) then execute conditionallyClickRecur() to begin the loop that'll keep checking the time. It is set to click at 0010 by default but you can obviously change that by altering targetTime. Good luck. Praise be upon The Pressiah.

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