23 lines
712 B
JavaScript
23 lines
712 B
JavaScript
"use strict";
|
|
|
|
const copy = document.getElementById("copy-code");
|
|
const status = document.getElementById("copy-status");
|
|
const fallback = document.getElementById("raw-code");
|
|
|
|
copy.addEventListener("click", async () => {
|
|
const bytes = Uint8Array.from(atob(copy.dataset.raw), character => character.charCodeAt(0));
|
|
const content = new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
|
|
copy.disabled = true;
|
|
try {
|
|
await navigator.clipboard.writeText(content);
|
|
fallback.hidden = true;
|
|
} catch {
|
|
fallback.value = content;
|
|
fallback.hidden = false;
|
|
fallback.focus();
|
|
fallback.select();
|
|
} finally {
|
|
copy.disabled = false;
|
|
}
|
|
});
|