MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / copyToClipboard

Function copyToClipboard

static/js/utils.js:758–786  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

756// ============================================
757
758async function copyToClipboard(text) {
759 if (navigator.clipboard && navigator.clipboard.writeText) {
760 try {
761 await navigator.clipboard.writeText(text);
762 toast.success('已复制到剪贴板');
763 return true;
764 } catch (err) {
765 // 降级到 execCommand
766 }
767 }
768 try {
769 const ta = document.createElement('textarea');
770 ta.value = text;
771 ta.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none;';
772 document.body.appendChild(ta);
773 ta.focus();
774 ta.select();
775 const ok = document.execCommand('copy');
776 document.body.removeChild(ta);
777 if (ok) {
778 toast.success('已复制到剪贴板');
779 return true;
780 }
781 throw new Error('execCommand failed');
782 } catch (err) {
783 toast.error('复制失败');
784 return false;
785 }
786}
787
788// ============================================
789// 本地存储助手

Callers 5

renderAccountsFunction · 0.85
copyEmailFunction · 0.85
copyLinkFunction · 0.85
loadRecentAccountsFunction · 0.85

Calls 2

successMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected