-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (73 loc) · 2.31 KB
/
Copy pathscript.js
File metadata and controls
84 lines (73 loc) · 2.31 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
let range = document.getElementById('range');
let rangevalue = document.getElementById('rangevalue');
let pbox = document.getElementById('pbox');
let copyicon = document.getElementById('copytext');
let p_gen_btn = document.getElementById('genpswdbtn');
var options = document.querySelectorAll(".option input");
// password generate button
p_gen_btn.addEventListener('click', () => {
let p = new PasswordGen();
pbox.value = p.generatePassword();
if (pbox.value != "") {
copyicon.style.visibility = 'visible';
}
});
// getting range in span
range.addEventListener('input', () => {
rangevalue.textContent = range.value;
});
//password copy button
copyicon.addEventListener('click', () => {
navigator.clipboard.writeText(pbox.value);
copyicon.classList.remove('fa', 'fa-clone');
copyicon.classList.add('fa', 'fa-check');
setTimeout(() => {
copyicon.classList.remove('fa', 'fa-check');
copyicon.innerText = "text copied!";
setTimeout(() => {
copyicon.innerText = "";
copyicon.classList.add('fa', 'fa-clone');
}, 1500);
}, 500)
});
// password generator using class
class PasswordGen {
constructor() {
this.password = "";
this.randompassword = "";
this.Selected = false;
this.characters = {
lowercase: "abcdefghijklmnopqrstuvwxyz",
uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
numbers: "0123456789",
symbols: "!@#$%^&*()_"
}
}
generatePassword() {
if (range.value < 6) {
console.log("pls greater den 6");
} else {
options.forEach((option) => {
if (option.checked) {
this.Selected = true;
this.password += this.characters[option.id];
} else {
this.randompassword = "";
}
});
if (this.Selected) {
let i = 0;
while (i < range.value) {
this.randompassword += this.password[Math.floor(Math.random() * this.password.length)];
i++;
}
}
return this.randompassword;
}
}
}
setInterval(() => {
if (pbox.value == "") {
copyicon.style.visibility = 'hidden';
}
});