1/** 2 * Clipboard utility for copying text to clipboard 3 * 4 * uses Clipboard API. 5 */ 6window.ClipboardUtils = { 7 /** 8 * Copy text to clipboard 9 * @param {string} text - Text to copy 10 * @returns {Promise<boolean>} - Promise resolving to success status 11 */ 12 async copyText(text) { 13 if (!navigator.clipboard) { 14 console.warn('Clipboard API not available'); 15 return false; 16 } 17 18 try { 19 await navigator.clipboard.writeText(text); 20 return true; 21 } catch (err) { 22 console.error('Failed to copy text:', err); 23 return false; 24 } 25 }, 26 27 /** 28 * Get text content from an element 29 * @param {string|Element} elementOrSelector - Element or selector 30 * @returns {string} - Text content 31 */ 32 getElementText(elementOrSelector) { 33 let element; 34 35 if (typeof elementOrSelector === 'string') { 36 element = document.querySelector(elementOrSelector); 37 } else { 38 element = elementOrSelector; 39 } 40 41 if (!element) { 42 return ''; 43 } 44 45 const tagName = element.tagName.toLowerCase(); 46 if (tagName === 'input' || tagName === 'textarea') { 47 return element.value || ''; 48 } else { 49 return element.textContent || element.innerText || ''; 50 } 51 }, 52 53 /** 54 * Copy content from an element 55 * @param {string|Element} elementOrSelector - Source element 56 * @param {Element} button - Button element for feedback 57 * @returns {Promise<boolean>} - Promise resolving to success status 58 */ 59 async copyFromElement(elementOrSelector, button) { 60 const text = this.getElementText(elementOrSelector); 61 if (!text) { 62 return false; 63 } 64 65 const success = await this.copyText(text); 66 67 if (success && button) { 68 this.showButtonFeedback(button); 69 } 70 71 return success; 72 }, 73 74 /** 75 * Show temporary "Copied!" feedback on button 76 * @param {Element} button - Button element 77 */ 78 showButtonFeedback(button) { 79 const originalText = button.textContent || button.innerText; 80 81 button.textContent = 'Copied!'; 82 setTimeout(() => { 83 button.textContent = originalText; 84 }, 2000); 85 } 86};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.