forked from M3351AN/timebase-otp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,29 @@ | ||
function getUTCTime() { | ||
var date = new Date(); | ||
var year = date.getUTCFullYear(); | ||
var month = date.getUTCMonth() + 1; | ||
var day = date.getUTCDate(); | ||
var hour = date.getUTCHours(); | ||
var minute = date.getUTCMinutes(); | ||
return [year, month, day, hour, minute]; | ||
} | ||
|
||
function generateCode(utcTime) { | ||
var sum = 0; | ||
for (var i = 0; i < 5; i++) { | ||
sum += utcTime[i]; | ||
} | ||
var code = sum ^ 3351 % 10000; | ||
return code; | ||
} | ||
|
||
function displayTimeAndCode() { | ||
var utcTime = getUTCTime(); | ||
var code = generateCode(utcTime); | ||
var timeString = utcTime.join(":"); | ||
var codeString = code.toString(); | ||
var remaining = 60 - (Date.now() / 1000) % 60; | ||
document.getElementById("time").innerHTML = timeString; | ||
document.getElementById("code").innerHTML = codeString; | ||
document.getElementById("progress").value = remaining; | ||
} |