forked from HackUCF/HorsePlinkoPasswords
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
72 lines (58 loc) · 2.64 KB
/
script.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
const breedList = ["Calico", "Tabby", "Orange", "Bengal", "Bombay", "Burmese", "Persian", "Ragdoll", "Siamese", "Sphynx", "Russian", "British", "American", "Scottish", "Norwegian", "Turkish", "Himalayan", "Ginger"];
const relatedWords = ["Chicken", "Tenders", "Jack", "Back", "Hack", "Red", "Blue", "Orange", "Green", "Gator", "Violet", "Swamp", "Albert", "Alberta", "Chmop", "Offensive", "Defensive", "Fries"];
let locations = ["Gainesville", "Orlando", "Roschester", "Charles", "Jacksonville", "Miami", "Tampa", "Charlotte", "Dallas", "Tallahassee", "Ocala", "Sarasota", "Naples", "Melbourne", "Reitz", "Marston", "Turlington", "Broward", "Smathers", "Shands", "Norman", "Anderson", "Malachowsky", "Newell", "Weil","Carleton", "Little", "Hume", "Rawlings"];
const numPasswords = 10;
const generatePasswordsButton = document.getElementById("generateButton");
generatePasswordsButton.addEventListener("click", generatePasswords);
const passwordContainer = document.getElementById("passwords");
function generatePasswords() {
passwordContainer.innerHTML = "";
for (let i = 0; i < numPasswords; i++) {
const [breed1, breed2] = pickRandomElements(breedList, 2);
const relatedWord = pickRandomElement(relatedWords);
const location = pickRandomElement(locations);
const password = `${breed1}-${relatedWord}-${location}-${padNumber(getRandomInt(0,99))}`;
const passwordElement = document.createElement("div");
passwordElement.onclick = (evt) => {
copyToClipboard(password);
}
passwordElement.classList.add("password");
passwordElement.title = "Click to copy password to clipboard!";
passwordElement.textContent = password;
passwordContainer.appendChild(passwordElement);
}
}
function pickRandomElement(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
function pickRandomElements(arr, count) {
const result = [];
for (let i = 0; i < count; i++) {
result.push(pickRandomElement(arr));
}
return result;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function padNumber(num) {
return num.toString().padStart(2, '0');
}
function showCopyNotification() {
const notification = document.getElementById("copyNotification");
notification.classList.add("show");
// Hide the notification after 2 seconds
setTimeout(() => {
notification.classList.remove("show");
}, 800);
}
function copyToClipboard(str) {
const el = document.createElement('textarea');
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
showCopyNotification();
document.body.removeChild(el);
}
generatePasswords()