forked from borfast/arrispwgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
64 lines (51 loc) · 2.39 KB
/
ui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
window.onload = function () {
"use strict";
// Start and end date elements
var start_year = document.getElementById('start-year'),
start_month = document.getElementById('start-month'),
start_day = document.getElementById('start-day'),
end_year = document.getElementById('end-year'),
end_month = document.getElementById('end-month'),
end_day = document.getElementById('end-day'),
// Store the table template in memory
table = document.getElementById('password-list'),
table_parent = table.parentNode,
table_template = table.cloneNode(true),
// Dance the funky chicken when the user clicks the magic button
go = document.getElementById('go');
// Pre-populate dates with today's date
var today = new Date();
start_year.value = end_year.value = today.getFullYear();
// In JS January == 0 but that's not user friendly
start_month.value = end_month.value = today.getMonth() + 1;
start_day.value = end_day.value = today.getDate();
go.onclick = function () {
// Get the Date objects for the dates entered and pass their timestamps
// to the password generator
var start_date = new Date(start_year.value, start_month.value - 1, start_day.value, 0, 0, 0, 0),
end_date = new Date(end_year.value, end_month.value - 1, end_day.value, 0, 0, 0, 0),
passwords = ArrisPwGen(start_date.getTime(), end_date.getTime());
// UI elements.
var table_guts = document.createDocumentFragment(),
row,
col1,
col2;
// Clear the previous table and get a reference to the new one
table_parent.removeChild(table);
table_parent.appendChild(table_template.cloneNode(true));
table = document.getElementById('password-list');
for(var pass in passwords) {
if (passwords.hasOwnProperty(pass)) {
row = document.createElement('tr');
col1 = document.createElement('td');
col1.textContent = (new Date(parseInt(pass, 10))).toLocaleDateString();
row.appendChild(col1);
col2 = document.createElement('td');
col2.textContent = passwords[pass];
row.appendChild(col2);
table_guts.appendChild(row);
}
}
table.appendChild(table_guts);
};
};