From ec8687a3267f36944dac8eaae0bdca038f79c661 Mon Sep 17 00:00:00 2001 From: Hani Rouatbi Date: Thu, 30 Mar 2023 12:04:48 +0100 Subject: [PATCH] Copy button in BS style is dynamic now --- styles/bootstrap/index_body.html | 43 ++++++++++++++++++++------------ styles/bootstrap/up_boxes.html | 7 ------ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/styles/bootstrap/index_body.html b/styles/bootstrap/index_body.html index 60c7442..07df33b 100755 --- a/styles/bootstrap/index_body.html +++ b/styles/bootstrap/index_body.html @@ -136,23 +136,22 @@ const copyText = button.closest('.form-group').querySelector('textarea'); copyText.select(); document.execCommand("copy"); - - // Show tooltip - const tooltip = document.createElement("div"); - tooltip.innerHTML = "Copied!"; - tooltip.style.position = "fixed"; - tooltip.style.bottom = "10px"; - tooltip.style.right = "10px"; - tooltip.style.backgroundColor = "lightgreen"; - tooltip.style.padding = "10px"; - tooltip.style.borderRadius = "5px"; - document.body.appendChild(tooltip); - - // Remove tooltip after 3 seconds + + // Store original button text + const originalButtonText = button.textContent; + + // Disable button while text is being copied + button.disabled = true; + + // Change button text to "Copied!" + button.textContent = "✔️"; + + // Wait for 3 seconds and then change button text back to original setTimeout(function() { - document.body.removeChild(tooltip); + button.textContent = originalButtonText; + button.disabled = false; }, 3000); - } + } function convertSize(size) { if (size > 1024 * 1024 * 1024) { @@ -217,7 +216,6 @@ self.humanSize = humanSize; let newHTML = humanSent + " / " + humanSize + " (" + percent.toFixed(2) + "%) complete"; stats.innerHTML = newHTML; - console.log(uploadSpeed); }; xhttp.onreadystatechange = function (e) { @@ -241,6 +239,19 @@ }); html += ""; speed.insertAdjacentHTML("afterend", html); + + // Add buttons after the new textareas + const formGroups = document.querySelectorAll(".form-group"); + formGroups.forEach(formGroup => { + const textarea = formGroup.querySelector("textarea"); + if (textarea) { + const button = document.createElement("button"); + button.innerHTML = "📋"; + button.classList.add("btn", "btn-primary", "btn-sm", "mt-2"); + button.addEventListener("click", copyText); + textarea.insertAdjacentElement("afterend", button); + } + }); } else if (this.readyState == 4 && this.status != 200) { diff --git a/styles/bootstrap/up_boxes.html b/styles/bootstrap/up_boxes.html index 551cece..7ac3550 100755 --- a/styles/bootstrap/up_boxes.html +++ b/styles/bootstrap/up_boxes.html @@ -10,7 +10,6 @@
-
@@ -22,19 +21,16 @@
-
-
-
@@ -45,13 +41,11 @@
-
-
@@ -64,7 +58,6 @@
-