Last active
August 29, 2015 14:06
-
-
Save jkrehm/00fa76e583f49a1589ad to your computer and use it in GitHub Desktop.
Facebook Utilities
This file contains 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
/* CSS | |
.timerWrapper { | |
color: #fff; | |
left: 5px; | |
position: fixed; | |
top: 5px; | |
z-index: 9999; | |
} | |
.timer { | |
height: 15px; | |
} | |
.timerWrapper label { | |
color: #fff; | |
} | |
*/ | |
var timer = 3 * 60; | |
var timeTicker; | |
var $timerBox = $('<div/>', {class : 'timerWrapper'}); | |
var $timer = $('<div/>', {class : 'timer'}); | |
var $pause = $('<label><input type="checkbox">Pause</label>'); | |
$timerBox.append($timer).append($pause).appendTo('body'); | |
// Start/stop timer | |
$pause.find('input').change(function () { | |
if ($(this).prop('checked')) { | |
stopTimer(); | |
} else { | |
startTimer(); | |
} | |
}); | |
// Outputs time in pretty format | |
function timeToString (time) { | |
var minutes = Math.floor((time % 3600) / 60); | |
var seconds = Math.floor(time % 60); | |
if (minutes < 10) { | |
minutes = '0' + minutes; | |
} | |
if (seconds < 10) { | |
seconds = '0' + seconds; | |
} | |
// Output the time in MM:SS format | |
return minutes + ':' + seconds; | |
} | |
// Starts the timer | |
function startTimer () { | |
timeTicker = setInterval(function () { | |
// Boot! | |
if (timer < 0) { | |
window.location.replace('https://duckduckgo.com/'); | |
} | |
// Output time remaining | |
$timer.text(timeToString(timer--)); | |
}, 1000); | |
} | |
// Stop the timer | |
function stopTimer () { | |
clearInterval(timeTicker); | |
} | |
// Let's get it started | |
startTimer(); | |
// Remove the chat bar | |
setTimeout(function () { | |
$('.fbChatSidebar').remove(); | |
}, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment