-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
67 lines (56 loc) · 2.12 KB
/
js.js
File metadata and controls
67 lines (56 loc) · 2.12 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
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
$(function(){
function generatePassword() {
var chars = "abcdefghijklmnopqrstuvwxyz0123456789";
var randomValues = new Uint32Array(32);
var result = "";
if (window.crypto && window.crypto.getRandomValues) {
window.crypto.getRandomValues(randomValues);
} else {
for (var i = 0; i < randomValues.length; i++) {
randomValues[i] = Math.floor(Math.random() * 4294967296);
}
}
for (var j = 0; j < randomValues.length; j++) {
result += chars.charAt(randomValues[j] % chars.length);
}
return result;
}
$.each(["database", "id", "pw"], function (index, name) {
var value = getParameterByName(name);
if(value)
$('[name=' + name + ']').val(value);
});
let $id = $('[name=id]');
if(!$id.val()) {
$id.val($('[name=database]').val());
}
let $pw = $('[name=pw]');
if(!$pw.val()) {
$pw.val(generatePassword());
}
$('.generatePw').on('click', function () {
$pw.val(generatePassword()).trigger('input');
});
$('input').on('input keydown', function () {
var s8 = $('.template8').val();
$.each(["database", "id", "pw"], function (index, name) {
var value = $('[name=' + name + ']').val();
s8 = s8.replace(new RegExp("__" + name + "__", "g"), value);
});
$('.result8').text(s8);
var s5 = $('.template5').val();
$.each(["database", "id", "pw"], function (index, name) {
var value = $('[name=' + name + ']').val();
s5 = s5.replace(new RegExp("__" + name + "__", "g"), value);
});
$('.result5').text(s5);
var url = '?' + $('.form').serialize();
$('.shareUrl').attr('href', url).text(url);
}).trigger('input');
});