Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bug-hercules/Password_generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1 class="app-name">Password Generator</h1>
<div class="display-container">
<input type="text" readonly placeholder="Password" class="display" data-password-display>

<button class="copy-btn" data-copy-btn>
<button id="copyPassword" class="copy-btn" data-copy-btn>
<p data-copy-msg class="copy-tooltip"></p>
<img src="./images/copy.svg" alt="copy" class="copy-img">
</button>
Expand Down
31 changes: 31 additions & 0 deletions bug-hercules/Password_generator/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,37 @@ function generatePassword(){
handleSlider();
}

function copyPassword() {
// Select the password display element
passwordDisplay.select();
// Copy the selected text
document.execCommand("copy");
// Deselect the text
window.getSelection().removeAllRanges();


copyMsg.classList.remove("hide");
setTimeout(() => {
copyMsg.classList.add("hide");
}, 2000);
alert('Password copied to clipboard');
}

// Add event listener to the copy button
copyBtn.addEventListener('click', copyPassword);

// function copyPassword(password){
// var tempInput = document.createElement("input");

// tempInput.value = password;
// tempInput.setAttribute("readonly", "");
// document.body.appendChild(tempInput);
// tempInput.select();
// tempInput.setSelectionRange(0, tempInput.value.length);

// document.execCommand("copy");
// document.body.removeChild(tempInput);
// }
// remove the previous password
if (password.length) password = "";

Expand Down