taggart

Simple golang tagging filesystem webapp
Log | Files | Refs

copy-link.js (956B)


      1 document.getElementById("copy-btn").addEventListener("click", function() {
      2     const input = document.getElementById("raw-url");
      3     const text = input.value.trim();
      4     const status = document.getElementById("copy-status");
      5 
      6     // Fallback approach using a temporary textarea
      7     const textarea = document.createElement("textarea");
      8     textarea.value = text;
      9     textarea.style.position = "fixed"; // prevent scrolling
     10     textarea.style.left = "-9999px"; // off-screen
     11     document.body.appendChild(textarea);
     12     textarea.focus();
     13     textarea.select();
     14 
     15     let successful = false;
     16     try {
     17         successful = document.execCommand("copy");
     18     } catch (err) {
     19         successful = false;
     20     }
     21 
     22     document.body.removeChild(textarea);
     23 
     24     if (successful) {
     25         status.textContent = "✓ Copied!";
     26         status.style.color = "green";
     27     } else {
     28         status.textContent = "✗ Copy failed";
     29         status.style.color = "red";
     30     }
     31 });