MCPcopy Create free account
hub / github.com/Freedium-cfd/web / handleCodeCopy

Function handleCodeCopy

new-web/src/lib/codeCopy.ts:7–32  ·  view source on GitHub ↗
(event: Event)

Source from the content-addressed store, hash-verified

5}
6
7function handleCodeCopy(event: Event): void {
8 const button = event.currentTarget as HTMLElement;
9 if (button.classList.contains("copied")) return;
10
11 const code = button.dataset.code ?? "";
12 const toggleMs = parseInt(button.dataset.toggleMs ?? "3000", 10);
13 const ready = button.querySelector<HTMLElement>(".ready");
14 const success = button.querySelector<HTMLElement>(".success");
15
16 navigator.clipboard.writeText(code);
17 button.classList.add("copied");
18 if (ready) ready.style.display = "none";
19 if (success) success.style.display = "block";
20
21 setTimeout(() => {
22 button.classList.remove("copied");
23 if (ready) ready.style.display = "block";
24 if (success) success.style.display = "none";
25 }, toggleMs);
26
27 window.dispatchEvent(
28 new CustomEvent("toast", {
29 detail: { message: "Copied to clipboard" },
30 }),
31 );
32}

Callers

nothing calls this directly

Calls 2

removeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected