-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwgen.js
95 lines (76 loc) · 3.28 KB
/
pwgen.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var reader; //GLOBAL File Reader object for demo purpose only
var fileText;
var pwFormat = "%3W!%3d%%%3a"; // = Net!123%vbx
//TODO:
/*
1. parse the pwFormat
2. create functions for creating parts of the pw
% = delimiter
N = number of characters
w/W = lower/UPPER word
T = title case word from wordlist file
a/A = lower/uppper letter
M = random case letter
s = random symbol
*/
//* Check for the various File API support.
function checkFileAPI() {
if (window.File && window.FileReader && window.FileList && window.Blob) {
reader = new FileReader();
return true;
} else {
alert('The File APIs are not fully supported by your browser. Fallback required.');
return false;
}
}
//* read text input
function readText(filePath) {
var output = ""; //placeholder for text output
if(filePath.files && filePath.files[0]) {
reader.onload = function (e) {
fileText = e.target.result;
};//end onload()
reader.readAsText(filePath.files[0]);
}//end if html5 filelist support
else if(ActiveXObject && filePath) { //fallback to IE 6-8 support via ActiveX
try {
reader = new ActiveXObject("Scripting.FileSystemObject");
var file = reader.OpenTextFile(filePath, 1); //ActiveX File Object
fileText = file.ReadAll(); //text contents of file
//displayContents(output);
file.Close(); //close file "input stream"
} catch (e) {
if (e.number == -2146827859) {
alert('Unable to access local files due to browser security settings. ' +
'To overcome this, go to Tools->Internet Options->Security->Custom Level. ' +
'Find the setting for "Initialize and script ActiveX controls not marked as safe" and change it to "Enable" or "Prompt"');
}
}
}
else { //this is where you could fallback to Java Applet, Flash or similar
return false;
}
return true;
}
//* display content using a basic HTML replacement
function displayContents() {
var thisFile = fileText;
var txt = "";
var wordLen = parseInt(document.getElementById("WordLength").value) + 1;
var fileLength = thisFile.split("\n").length;
if (wordLen > 0){
for (i = Math.round(Math.random() * 100);i < fileLength; i = i + 100){
document.getElementById('wait').innerHTML = i;
console.log(i + ": " + thisFile.split("\n")[i]);
txt += (thisFile.split("\n")[i].length == (wordLen)) ? thisFile.split("\n")[i] + "\n" : "";
}
console.log(txt);
}
else {
txt = thisFile;
}
var txtLength = txt.split("\n").length;
var rndWord = Math.round(Math.random() * txtLength);
var el = document.getElementById('main');
el.innerHTML = rndWord + " / " + txt.split("\n")[rndWord]; //display output in DOM
}