Skip to content

Added copy to clipboard button #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<div class="container">
<h1 class="title">Password Generator</h1>
<h3 class="password-display" id="passwordDisplay">password</h3>
<button class='btn' id='copy-btn' style='margin-bottom: 20px;'>Copy to Clipboard</button>

<form id="passwordGeneratorForm" class="form">
<label for="characterAmountNumber">Number Of Characters</label>
<div class="character-amount-container">
Expand Down
8 changes: 7 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const includeUppercaseElement = document.getElementById('includeUppercase')
const includeNumbersElement = document.getElementById('includeNumbers')
const includeSymbolsElement = document.getElementById('includeSymbols')
const form = document.getElementById('passwordGeneratorForm')
const copyBtn = document.getElementById('copy-btn')
const passwordDisplay = document.getElementById('passwordDisplay')

const UPPERCASE_CHAR_CODES = arrayFromLowToHigh(65, 90)
Expand Down Expand Up @@ -56,4 +57,9 @@ function syncCharacterAmount(e) {
const value = e.target.value
characterAmountNumber.value = value
characterAmountRange.value = value
}
}

// copy btn
copyBtn.addEventListener('click', () => {
navigator.clipboard.writeText(passwordDisplay.innerText)
})
9 changes: 5 additions & 4 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ body {
display: flex;
justify-content: center;
align-items: center;
font-family: Georgia, 'Times New Roman', Times, serif;
font-family: sans-serif;
}

.container {
background-color: #006699;
background-color: #0073ad;
padding: 3rem;
border-radius: 1rem;
border: 2px solid black;
display: flex;
justify-content: center;
align-items: center;
Expand All @@ -32,10 +31,12 @@ body {
.title {
margin: 0;
text-align: center;
opacity: 0.92;
}

label {
font-weight: bold;
opacity: 0.92;
}

.character-amount-container {
Expand All @@ -48,7 +49,7 @@ label {
}

.password-display {
background-color: white;
background-color: rgba(255,255,255,0.6);
color: black;
padding: 1rem;
border: 1px solid #333;
Expand Down