|
1 | 1 | // Prevent text marking on this page |
2 | 2 | onselectstart = (e) => {e.preventDefault()} |
3 | 3 |
|
4 | | -/* this JS handles the binary clock */ |
5 | | -var startTime = new Date().getTime(); |
| 4 | +// Start date |
| 5 | +var d = new Date(); |
| 6 | +// Covert current time to UTC |
| 7 | +var startTime = d.getTime() + d.getTimezoneOffset() * 60000; |
| 8 | + |
| 9 | +// Timer |
| 10 | +var timer; |
6 | 11 |
|
7 | 12 | var main = function() { |
8 | 13 |
|
9 | | - window.setInterval(function() {clock()}, 1000); |
| 14 | + // Update everys 1000 ms |
| 15 | + timer = window.setInterval(function() {clock()}, 1000); |
10 | 16 |
|
| 17 | + // Pre-Setup to make everything nice and dark |
11 | 18 | var lighting = function(n,t) { |
12 | 19 | if(n == 1) { |
13 | 20 | $('.'+t+'-1').addClass('on').removeClass('off'); |
@@ -73,27 +80,65 @@ var main = function() { |
73 | 80 | }; |
74 | 81 |
|
75 | 82 | var clock = function() { |
76 | | - |
77 | | - var currentTime = new Date(new Date().getTime() - startTime) |
78 | 83 |
|
79 | | - var hours = currentTime.getHours()-1; |
80 | | - var minutes = currentTime.getMinutes(); |
81 | | - var seconds = currentTime.getSeconds(); |
82 | | - |
| 84 | + // Current Time |
| 85 | + var d2 = new Date(); |
| 86 | + var currentTime = d2.getTime() + (d2.getTimezoneOffset() * 60000) - startTime; |
| 87 | + |
| 88 | + // Convert miliseconds |
| 89 | + var seconds = currentTime / 1000; |
| 90 | + var minutes = seconds / 60; |
| 91 | + var hours = minutes / 60; |
| 92 | + |
| 93 | + // Get within current limits |
| 94 | + seconds = Math.floor(seconds % 60); |
| 95 | + minutes = Math.floor(minutes % 60); |
| 96 | + hours = Math.floor(hours); |
| 97 | + |
| 98 | + // Negative time protection |
| 99 | + if (hours < 0 || minutes < 0 || seconds < 0) { |
| 100 | + d = new Date(); |
| 101 | + startTime = d.getTime() + d.getTimezoneOffset() * 60000; |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + // No-Life protection |
| 106 | + if (hours >= 30) { |
| 107 | + document.getElementById("clockDIV").innerHTML = ""; |
| 108 | + document.getElementById("numberDIV").innerHTML = ""; |
| 109 | + |
| 110 | + // Get some help. |
| 111 | + var timeMsg = document.createElement("h1"); |
| 112 | + timeMsg.innerHTML = " > 30 GODDAMNED HOURS!"; |
| 113 | + |
| 114 | + var helpMsg = document.createElement("h3"); |
| 115 | + helpMsg.innerHTML = "If you didn't cheat on achieving this amount of time<br> you should really go out and get some help." |
| 116 | + helpMsg.style.textAlign = "center"; |
| 117 | + helpMsg.style.color = "#4f4f66" |
| 118 | + |
| 119 | + document.getElementById("innerDIV").appendChild(timeMsg); |
| 120 | + document.getElementById("innerDIV").appendChild(helpMsg); |
| 121 | + |
| 122 | + window.clearInterval(timer); |
| 123 | + } |
| 124 | + |
| 125 | + // Calculate the binary lights |
83 | 126 | var s2 = seconds % 10; |
84 | 127 | var s1 = (seconds - s2) / 10 % 10; |
85 | 128 | var m2 = minutes % 10; |
86 | 129 | var m1 = (minutes - m2) / 10 % 10; |
87 | 130 | var h2 = hours % 10; |
88 | 131 | var h1 = (hours - h2) / 10 % 10; |
89 | 132 |
|
| 133 | + // Make it bright (or dark lol) |
90 | 134 | lighting(s2, 's-2'); |
91 | 135 | lighting(s1, 's-1'); |
92 | 136 | lighting(m2, 'm-2'); |
93 | 137 | lighting(m1, 'm-1'); |
94 | 138 | lighting(h2, 'h-2'); |
95 | 139 | lighting(h1, 'h-1'); |
96 | 140 |
|
| 141 | + // Display time number |
97 | 142 | $('.dec-hour1 p').text(h1); |
98 | 143 | $('.dec-hour2 p').text(h2); |
99 | 144 | $('.dec-minute1 p').text(m1); |
|
0 commit comments