From 58ef0ee65cabe34c249401032a7aec3e9aacae24 Mon Sep 17 00:00:00 2001 From: Ryan Hawkins Date: Tue, 21 Jan 2025 20:00:02 -0600 Subject: [PATCH] Added functionality to copy the passwword --- script.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/script.js b/script.js index 192936e..3ebd147 100644 --- a/script.js +++ b/script.js @@ -17,6 +17,7 @@ lengthSelector.addEventListener("input", (e) => { }); lengthSelector.addEventListener("change", generatePassword); +passwordDisplay.addEventListener("click", copyPassword); function clampValues(val, min, max) { if (val < min) { @@ -90,3 +91,10 @@ function generatePassword() { function getRandomInRange(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } + +function copyPassword() { + let password = passwordDisplay.innerText; + navigator.clipboard.writeText(password); + displayPassword("copied..."); + setTimeout(() => {displayPassword(password)}, 250); +} \ No newline at end of file