INNER CODE UNIT · TypeScript

onCopyButtonClick

yoav-lavi/melody · playground/src/copy-button/index.ts:14

const onCopyButtonClick = async (copyButton: HTMLElement) => {
  try {
    await navigator.clipboard.writeText(
      `${location.origin}?content=${btoa(
        encodeURIComponent(window.currentEditorContent ?? ''),
      )}`,
    );
    copyButton.textContent = CopyButtonTextState.Copied;
    copyButton.style.background = COPY_BUTTON_HIGHLIGHT;
  } catch (error) {
    copyButton.textContent = CopyButtonTextState.Error;
    copyButton.style.background = COPY_BUTTON_ERROR;
  } finally {
    setTimeout(() => {
      copyButton.textContent = originalText;
      copyButton.style.background = COPY_BUTTON_COLOR;
    }, 3000);
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…