| 59 | } |
| 60 | |
| 61 | export async function copyToClipboard(canvas) { |
| 62 | if ("ClipboardItem" in window) { |
| 63 | // https://bugs.webkit.org/show_bug.cgi?id=222262 |
| 64 | // https://web.dev/async-clipboard/ |
| 65 | const item = new ClipboardItem({ |
| 66 | "image/png": new Promise((resolve) => { |
| 67 | canvas.toBlob(resolve, "image/png"); |
| 68 | }) |
| 69 | }); |
| 70 | navigator.clipboard |
| 71 | .write([item]) |
| 72 | .then(() => toast("🎉 Copied image!")) |
| 73 | .catch((err) => { |
| 74 | toast("Sorry, copying image is not supported on this browser"); |
| 75 | console.error("failed to copy"); |
| 76 | }); |
| 77 | } else { |
| 78 | toast("Sorry, copying image is not supported on this browser"); |
| 79 | console.error("failed to copy"); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | export function cleanUsername(username) { |
| 84 | return username.replace(/^(http|https):\/\/(?!www\.)github\.com\//, ""); |