MCPcopy Create free account
hub / github.com/TheJoWo/Clean-Clode / autoCopyToClipboard

Function autoCopyToClipboard

script.js:41–83  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

39 }
40
41 async function autoCopyToClipboard(text) {
42 if (isMobile()) {
43 return;
44 }
45
46 if (isSafari()) {
47 return;
48 }
49
50 if (!window.isSecureContext) {
51 return;
52 }
53
54 try {
55
56 if (navigator.clipboard && navigator.clipboard.writeText) {
57 await navigator.clipboard.writeText(text);
58 showCopiedStatus();
59 return;
60 }
61 } catch (err) {
62 }
63
64 try {
65 const tempTextarea = document.createElement('textarea');
66 tempTextarea.value = text;
67 tempTextarea.style.position = 'fixed';
68 tempTextarea.style.left = '-9999px';
69 tempTextarea.style.top = '-9999px';
70 document.body.appendChild(tempTextarea);
71
72 tempTextarea.focus();
73 tempTextarea.select();
74
75 const success = document.execCommand('copy');
76 document.body.removeChild(tempTextarea);
77
78 if (success) {
79 showCopiedStatus();
80 }
81 } catch (fallbackErr) {
82 }
83 }
84
85 function showCopiedStatus() {
86 copiedBadge.style.display = 'inline-block';

Callers 1

performCleanupFunction · 0.85

Calls 3

isMobileFunction · 0.85
isSafariFunction · 0.85
showCopiedStatusFunction · 0.85

Tested by

no test coverage detected