MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / copyToClipboard

Function copyToClipboard

frontend/src/utils.js:80–127  ·  view source on GitHub ↗
(value, options = {})

Source from the content-addressed store, hash-verified

78 path.split('.').reduce((acc, part) => acc && acc[part], obj);
79
80export const copyToClipboard = async (value, options = {}) => {
81 const {
82 successTitle = 'Copied!',
83 successMessage = 'Copied to clipboard',
84 failureTitle = 'Copy Failed',
85 failureMessage = 'Failed to copy to clipboard',
86 showNotification = true,
87 } = options;
88
89 let success = false;
90
91 if (navigator.clipboard) {
92 // Modern method, using navigator.clipboard
93 try {
94 await navigator.clipboard.writeText(value);
95 success = true;
96 } catch (err) {
97 console.error('Failed to copy: ', err);
98 }
99 }
100
101 if (!success) {
102 // Fallback method for environments without clipboard support
103 try {
104 const textarea = document.createElement('textarea');
105 textarea.value = value;
106 document.body.appendChild(textarea);
107 textarea.select();
108 const successful = document.execCommand('copy');
109 document.body.removeChild(textarea);
110 success = successful;
111 } catch (err) {
112 console.error('Failed to copy with fallback method: ', err);
113 success = false;
114 }
115 }
116
117 // Show notification if enabled
118 if (showNotification) {
119 notifications.show({
120 title: success ? successTitle : failureTitle,
121 message: success ? successMessage : failureMessage,
122 color: success ? 'green' : 'red',
123 });
124 }
125
126 return success;
127};
128
129export const setCustomProperty = (input, key, value, serialize = false) => {
130 let obj;

Callers 12

copyPublicIPFunction · 0.90
SidebarFunction · 0.90
handleCopyEpisodeLinkFunction · 0.90
handleCopyLinkFunction · 0.90
StreamRowActionsFunction · 0.90
ChannelsTable.jsxFile · 0.90
copyM3UUrlFunction · 0.90
copyEPGUrlFunction · 0.90
copyHDHRUrlFunction · 0.90
UserFunction · 0.90
ConnectLogsPageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected