Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chrisdarroch
Forked from jaredwy/laksatime.js
Created May 13, 2011 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdarroch/970100 to your computer and use it in GitHub Desktop.
Save chrisdarroch/970100 to your computer and use it in GitHub Desktop.
Laksa time without jQuery
(function(){
var options = {
yesMessage: "YES!",
noMessage: "No",
target: document.getElementById("isitlaksatime"),
wrapper: document.body,
day: 5, // 5 for friday
hour: 12 // 12 for noon!
};
function getMessage(now) {
var targetDay = options.day,
targetHour = options.hour,
yesMessage = options.yesMessage || "Yes",
noMessage = options.noMessage || "No",
theDay = now.getDay(),
theHour = now.getHours(),
theMinute = now.getMinutes();
if ( theDay === targetDay ) {
if ( theHour === targetHour ) {
return yesMessage;
}
if ( (theHour + 2) === targetHour ) return "Not yet";
if ( (theHour + 1) === targetHour ) {
if ( theMinute >= 58) return "Get ready";
if ( theMinute >= 55) return "Nearly";
if ( theMinute >= 45) return "Really soon";
return "Soon";
}
return noMessage;
}
if ( theDay === (targetDay - 1)) return "Come back tomorrow";
return noMessage;
}
function countDown() {
var now = new Date(),
message = getMessage(now);
options.target.innerText = message;
options.wrapper.className = (message.length > 10) ? "long" : "";
//console.log("minute: " + theMinute + " message: " + message);
}
countDown();
timer = setInterval(countDown, 10000);
})();
@chrisdarroch
Copy link
Author

Because I removed the use of the jQuery $(document).ready() function, this script would now need to be loaded just before the closing </body> tag, which isn't a bad thing.

@chrisdarroch
Copy link
Author

BAM! And the jQuery is gone!

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