1document.addEventListener('DOMContentLoaded', function() { 2 const buttons = document.querySelectorAll('.copy-btn'); 3 4 buttons.forEach(button => { 5 button.addEventListener('click', function() { 6 const targetId = button.getAttribute('data-target'); 7 const msgId = button.getAttribute('data-msg'); 8 9 const textEl = document.getElementById(targetId); 10 const msgEl = document.getElementById(msgId); 11 12 if (!textEl) return; 13 14 // ÐÑÑимÑÑмо ÑекÑÑ (Ñазом з емоджÑ) з <p> (Ñи ÑнÑого ÑегÑ). 15 const textToCopy = textEl.innerText || textEl.textContent; 16 17 // СпÑобÑÑмо API navigator.clipboard 18 if (navigator.clipboard && navigator.clipboard.writeText) { 19 navigator.clipboard.writeText(textToCopy) 20 .then(() => { 21 showCopiedMessage(button, msgEl); 22 }) 23 .catch(err => { 24 console.warn('navigator.clipboard.writeText не ÑпÑаÑÑвав, ÑпÑобÑÑмо fallback', err); 25 fallbackCopyText(textToCopy); 26 showCopiedMessage(button, msgEl); 27 }); 28 } else { 29 // ЯкÑо бÑаÑÐ·ÐµÑ ÑÑаÑий або забоÑонено, Ñобимо fallback 30 fallbackCopyText(textToCopy); 31 showCopiedMessage(button, msgEl); 32 } 33 }); 34 }); 35 36 /** 37 * ÐоказÑÑмо повÑÐ´Ð¾Ð¼Ð»ÐµÐ½Ð½Ñ Â«Copied!» Ñ Ð²Ð¼Ð¸ÐºÐ°Ñмо анÑмаÑÑÑ ÐºÐ½Ð¾Ð¿ÐºÐ¸. 38 */ 39 function showCopiedMessage(button, msgEl) { 40 // ÐнÑмаÑÑÑ ÐºÐ½Ð¾Ð¿ÐºÐ¸ 41 button.classList.add('clicked'); 42 setTimeout(() => { 43 button.classList.remove('clicked'); 44 }, 400); 45 46 // ÐоказÑÑмо «Copied!» на 2Ñ 47 if (msgEl) { 48 msgEl.style.display = 'inline'; 49 setTimeout(() => { 50 msgEl.style.display = 'none'; 51 }, 2000); 52 } 53 } 54 55 /** 56 * Fallback-меÑод ÑеÑез пÑÐ¸Ñ Ð¾Ð²Ð°Ð½Ð¸Ð¹ textarea + document.execCommand('copy'). 57 * ÐÑдÑÑимка ÑÑаÑÐ¸Ñ iOS Ñа деÑÐºÐ¸Ñ Android-бÑаÑзеÑÑв. 58 */ 59 function fallbackCopyText(text) { 60 const textArea = document.createElement('textarea'); 61 textArea.value = text; 62 63 // Щоб textarea не "ÑÑÑибав" по ÑÑоÑÑнÑÑ, Ð·Ð°Ñ Ð¾Ð²Ð°Ñмо його поза вÑкном 64 textArea.style.position = 'fixed'; 65 textArea.style.left = '-999999px'; 66 67 document.body.appendChild(textArea); 68 textArea.focus(); 69 textArea.select(); 70 71 try { 72 document.execCommand('copy'); 73 } catch (err) { 74 console.error('Fallback copy error:', err); 75 } 76 document.body.removeChild(textArea); 77 } 78 79});
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.