MCPcopy Create free account
hub / github.com/Facets-cloud/flow / copyText

Function copyText

site/script.js:55–77  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

53 if (!buttons.length) return;
54
55 function copyText(text) {
56 if (navigator.clipboard && window.isSecureContext) {
57 return navigator.clipboard.writeText(text);
58 }
59 // Fallback: textarea + execCommand for non-secure contexts (e.g. file://).
60 return new Promise((resolve, reject) => {
61 const ta = document.createElement('textarea');
62 ta.value = text;
63 ta.setAttribute('readonly', '');
64 ta.style.position = 'fixed';
65 ta.style.left = '-9999px';
66 document.body.appendChild(ta);
67 ta.select();
68 try {
69 const ok = document.execCommand('copy');
70 document.body.removeChild(ta);
71 ok ? resolve() : reject(new Error('execCommand failed'));
72 } catch (err) {
73 document.body.removeChild(ta);
74 reject(err);
75 }
76 });
77 }
78
79 buttons.forEach((btn) => {
80 btn.addEventListener('click', () => {

Callers 1

script.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected