Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -453,32 +453,47 @@
|
|
| 453 |
'<polyline points="20 6 9 17 4 12"/></svg>';
|
| 454 |
|
| 455 |
function makeShareBtn(filename) {
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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) => {
|