Skip to content

Instantly share code, notes, and snippets.

@jaredwy
Created May 13, 2011 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaredwy/970030 to your computer and use it in GitHub Desktop.
Save jaredwy/970030 to your computer and use it in GitHub Desktop.
Refactor me
(function(){
var options = {
"yesMessage": "YES!",
"noMessage": "No",
"target": "#isitlaksatime",
"day": 5, // 5 for friday
"hour": 12 // 12 for noon!
};
function countDown() {
var target = options.target,
targetDay = options.day,
targetHour = options.hour,
yesMessage = options.yesMessage || "Yes",
noMessage = options.noMessage || "No",
now = new Date(),
theDay = now.getDay(),
theHour = now.getHours(),
theMinute = now.getMinutes();
if ( theDay === targetDay ) {
if ( theHour === targetHour ) {
message = yesMessage;
} else if ( (theHour + 2) === targetHour ) {
// can't be arsed abstracting these
message = "Not yet";
} else if ( (theHour + 1) === targetHour ) {
message = "Soon";
if ( theMinute >= 45) {
message = "Really soon";
}
if ( theMinute >= 55) {
message = "Nearly";
}
if ( theMinute >= 58) {
message = "Get ready";
}
} else {
message = noMessage;
}
} else if ( theDay === (targetDay - 1)) {
message = "Come back tomorrow";
} else {
message = noMessage;
}
$(target).text(message);
if (message.length > 10) {
$("body").addClass("long");
} else {
$("body").removeClass("long");
}
//console.log("minute: " + theMinute + " message: " + message)
}
$(document).ready( function() {
countDown();
var timer = setInterval(countDown, 10000);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment