wop commited on
Commit
91e17c8
·
verified ·
1 Parent(s): f324186

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +40 -25
script.js CHANGED
@@ -453,32 +453,47 @@
453
  '<polyline points="20 6 9 17 4 12"/></svg>';
454
 
455
  function makeShareBtn(filename) {
456
- const btn = document.createElement("button");
457
- btn.type = "button";
458
- btn.className = "share-btn";
459
- btn.setAttribute("aria-label", "Copy share link");
460
- btn.title = "Copy share link";
461
- btn.innerHTML = SHARE_ICON;
462
- btn.addEventListener("click", async (e) => {
463
- e.preventDefault();
464
- e.stopPropagation();
465
- const url = `${SITE_BASE}?post=${filename}`;
466
- try {
467
- await navigator.clipboard.writeText(url);
468
- btn.classList.remove("error");
469
- btn.classList.add("copied");
470
- btn.innerHTML = CHECK_ICON;
471
- setTimeout(() => {
472
- btn.classList.remove("copied");
473
- btn.innerHTML = SHARE_ICON;
474
- }, 1400);
475
- } catch {
476
- btn.classList.add("error");
477
- setTimeout(() => btn.classList.remove("error"), 1400);
478
- }
479
- });
480
- return btn;
 
 
 
 
 
 
 
 
 
 
 
481
  }
 
 
 
 
482
 
483
  // One share button per post card on the index page
484
  document.querySelectorAll(".post-card").forEach((card) => {
 
453
  '<polyline points="20 6 9 17 4 12"/></svg>';
454
 
455
  function makeShareBtn(filename) {
456
+ const btn = document.createElement("button");
457
+ btn.type = "button";
458
+ btn.className = "share-btn tooltip";
459
+ btn.setAttribute("aria-label", "Copy share link");
460
+ btn.dataset.tooltip = "Copy share link";
461
+ btn.innerHTML = SHARE_ICON;
462
+
463
+ btn.addEventListener("click", async (e) => {
464
+ e.preventDefault();
465
+ e.stopPropagation();
466
+
467
+ const url = `${SITE_BASE}?post=${filename}`;
468
+
469
+ try {
470
+ await navigator.clipboard.writeText(url);
471
+
472
+ btn.classList.remove("error");
473
+ btn.classList.add("copied");
474
+ btn.innerHTML = CHECK_ICON;
475
+ btn.dataset.tooltip = "Copied!";
476
+
477
+ setTimeout(() => {
478
+ btn.classList.remove("copied");
479
+ btn.innerHTML = SHARE_ICON;
480
+ btn.dataset.tooltip = "Copy share link";
481
+ }, 1400);
482
+
483
+ } catch {
484
+ btn.classList.remove("copied");
485
+ btn.classList.add("error");
486
+ btn.dataset.tooltip = "Couldn't copy";
487
+
488
+ setTimeout(() => {
489
+ btn.classList.remove("error");
490
+ btn.dataset.tooltip = "Copy share link";
491
+ }, 1400);
492
  }
493
+ });
494
+
495
+ return btn;
496
+ }
497
 
498
  // One share button per post card on the index page
499
  document.querySelectorAll(".post-card").forEach((card) => {