Skip to content

Instantly share code, notes, and snippets.

@thebecwar
Created February 22, 2019 15:36
Show Gist options
  • Save thebecwar/acbccb3455441a764f0da4f2c07d52ee to your computer and use it in GitHub Desktop.
Save thebecwar/acbccb3455441a764f0da4f2c07d52ee to your computer and use it in GitHub Desktop.
Stone counter
var gagStarted = new Date('2019-02-21T15:00:00+05:00');
function setupTimer() {
var timerSpan = document.createElement('span');
timerSpan.setAttribute('id', 'gag-time-content');
timerSpan.innerText = 'It has been 0 days, 0 hours, 0 minutes and 0 seconds since Roger Stone last violated his gag order';
var parent = document.getElementById('gag-timer');
if (parent) {
parent.appendChild(timerSpan);
}
}
function updateTimer() {
var element = document.getElementById('gag-time-content');
if (element) {
var now = new Date();
var seconds = (now.getTime() - gagStarted.getTime()) / 1000;
var days = Math.floor(seconds / 86400);
seconds = seconds - (days * 86400);
var hours = Math.floor(seconds / 3600);
seconds = seconds - (hours * 3600);
var minutes = Math.floor(seconds / 60);
seconds = Math.floor(seconds - (minutes * 60));
var content = 'It has been ' + days + ' days ' + hours + ' hours ' + minutes + ' minutes and ' + seconds + ' seconds since Roger Stone last violated his gag order.';
element.innerText = content;
}
}
window.onload = function() {
setupTimer();
setInterval(updateTimer, 1000);
};
<!-- Insert this wherever you want the timer to be -->
<div id='gag-timer' />
<!-- put this in <head> -->
<script type='text/javascript' src='counter.js'></script>
<!-- or you can copy and paste the JS into the block -->
@thebecwar
Copy link
Author

The counter's text can be styled with the css selector #gag-time-content

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