Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
146 lines (127 loc) · 5.29 KB
/
Copy pathindex.js
File metadata and controls
146 lines (127 loc) · 5.29 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function highlight(str) {
str = str.replace(/\*/g, "<span class=\"highlight\">").replace(/_/g, "</span>");
return str
}
function handleClick(){
form = document.form;
inputs = form.getElementsByTagName('input');
values = {};
string = "";
for (i = 0; i < inputs.length; ++i) {
switch (inputs[i].getAttribute("type")) {
case "number":
max_value = parseInt(inputs[i].getAttribute("max"));
min_value = parseInt(inputs[i].getAttribute("min"));
value = parseInt(inputs[i].value);
if (value >= max_value) {
inputs[i].value = max_value;
value = max_value;
string += "&";
string += inputs[i].getAttribute("name") + "=" + value;
} else if (value <= min_value) {
inputs[i].value = min_value;
value = min_value;
string += "&";
string += inputs[i].getAttribute("name") + "=" + value;
} else {
string += "&";
string += inputs[i].getAttribute("name") + "=" + value;
}
break;
case "checkbox":
string += "&";
string += inputs[i].getAttribute("name") + "=" + (inputs[i].checked ? "1" : "0");
break
default:
continue;
}
}
xmlhttp.open("GET","/pwgen/passwordGenerator.php?format=json&hl=1&"+string,true);
xmlhttp.send();
}
function count_symbols(){
dc = parseInt(document.getElementById('dc').value);
wc = parseInt(document.getElementById('wc').value);
cc = parseInt(document.getElementById('cc').value);
sc = cc * wc + dc;
document.getElementById('count_symbols').innerHTML = sc;
}
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var data = this.responseText;
try {
var json_obj = JSON.parse(data);
var table = document.getElementById('passwords-table');
if (typeof(table) != 'undefined' && table != null) {
table.parentNode.removeChild(table);
} else {
document.getElementById("passwords").innerHTML = "";
}
var table = document.createElement('table');
table.setAttribute('class', 'passwords table table-striped table-condensed');
table.setAttribute('id', 'passwords-table');
var table_head = document.createElement('thead');
table.appendChild(table_head);
var tr = document.createElement('tr');
table_head.appendChild(tr);
var th0 = document.createElement('th');
th0.innerHTML = "№";
var th1 = document.createElement('th');
th1.innerHTML = "Пароль";
var th2 = document.createElement('th');
th2.innerHTML = "Фраза";
tr.appendChild(th0);
tr.appendChild(th1);
tr.appendChild(th2);
var table_body = document.createElement('tbody');
for(var i=1;i<=json_obj.length;i++) {
var tr = document.createElement('tr');
tr.setAttribute('class', 'bg_' + ((i % 2) + 1));
var td0 = document.createElement('td');
var b = document.createElement('strong');
b.innerHTML = (i < 10 ? "0" + i : i);
td0.appendChild(b);
var td1 = document.createElement('td');
td1.innerHTML = json_obj[i-1]["password"];
var td2 = document.createElement('td');
td2.innerHTML = highlight(json_obj[i-1]["sentence"]);
tr.appendChild(td0);
tr.appendChild(td1);
tr.appendChild(td2);
table_body.appendChild(tr);
}
table.appendChild(table_body);
document.getElementById("passwords").appendChild(table);
} catch (e) {
document.getElementById("passwords").innerHTML = data;
}
}
}
document.addEventListener('keyup', function(event){
if (event.ctrlKey && event.keyCode == 13) {
var selection = window.getSelection().toString();;
console.log(selection.length);
if (selection.length > 120) {
alert("Вы выбрали слишком большой объем текста!");
} else {
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "mistakes.php");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "mistake");
hiddenField.setAttribute("value", selection);
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
}
}
}, false);