Skip to content

Instantly share code, notes, and snippets.

@kolodny
Created December 29, 2013 03:54
Show Gist options
  • Save kolodny/8167230 to your computer and use it in GitHub Desktop.
Save kolodny/8167230 to your computer and use it in GitHub Desktop.
Something I threw together to watch a youtube vid on the treadmill while doing the program
var messages = [
{
html: 'Warmup walking',
seconds: 60 * 5
}
];
var total = messages[0].seconds;
function addItem(html, seconds) {
messages.push({html:html, seconds: seconds});
total += seconds;
}
var wasRunning = false;
while (total < 60 * 20) {
addItem.apply(0, wasRunning ? ['Walk', 90] : ['Run', 60]);
wasRunning = !wasRunning;
}
var newWindow = window.open('about:blank','couch',"directories=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width=400,height=350");
var newBody = newWindow.document.body;
newBody.innerHTML = '<span id=m></span> <span id=e></span>'
var m = newBody.firstChild;
var e = newBody.lastChild;
var startedTotal = new Date();
var startedSet = new Date();
newWindow.setInterval(function() {
var elapsed = (new Date() - startedTotal) / 1000;
e.innerHTML =
('00' + ~~(elapsed / 60)).substr(-2) +
':' +
('00' + ~~(elapsed % 60)).substr(-2);
var elapsed = (new Date() - startedSet) / 1000;
e.innerHTML += ' <strong>' +
('00' + ~~(elapsed / 60)).substr(-2) +
':' +
('00' + ~~(elapsed % 60)).substr(-2);
}, 1000);
var message;
function nextMessage(index) {
startedSet = new Date();
hey();
if (index < messages.length) {
m.innerHTML = messages[index].html;
newWindow.setTimeout(function() {
nextMessage(index + 1);
}, messages[index].seconds * 1000);
} else {
m.innerHTML = 'Done!';
}
}
m.innerHTML = 'Starting when timers reach 5';
newWindow.setTimeout(function() {
startedTotal = new Date();
startedSet = new Date();
nextMessage(0);
}, 5000);
function hey() {
var count = 50;
newWindow.setTimeout(function changeColors() {
newBody.style.background = count % 2 ? 'red' : 'white';
if (count--) newWindow.setTimeout(changeColors, 10)
});
n = 50
for (i = 10; i > 0; i--) {
for (j = n; j > 0; j--) {
newWindow.moveBy(0, i);
newWindow.moveBy(i, 0);
newWindow.moveBy(0, -i);
newWindow.moveBy(-i, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment