1// ФÑнкÑÐ¸Ñ Ð´Ð»Ñ Ð³ÐµÐ½ÐµÑаÑии QR-кода ÑеÑез Google Charts API 2function generateQRCode(url, size = 250) { 3 const encodedUrl = encodeURIComponent(url); 4 return `https://chart.googleapis.com/chart?chs=${size}x${size}&cht=qr&chl=${encodedUrl}&choe=UTF-8&chld=H|0`; 5} 6 7// ФÑнкÑÐ¸Ñ Ð´Ð»Ñ ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð¿Ð¾Ð´Ð³Ð¾Ñовленного конÑенÑа Ð´Ð»Ñ Ð¿ÐµÑаÑи 8function prepareContentForPrint() { 9 const mainContent = document.querySelector('.page__text'); 10 if (!mainContent) { 11 console.error('ÐÑновной конÑÐµÐ½Ñ ÑÑаÑÑи не найден'); 12 return null; 13 } 14 15 // Создаем глÑбокий клон конÑенÑа 16 const printContent = mainContent.cloneNode(true); 17 18 // УдалÑем ÑлеменÑÑ, коÑоÑÑе не Ð´Ð¾Ð»Ð¶Ð½Ñ Ð¿Ð¾Ð¿Ð°ÑÑÑ Ð² пеÑаÑÑ 19 const elementsToRemove = printContent.querySelectorAll( 20 '.no-print, .print-action-btn, .social-share, .comments, form, iframe, script, ' + 21 'nav, .breadcrumbs, .breadcrumb, .share-buttons, header, footer, aside, ' + 22 '.chat-window, .chat-button, .modal, .popup, button, input, textarea, select' 23 ); 24 elementsToRemove.forEach(el => el.remove()); 25 26 // УбиÑаем пеÑвÑе ÑпиÑки (5 ÑоÑек) 27 const firstLists = printContent.querySelectorAll('ul, ol'); 28 for (let i = 0; i < Math.min(3, firstLists.length); i++) { 29 const list = firstLists[i]; 30 const items = list.querySelectorAll('li'); 31 if (items.length <= 6) { 32 list.remove(); 33 } 34 } 35 36 // ÐбÑабоÑка подпиÑей - иÑпÑавлÑем ÑÑÑÑкÑÑÑÑ 37 const authorCards = printContent.querySelectorAll('.BQ-author-card'); 38 authorCards.forEach(card => { 39 // УбедимÑÑ, ÑÑо ÑоÑо и конÑÐµÐ½Ñ Ð² пÑавилÑном поÑÑдке 40 const avatar = card.querySelector('.BQ-author-card__avatar'); 41 const content = card.querySelector('.BQ-author-card__content'); 42 43 if (avatar && content) { 44 // ÐеÑемеÑаем ÑоÑо в наÑало (Ñлева) 45 card.prepend(avatar); 46 47 // УменÑÑаем ÑоÑо 48 const img = avatar.querySelector('img'); 49 if (img) { 50 img.style.width = '15mm'; 51 img.style.height = '15mm'; 52 img.style.borderRadius = '50%'; 53 img.style.border = '1pt solid #ccc'; 54 img.style.objectFit = 'cover'; 55 } 56 57 // УбиÑаем подÑеÑкивание Ñ Ñио и ÑменÑÑаем ÑÑиÑÑ 58 const links = content.querySelectorAll('a'); 59 links.forEach(link => { 60 link.style.textDecoration = 'none'; 61 link.style.color = '#000'; 62 }); 63 64 // ÐобавлÑем оÑÑÑÑп Ñлева как в ÑиÑаÑÐ°Ñ 65 card.style.paddingLeft = '10mm'; 66 } 67 }); 68 69 // УбиÑаем ненÑжнÑе изобÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð² дÑÑÐ³Ð¸Ñ Ð¼ÐµÑÑÐ°Ñ 70 const imagesToRemove = printContent.querySelectorAll( 71 '.BQ-expert-approach img, .expert-approach img, [class*="expert"] img, ' + 72 '[class*="approach"] img, .expert-photo img, .author-photo img, .profile-photo img' 73 ); 74 imagesToRemove.forEach(img => img.remove()); 75 76 // Создаем авÑомаÑиÑеÑкое ÑодеÑжание, еÑли его Ð½ÐµÑ 77 const hasToc = printContent.querySelector('.toc, .table-of-contents, #toc'); 78 if (!hasToc) { 79 const headings = printContent.querySelectorAll('h2'); 80 if (headings.length > 0) { 81 const toc = document.createElement('div'); 82 toc.className = 'table-of-contents'; 83 const list = document.createElement('ol'); 84
85 headings.forEach((heading, index) => { 86 const listItem = document.createElement('li'); 87 const link = document.createElement('a'); 88 link.href = `#heading-${index}`; 89 link.textContent = heading.textContent; 90 link.style.textDecoration = 'none'; 91 link.style.color = '#000'; 92 listItem.appendChild(link); 93 list.appendChild(listItem); 94 95 heading.id = `heading-${index}`; 96 }); 97 98 toc.appendChild(list); 99 const h1 = printContent.querySelector('h1'); 100 if (h1) { 101 h1.parentNode.insertBefore(toc, h1.nextSibling); 102 } 103 } 104 } 105 106 return printContent; 107} 108 109// ÐÑÐ½Ð¾Ð²Ð½Ð°Ñ ÑÑнкÑÐ¸Ñ Ð¿ÐµÑаÑи ÑеÑез ÐºÐ½Ð¾Ð¿ÐºÑ 110window.printArticle = function() { 111 const printContent = prepareContentForPrint(); 112 if (!printContent) { 113 alert('Ðе ÑдалоÑÑ Ð¿Ð¾Ð´Ð³Ð¾ÑовиÑÑ ÐºÐ¾Ð½ÑÐµÐ½Ñ Ð´Ð»Ñ Ð¿ÐµÑаÑи'); 114 return; 115 } 116 117 // ÐенеÑиÑÑем QR-код 118 const currentUrl = window.location.href; 119 const qrCodeUrl = generateQRCode(currentUrl, 200); 120 121 // Создаем HTML Ð´Ð»Ñ Ð¿ÐµÑаÑи 122 const printHtml = ` 123 <!DOCTYPE html> 124 <html> 125 <head> 126 <meta charset="utf-8"> 127 <title>${document.title || 'ÐеÑаÑÑ ÑÑаÑÑи'}</title> 128 <style> 129 body { 130 margin: 0; 131 padding: 0; 132 font-family: 'Arial', sans-serif; 133 } 134 @page { 135 margin: 2cm 1cm 2.5cm 2cm; 136 } 137 .no-print { display: none !important; } 138 </style> 139 <link rel="stylesheet" href="/assets/styles/print-styles.css"> 140 </head> 141 <body> 142 <div class="page__text"> 143 ${printContent.innerHTML} 144 <div class="print-qr-code"> 145 <p>ÐÐ»Ñ Ð¾Ð½Ð»Ð°Ð¹Ð½-веÑÑии ÑÑаÑÑи оÑÑканиÑÑйÑе QR-код:</p> 146 <img src="${qrCodeUrl}" alt="QR-код ÑÑаÑÑи" 147 onerror="this.style.display='none'; this.parentNode.querySelector('.print-qr-code p').innerHTML='Ðнлайн-веÑÑиÑ: ${currentUrl}';"> 148 <p>Ðли пеÑейдиÑе по ÑÑÑлке:<br> 149 <small>${currentUrl}</small></p> 150 </div> 151 </div> 152 </body> 153 </html> 154 `; 155 156 // ÐÑкÑÑваем новое окно Ð´Ð»Ñ Ð¿ÐµÑаÑи 157 const printWindow = window.open('', '_blank', 'width=800,height=600'); 158 159 if (!printWindow) { 160 alert('РазÑеÑиÑе вÑплÑваÑÑие окна Ð´Ð»Ñ Ð¿ÐµÑаÑи ÑÑаÑÑи'); 161 return; 162 } 163 164 printWindow.document.write(printHtml); 165 printWindow.document.close(); 166 167 // Ðдем загÑÑзки ÑÑилей и запÑÑкаем пеÑаÑÑ 168 setTimeout(() => { 169 printWindow.focus(); 170 printWindow.print(); 171 printWindow.onafterprint = () => setTimeout(() => printWindow.close(), 100); 172 }, 500); 173}; 174 175// ÐбÑабоÑÑик Ctrl+P Ð´Ð»Ñ ÑÑандаÑÑной пеÑаÑи бÑаÑзеÑа 176document.addEventListener('keydown', function(e) { 177 if ((e.ctrlKey || e.metaKey) && e.key === 'p') { 178 e.preventDefault(); 179 e.stopImmediatePropagation(); 180 181 // ÐÑеменно ÑкÑÑваем вÑплÑваÑÑие окна 182 const popups = document.querySelectorAll('.chat-window, .modal, .popup, [class*="chat"]'); 183 const originalStyles = []; 184 185 popups.forEach(popup => { 186 originalStyles.push({ 187 element: popup, 188 display: popup.style.display, 189 className: popup.className 190 }); 191 popup.style.display = 'none'; 192 popup.classList.add('no-print'); 193 }); 194 195 // ÐобавлÑем QR-код в ÐºÐ¾Ð½ÐµÑ ÑÑаÑÑи 196 const mainContent = document.querySelector('.page__text'); 197 if (mainContent) { 198 const currentUrl = window.location.href; 199 const qrCodeUrl = generateQRCode(currentUrl, 150); 200 201 const qrCodeDiv = document.createElement('div'); 202 qrCodeDiv.className = 'print-qr-code no-print'; 203 qrCodeDiv.innerHTML = ` 204 <p>ÐÐ»Ñ Ð¾Ð½Ð»Ð°Ð¹Ð½-веÑÑии ÑÑаÑÑи оÑÑканиÑÑйÑе QR-код:</p> 205 <img src="${qrCodeUrl}" alt="QR-код ÑÑаÑÑи" 206 onerror="this.style.display='none';"> 207 <p>Ðли пеÑейдиÑе по ÑÑÑлке:<br> 208 <small>${currentUrl}</small></p> 209 `; 210 211 mainContent.appendChild(qrCodeDiv); 212 } 213 214 // ÐапÑÑкаем ÑÑандаÑÑнÑÑ Ð¿ÐµÑаÑÑ 215 setTimeout(() => { 216 window.print(); 217 218 // ÐоÑÑÑанавливаем ÑоÑÑоÑние поÑле пеÑаÑи 219 setTimeout(() => { 220 const qrCode = document.querySelector('.print-qr-code.no-print'); 221 if (qrCode) { 222 qrCode.remove(); 223 } 224
225 originalStyles.forEach(style => { 226 if (style.element) { 227 style.element.style.display = style.display; 228 style.element.classList.remove('no-print'); 229 } 230 }); 231 }, 100); 232 }, 100); 233 234 return false; 235 } 236}, true); 237 238// ÐниÑиализаÑÐ¸Ñ Ð¿Ñи загÑÑзке ÑÑÑаниÑÑ 239document.addEventListener('DOMContentLoaded', function() { 240 console.log('СиÑÑема пеÑаÑи иниÑиализиÑована'); 241 242 // ÐобавлÑем ÐºÐ½Ð¾Ð¿ÐºÑ Ð¿ÐµÑаÑи, еÑли ÐµÑ Ð½ÐµÑ 243 if (!document.querySelector('.print-action-btn')) { 244 const printBtn = document.createElement('button'); 245 printBtn.className = 'print-action-btn'; 246 printBtn.onclick = window.printArticle; 247 printBtn.title = 'РаÑпеÑаÑаÑÑ ÑÑаÑÑÑ'; 248 printBtn.innerHTML = 'ð¨ï¸ ÐеÑаÑÑ'; 249 250 const pageBottom = document.querySelector('.page__bottom'); 251 if (pageBottom) { 252 // ÐÑÑавлÑем ÐºÐ½Ð¾Ð¿ÐºÑ Ð¿ÐµÑед ÑоÑ. кнопками 253 const socialButtons = pageBottom.querySelector('.social-share, .share-buttons'); 254 if (socialButtons) { 255 pageBottom.insertBefore(printBtn, socialButtons); 256 } else { 257 pageBottom.appendChild(printBtn); 258 } 259 } 260 } 261 262 // ÐомеÑаем вÑплÑваÑÑие окна как no-print 263 const popups = document.querySelectorAll('.chat-window, .modal, .popup'); 264 popups.forEach(popup => { 265 popup.classList.add('no-print'); 266 }); 267}); 268 269 270function generateQRCodeWithLogo(url, size = 250) { 271 // ÐлÑÑеÑнаÑивнÑе ÑеÑвиÑÑ Ð´Ð»Ñ Ð³ÐµÐ½ÐµÑаÑии QR-кодов 272 const services = [ 273 `https://api.qrserver.com/v1/create-qr-code/?size=${size}x${size}&data=${encodeURIComponent(url)}&margin=10`, 274 `https://quickchart.io/qr?text=${encodeURIComponent(url)}&size=${size}&margin=2`, 275 `https://chart.googleapis.com/chart?chs=${size}x${size}&cht=qr&chl=${encodeURIComponent(url)}&choe=UTF-8` 276 ]; 277 return services[0]; // ÐÑполÑзÑем пеÑвÑй ÑеÑÐ²Ð¸Ñ 278} 279 280 281// Ð ÑÑнкÑии printArticle добавиÑÑ: 282const printDate = new Date().toLocaleDateString('ru-RU', { 283 day: 'numeric', 284 month: 'long', 285 year: 'numeric' 286}); 287 288const printFooter = ` 289 <div class="print-footer-info"> 290 РаÑпеÑаÑано: ${printDate} | ${document.title} 291 </div> 292`;
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.