Browse files

added clock

  • Loading branch information...
1 parent e75c8aa commit 5cd3ba94a2f6663a4af2aaa9ad4d36dbad1972ee @crshd committed Jun 23, 2012
Showing with 50 additions and 2 deletions.
  1. +39 −0 js/script.js
  2. +4 −2 settings.js
  3. +7 −0 style/style.css
View
39 js/script.js
@@ -32,6 +32,34 @@
THE SOFTWARE.
*/
+/* Clock *\
+\*=========*/
+function updateClock() {
+ var currentTime = new Date ();
+ var currentHours = currentTime.getHours ();
+ var currentMinutes = currentTime.getMinutes ();
+ var currentSeconds = currentTime.getSeconds ();
+
+ // Pad the minutes and seconds with leading zeros, if required
+ currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
+ currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;
+
+ // Choose either "AM" or "PM" as appropriate
+ var timeOfDay = (currentHours < 12) ? "AM" : "PM";
+
+ // Convert the hours component to 12-hour format if needed
+ currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;
+
+ // Convert an hours component of "0" to "12"
+ currentHours = (currentHours == 0) ? 12 : currentHours;
+
+ // Compose the string for display
+ var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
+
+ // Fill '#clock' div with time
+ $("#clock").html(currentTimeString);
+}
+
$(document).ready(function() {
/* Get Links *\
@@ -183,5 +211,16 @@ $(document).ready(function() {
var searchDiv = document.getElementById ('searches');
$(searchDiv.firstChild.firstChild).focus();
}
+
+ /* Clock *\
+ \*=========*/
+
+ if(showClock) {
+ // Add empty '#clock' div
+ $('body').append('<div id="clock"></div>');
+
+ // Update clock
+ setInterval('updateClock()', 1000);
+ }
});
View
6 settings.js
@@ -52,7 +52,9 @@ $(document).ready(function() {
flickr = false;
deviantart = false;
- // Focus on searchbox when opening
- focusSearch = false;
+ // Focus on searchbox when opening
+ focusSearch = false;
+ // Enable clock
+ showClock = true;
});
View
7 style/style.css
@@ -75,6 +75,13 @@ ul li {
right: 2em; /* from right edge */
}
+#clock {
+ position: absolute;
+ bottom: 10px;
+ right: 10px;
+ font-size: 2em;
+}
+
form {
margin-top: 1em;
}

0 comments on commit 5cd3ba9

Please sign in to comment.