Skip to content

Commit

Permalink
Add a copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjago committed Jan 31, 2024
1 parent 5207015 commit 9f9a720
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/deformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@ document.getElementById("deformat").addEventListener("click", function() {
document.getElementById("clear").addEventListener("click", function() {
document.getElementById("text").value = "";
});

document.getElementById("copy").addEventListener("click", function () {
const text = document.querySelector("#text");
text.select();
document.execCommand("copy");
showToast();
});

function showToast() {
const toast = document.getElementById("toast");
toast.style.display = "block";
setTimeout(() => {
toast.style.display = "none";
}, 3000);
}
14 changes: 10 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ <h1>Deformat</h1>
<form>
<textarea id="text" rows="25" placeholder="Paste text here" autofocus></textarea>
<button id="deformat" type="button" class="primary">Deformat</button>
<button id="clear" type="button" class="btn btn-secondary">Clear</button>
<button id="copy" type="button">Copy</button>
<button id="clear" type="button">Clear</button>
</form>
<p>
No more manually removing each line break when pasting large chunks of text
Expand All @@ -25,11 +26,16 @@ <h1>Deformat</h1>
<h2>Tips</h2>
<ul>
<li>The following characters are removed: carriage return and line feed together (<code>\r\n</code>), carriage return (<code>\r</code>), line feed (<code>\n</code>), and extra single space characters.</li>
<li>Click the <strong>Deformat</strong> button to remove whitespace.</li>
<li>Use <strong>Ctrl+A</strong> to select all text.</li>
<li>Use the <strong>Clear</strong> button to remove all text.</li>
<li>Click <strong>Deformat</strong> to remove whitespace.</li>
<li>Use <strong>Copy</strong> to copy all text to the clipboard.</li>
<li>Use <strong>Clear</strong> to remove all text.</li>
</ul>
<small>made by <a href="https://johnjago.com">JC</a><a href="https://forms.gle/ghcJtmPQNSrdRKfZ8">send feedback</a></small>
<div id="toast-container">
<div class="toast" id="toast" style="display: none;">
Text copied successfully!
</div>
</div>
<script src="deformat.js"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,39 @@ textarea {
padding: 5px;
width: 100%;
}

#toast-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 9999;
}

.toast {
display: none;
background-color: #4CAF50;
color: #fff;
padding: 15px;
border-radius: 5px;
margin-bottom: 15px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
animation: slideInRight 0.5s, fadeOut 0.5s 2.5s forwards;
}

@keyframes slideInRight {
from {
transform: translateX(100%);
}
to {
transform: translateX(0);
}
}

@keyframes fadeOut {
from {
opacity: 1;
}
to {
opacity: 0;
}
}

0 comments on commit 9f9a720

Please sign in to comment.