MCPcopy
hub / github.com/sallar/github-contributions-chart / copyToClipboard

Function copyToClipboard

src/utils/export.js:61–81  ·  view source on GitHub ↗
(canvas)

Source from the content-addressed store, hash-verified

59}
60
61export 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
83export function cleanUsername(username) {
84 return username.replace(/^(http|https):\/\/(?!www\.)github\.com\//, "");

Callers 1

onCopyFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected