Modified script so that it can be used in a repeating partial

This commit is contained in:
Thomas Smith 2023-05-05 17:47:01 +02:00
parent 53df889e70
commit d06b467b8e

View file

@ -1,12 +1,12 @@
<div class="flex pt-1 pb-1 ps-4 pe-1 mb-3 black-bg" style="max-width: 800px; margin-left:auto; margin-right:auto; height:60px; border: 1px solid #949494;">
<code id="copy-text" class="white lead">sh <(curl tea.xyz)</code>
<button class="hbtn hb-fill-right" id="copy-button" style="height:100%;">Copy</button>
<div class="flex pt-1 pb-1 ps-4 pe-1 mb-3 black-bg copy-section" style="max-width: 800px; margin-left:auto; margin-right:auto; height:60px; border: 1px solid #949494;">
<code class="white lead copy-text">sh <(curl tea.xyz)</code>
<button class="hbtn hb-fill-right copy-button" style="height:100%; width:140px;">Copy</button>
</div>
<script>
$("#copy-button").on("click", function() {
var copyText = "sh <(curl https://tea.xyz)";
$(".copy-button").on("click", function() {
var copyText = $(this).siblings(".copy-text").text();
var tempInput = document.createElement("input");
tempInput.style = "position: absolute; left: -1000px; top: -1000px";
tempInput.value = copyText;
@ -16,11 +16,11 @@
document.body.removeChild(tempInput);
// Change the button text to 'Copied'
var button = $("#copy-button");
var button = $(this);
var originalText = button.text();
button.text("Copied!");
// Change the button text back to original after 5 seconds
// Change the button text back to original after 2 seconds
setTimeout(function() {
button.text(originalText);
}, 2000);