forked from borfast/arrispwgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.js
61 lines (48 loc) · 2.11 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
window.onload = function () {
"use strict";
// Start and end date elements
var start_year = document.getElementById('start-year');
var start_month = document.getElementById('start-month');
var start_day = document.getElementById('start-day');
var end_year = document.getElementById('end-year');
var end_month = document.getElementById('end-month');
var end_day = document.getElementById('end-day');
// Pre-populate dates with today's date
var today = new Date();
start_year.value = end_year.value = today.getFullYear();
start_month.value = end_month.value = today.getMonth() + 1; // In JS January == 0 but that's not user friendly
start_day.value = end_day.value = today.getDate();
// Store the table template in memory
var table = document.getElementById('password-list');
var table_parent = table.parentNode;
var table_template = table.cloneNode(true);
// Dance the funky chicken when the user clicks the magic button
var go = document.getElementById('go');
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);
var end_date = new Date(end_year.value, end_month.value - 1, end_day.value, 0, 0, 0, 0);
var passwords = GenArrisPasswords(start_date.getTime(), end_date.getTime());
// 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');
var table_guts = document.createDocumentFragment();
var row;
var col1;
var col2;
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);
};
};