-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
77 lines (72 loc) · 2.44 KB
/
function.js
File metadata and controls
77 lines (72 loc) · 2.44 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
var clipboard = new Clipboard('.copy')
var lowercase = "abcdefghijklmnopqrstuvwxyz",
uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
numbers = "0123456789",
punctuation = "!@#$%^&*()_+~`|}{[]:;?><,./-=",
lowercaseInput = document.getElementById("lowercase"),
uppercaseInput = document.getElementById("uppercase"),
punctuationInput = document.getElementById("punctuation"),
numbersInput = document.getElementById("numbers"),
lengthInput = document.getElementById("length"),
passwordFeild = document.getElementById("pass-field"),
generateButton = document.getElementById("generate"),
copyButton = document.getElementById("copy"),
plength,
userPassword,
passwordCharSet;
function generate() {
userPassword = "";
passwordCharSet = "";
if (lowercaseInput.checked) {
passwordCharSet += lowercase;
}
if (uppercaseInput.checked) {
passwordCharSet += uppercase;
}
if (punctuationInput.checked) {
passwordCharSet += punctuation;
}
if (numbersInput.checked) {
passwordCharSet += numbers;
}
plength = Number(lengthInput.value);
for (let i = 0; i < plength; i++) {
userPassword += passwordCharSet.charAt(
Math.floor(Math.random() * passwordCharSet.length)
);
}
if (userPassword == "") {
let alertbox = document.getElementById('alert');
alertbox.innerHTML = "Please select an option before generating"
alertbox.classList.add('fail');
setTimeout(function(){
alertbox.classList.remove('fail');
}, 3000);
} else {
passwordFeild.innerHTML = userPassword;
}
copyButton.setAttribute("data-clipboard-text", userPassword)
}
generateButton.addEventListener("click", generate);
clipboard.on('success', function(e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);
let alertbox = document.getElementById('alert');
alertbox.innerHTML = "Copied!"
alertbox.classList.add('success');
setTimeout(function(){
alertbox.classList.remove('success');
}, 3000);
e.clearSelection();
});
clipboard.on('error', function(e) {
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
let alertbox = document.getElementById('alert');
alertbox.innerHTML = "Try select the text to copy"
alertbox.classList.add('fail');
setTimeout(function(){
alertbox.classList.remove('fail');
}, 3000);
});