MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / copyToClipboard

Function copyToClipboard

codeclash/viewer/static/js/picker.js:214–246  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

212}
213
214function copyToClipboard(text) {
215 // Modern clipboard API (requires HTTPS or localhost)
216 if (navigator.clipboard && window.isSecureContext) {
217 return navigator.clipboard.writeText(text);
218 } else {
219 // Fallback for non-HTTPS environments
220 return new Promise((resolve, reject) => {
221 // Create a temporary textarea element
222 const textArea = document.createElement("textarea");
223 textArea.value = text;
224 textArea.style.position = "fixed";
225 textArea.style.left = "-999999px";
226 textArea.style.top = "-999999px";
227 document.body.appendChild(textArea);
228 textArea.focus();
229 textArea.select();
230
231 try {
232 // Use the older execCommand API
233 const successful = document.execCommand("copy");
234 if (successful) {
235 resolve();
236 } else {
237 reject(new Error("execCommand copy failed"));
238 }
239 } catch (err) {
240 reject(err);
241 } finally {
242 document.body.removeChild(textArea);
243 }
244 });
245 }
246}
247
248function showCopyMessage(message) {
249 // Create temporary message element

Callers 1

copyFromModalFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected