PageSourceSearch

https://www.belnovosti.by/c/s2/cookie-consent.js

js belnovosti.by collected 2026-10-01 10:36:56 UTC 18,081 bytes, 561 lines download raw bytes

1// ==================== 1. ОЧИСТКА КУК ====================
2function deleteCookie(name) {
3    var domain = location.hostname.replace(/^www\./, '');
4    document.cookie = name + '=; Max-Age=-99999999; path=/;';
5    document.cookie = name + '=; Max-Age=-99999999; path=/; domain=' + domain + ';';
6    document.cookie = name + '=; Max-Age=-99999999; path=/; domain=.' + domain + ';';
7}
8
9function clearAnalyticsCookies() {
10    deleteCookie('_ym_uid');
11    deleteCookie('_ym_d');
12    deleteCookie('_ym_isad');
13    deleteCookie('_ym_visorc');
14    deleteCookie('_ym_metrika_enabled');
15    deleteCookie('_ga');
16    deleteCookie('_gid');
17    deleteCookie('_gcl');
18    document.cookie.split(';').forEach(function(c) {
19        var name = c.split('=')[0].trim();
20        if (name.indexOf('_ga') === 0) deleteCookie(name);
21    });
22    try {
23      localStorage.removeItem('_ym_uid');
24      localStorage.removeItem('_ym_synced');
25      localStorage.removeItem('_ym_retryIds');
26      sessionStorage.removeItem('_ym_synced');
27    } catch(e) {}
28}
29
30function clearAdvertisingCookies() {
31    // Яндекс.Реклама
32    deleteCookie('_yandex_uid');
33    deleteCookie('adfox_uid');
34    // Google AdSense (если куки все же были созданы)
35    deleteCookie('__gads');
36    deleteCookie('__gac');
37    deleteCookie('__gcl');
38    deleteCookie('_fbp');
39}
40
41function clearSearchCookies() {
42    deleteCookie('_gsc');
43    deleteCookie('_gss');
44    deleteCookie('_gac');
45    deleteCookie('_gcl');
46}
47
48function clearAllCookies() {
49    clearAnalyticsCookies();
50    clearAdvertisingCookies();
51    clearSearchCookies();
52}
53
54// ==================== 2. ИНИЦИАЛИЗАЦИЯ GOOGLE TAG (gtag.js) ====================
55// Эта функция загружает gtag.js и устанавливает начальное состояние согласия.
56// Она вызывается один раз при загрузке страницы.
57function initGoogleTag() {
58    // Загружаем скрипт gtag.js
59    var script = document.createElement('script');
60    script.async = true;
61    script.src = 'https://www.googletagmanager.com/gtag/js?id=G-CWNDH7RNG7';
62    document.head.appendChild(script);
63
64    // Инициализируем глобальную функцию gtag
65    window.dataLayer = window.dataLayer || [];
66    function gtag(){ dataLayer.push(arguments); }
67    window.gtag = gtag; // Делаем gtag глобально доступной
68
69    // Устанавливаем значения по умолчанию (denied) ДО загрузки скрипта
70    // Это ключевой момент для Consent Mode
71    gtag('consent', 'default', {
72        'ad_storage': 'denied',
73        'ad_user_data': 'denied',
74        'ad_personalization': 'denied',
75        'analytics_storage': 'denied',
76        'wait_for_update': 500
77    });
78
79    // После загрузки применяем сохраненные настройки
80    script.onload = function() {
81        gtag('js', new Date());
82        gtag('config', 'G-CWNDH7RNG7');
83
84        // Применяем сохраненные настройки после инициализации
85        var prefs = loadPreferences();
86        if (prefs) {
87            applyGoogleConsent(prefs);
88        }
89    }; 
90}
91
92// ==================== 3. УПРАВЛЕНИЕ СОГЛАСИЕМ ДЛЯ GOOGLE ====================
93// Эта функция обновляет состояние согласия для Google через gtag('consent', 'update', ...)
94function applyGoogleConsent(prefs) {
95    if (typeof gtag !== 'function') return;
96
97    var analyticsStatus = (prefs && prefs.analytics) ? 'granted' : 'denied';
98    var adStatus = (prefs && prefs.advertising) ? 'granted' : 'denied';
99
100    gtag('consent', 'update', {
101        'analytics_storage': analyticsStatus,
102        'ad_storage': adStatus,
103        'ad_user_data': adStatus,
104        'ad_personalization': adStatus
105    });
106}
107
108var analyticsInitialized = false;
109function initAnalytics() {
110    if (analyticsInitialized) return;
111    analyticsInitialized = true;
112
113//     // Яндекс.Метрика
114//     (function() {
115//         var script = document.createElement('script');
116//         script.async = true;
117//         script.src = 'https://mc.yandex.ru/metrika/tag.js';
118//         document.head.appendChild(script);
119//         script.onload = function() {
120//             window.ym = window.ym || function() { (ym.a = ym.a || []).push(arguments); };
121//             ym(16666762, 'init', {
122//                 clickmap: true,
123//                 trackLinks: true,
124//                 accurateTrackBounce: true
125//             });
126//         };
127//     })();
128}
129
130
131// ==================== 4. ИНИЦИАЛИЗАЦИЯ ЯНДЕКС.РЕКЛАМЫ (AdFox) ====================
132var advertisingInitialized = false;
133
134function initYandexAdvertising(personalized) {
135    if (advertisingInitialized) return;
136    advertisingInitialized = true;
137
138    (function() {
139        var script = document.createElement('script');
140        script.async = true;
141        script.src = 'https://yandex.ru/ads/system/context.js';
142        document.head.appendChild(script);
143
144        function runAdFox() {
145            if (typeof Ya !== 'undefined' && Ya.adfoxCode) {
146                window.yaContextCb = window.yaContextCb || [];
147
148                 if (window.matchMedia("only screen and (max-device-width: 728px)").matches){
149                  // Mobile
150									var adfoxBlocks = [
151										{
152												ownerId: 261330,
153												containerId: 'adfox_177208899133668640',
154												params: {
155														p1: 'dmogq',
156														p2: 'gjzr'
157												}
158										},
159										{
160												ownerId: 261330,
161												containerId: 'adfox_177218222768798640',
162												params: {
163														p1: 'dmogu',
164														p2: 'gjzr'
165												}
166										},
167										{
168											ownerId: 261330,
169											containerId: 'adfox_177218426569928640',
170											params: {
171													p1: 'dmogx',
172													p2: 'gjzr'
173										  }
174										},
175										{
176												ownerId: 261330,
177												containerId: 'adfox_17722199530358640',
178												params: {
179														p1: 'dmohf',
180														p2: 'gjzr'
181												}
182										},
183										{
184												ownerId: 261330,
185												containerId: 'adfox_177222006538988640',
186												params: {
187														p1: 'dmohh',
188														p2: 'gjzr'
189												}
190										},
191										{
192												ownerId: 261330,
193												containerId: 'adfox_177222015720748640',
194												params: {
195														p1: 'dmohj',
196														p2: 'gjzr'
197												}
198										},
199										{
200												ownerId: 261330,
201												containerId: 'adfox_177200498215698640',
202												params: {
203														p1: 'dmohd',
204														p2: 'gjzr'
205												}
206										},
207										{
208												ownerId: 261330,
209												containerId: 'adfox_177218465067698640',
210												params: {
211														p1: 'dmohb',
212														p2: 'gjzr'
213												}
214										},
215										{
216												ownerId: 261330,
217												containerId: 'adfox_177222047684888640',
218												params: {
219														p1: 'dmohn',
220														p2: 'gjzr'
221												}
222										}
223									];
224                } else {
225                  // Desktop
226                  var adfoxBlocks = [
227											{
228													ownerId: 261330,
229													containerId: 'adfox_177208899133668640',
230													params: {
231															p1: 'dmogt',
232															p2: 'gjzs'
233													}
234											},
235											{
236													ownerId: 261330,
237													containerId: 'adfox_177218222768798640',
238													params: {
239															p1: 'dmogw',
240															p2: 'gjzs'
241													}
242											},
243											{
244													ownerId: 261330,
245													containerId: 'adfox_177218426569928640',
246													params: {
247															p1: 'dmogy',
248															p2: 'gjzs'
249													}
250											},
251											{
252													ownerId: 261330,
253													containerId: 'adfox_17722199530358640',
254													params: {
255															p1: 'dmohg',
256															p2: 'gjzs'
257													}
258											},
259											{
260													ownerId: 261330,
261													containerId: 'adfox_177222006538988640',
262													params: {
263															p1: 'dmohi',
264															p2: 'gjzs'
265													}
266											},
267											{
268													ownerId: 261330,
269													containerId: 'adfox_177222015720748640',
270													params: {
271															p1: 'dmohk',
272															p2: 'gjzs'
273													}
274											},
275										{
276												ownerId: 261330,
277												containerId: 'adfox_177200498215698640',
278												params: {
279														p1: 'dmohd',
280														p2: 'gjzr'
281												}
282										},
283										{
284												ownerId: 261330,
285												containerId: 'adfox_177218465067698640',
286												params: {
287														p1: 'dmohc',
288														p2: 'gjzs'
289												}
290										},
291										{
292												ownerId: 261330,
293												containerId: 'adfox_177222047684888640',
294												params: {
295														p1: 'dmohn',
296														p2: 'gjzr'
297												}
298										}
299									];
300                }
301
302                adfoxBlocks.forEach(function(block) {
303                    if (document.getElementById(block.containerId)) {
304                        window.yaContextCb.push(function() {
305                            var params = block.params || {};
306                            params['cookie-consent-flag'] = personalized ? 1 : 0;
307                            params['gdpr-consent-flag'] = personalized ? 1 : 0;
308                            Ya.adfoxCode.create({
309                                ownerId: block.ownerId,
310                                containerId: block.containerId,
311                                params: params
312                            });
313                        });
314                    }
315                });
316            } else {
317                setTimeout(runAdFox, 500);
318            }
319        }
320        script.onload = runAdFox;
321    })();
322}
323
324// ==================== 5. ИНИЦИАЛИЗАЦИЯ ПОИСКА (Google Custom Search) ====================
325var searchInitialized = false;
326
327function initSearch() {
328    if (searchInitialized) return;
329    searchInitialized = true;
330    (function() {
331        var cx = 'partner-pub-2594699865181708:7624390076';
332        var gcse = document.createElement('script');
333        gcse.async = true;
334        gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
335        document.head.appendChild(gcse);
336    })();
337}
338
339// ==================== 6. РАБОТА С НАСТРОЙКАМИ ====================
340function getDefaultPrefs() {
341    return { analytics: true, advertising: true, search: true };
342}
343
344function loadPreferences() {
345    var stored = localStorage.getItem('belnovosti_cookie_preferences');
346    if (stored) {
347        try { return JSON.parse(stored); } catch(e) { return null; }
348    }
349    return null;
350}
351
352function savePreferences(prefs) {
353    localStorage.setItem('belnovosti_cookie_preferences', JSON.stringify(prefs));
354}
355
356// ==================== 7. УПРАВЛЕНИЕ ИНТЕРФЕЙСОМ ====================
357function hideBanner() {
358    var notice = document.getElementById('cookieNotice');
359    if (notice) notice.style.display = 'none';
360}
361
362function showBanner() {
363    var notice = document.getElementById('cookieNotice');
364    if (notice) notice.style.display = 'block';
365}
366
367function hideModal() {
368    var modal = document.getElementById('cookieModal');
369    if (modal) modal.style.display = 'none';
370}
371
372function showModal() {
373    var modal = document.getElementById('cookieModal');
374    if (modal) modal.style.display = 'flex';
375    var prefs = loadPreferences() || getDefaultPrefs();
376    document.getElementById('prefAnalytics').checked = prefs.analytics;
377    document.getElementById('prefAdvertising').checked = prefs.advertising;
378    document.getElementById('prefSearch').checked = prefs.search;
379}
380
381function getCheckboxValues() {
382    return {
383        analytics: document.getElementById('prefAnalytics').checked,
384        advertising: document.getElementById('prefAdvertising').checked,
385        search: document.getElementById('prefSearch').checked
386    };
387}
388
389// ==================== 8. ОБРАБОТЧИКИ СОБЫТИЙ ====================
390function acceptAll() {
391    var prefs = getDefaultPrefs();
392    savePreferences(prefs);
393    initGoogleTag();
394    setTimeout(function() {applyGoogleConsent(prefs);}, 200);
395//         applyGoogleConsent(prefs); // Обновляем consent для Google
396    hideBanner();
397    hideModal();
398    // Перезагружаем, чтобы Яндекс.Реклама применила новый флаг
399    location.reload();
400}
401
402function saveCustom() {
403    var prefs = getCheckboxValues();
404    savePreferences(prefs);
405    if (prefs && prefs.analytics) {
406      initGoogleTag();
407      setTimeout(function() {applyGoogleConsent(prefs);}, 200);
408    } else {
409      applyGoogleConsent(prefs);
410      if (window.yaCounter16666762) {
411        window.yaCounter16666762 = null;
412      }
413      window['ga-disable-G-CWNDH7RNG7'] = true;
414    }
415    clearAllCookies();
416//         applyGoogleConsent(prefs); // Обновляем consent для Google
417    hideBanner();
418    hideModal();
419    location.reload();
420}
421
422function declineAll() {
423    var prefs = { analytics: false, advertising: false, search: false };
424    savePreferences(prefs);
425    applyGoogleConsent(prefs);
426    if (window.yaCounter16666762) {
427      window.yaCounter16666762 = null;
428    }
429    window['ga-disable-G-CWNDH7RNG7'] = true;
430    clearAllCookies();
431//     applyGoogleConsent(prefs); // Обновляем consent для Google
432    hideBanner();
433    hideModal();
434    location.reload();
435}
436
437// function revokeConsent() {
438//     localStorage.removeItem('belnovosti_cookie_preferences');
439//     clearAllCookies();
440//     // Сбрасываем consent для Google на 'denied'
441//     if (typeof gtag === 'function') {
442//         gtag('consent', 'update', {
443//             'analytics_storage': 'denied',
444//             'ad_storage': 'denied',
445//             'ad_user_data': 'denied',
446//             'ad_personalization': 'denied'
447//         });
448//     }
449//     location.reload();
450// }
451
452// ==================== 9. ЗАГРУЗКА СТРАНИЦЫ ====================
453document.addEventListener('DOMContentLoaded', function() {
454    // 1. Инициализируем Google Tag (gtag.js) с настройками по умолчанию (denied)
455    // Это нужно сделать как можно раньше
456//     initGoogleTag();
457
458    var prefs = loadPreferences();
459
460    if (prefs && prefs.analytics) {
461        // 1. Инициализируем Google Tag (gtag.js) с настройками по умолчанию (denied)
462        // Это нужно сделать как можно раньше
463        initGoogleTag();
464        // Небольшая задержка, чтобы дать время gtag.js полностью инициализироваться
465        setTimeout(function() {applyGoogleConsent(prefs);}, 200);
466        initAnalytics();
467    } else {
468      clearAnalyticsCookies();
469      window['ga-disable-G-CWNDH7RNG7'] = true;
470    }
471    
472    // 3. Яндекс.Реклама загружается всегда (с флагом персонализации)
473    var personalized = prefs ? prefs.advertising : false;
474    if (!personalized) {
475      clearAdvertisingCookies();
476    }
477    initYandexAdvertising(personalized);
478
479    // 4. Поиск – только при согласии
480    if (prefs && prefs.search) {
481        initSearch();
482    } else {
483      clearSearchCookies();
484    }
485
486    // 5. Показываем или скрываем баннер
487    if (prefs) {
488        hideBanner();
489    } else {
490        showBanner();
491        clearAllCookies(); 
492    }
493
494    // 6. Привязываем кнопки
495    var acceptBtn = document.getElementById('cookieAcceptBtn');
496//     var settingsBtn = document.getElementById('cookieSettingsBtn');
497    if (acceptBtn) acceptBtn.addEventListener('click', acceptAll);
498//     if (settingsBtn) settingsBtn.addEventListener('click', showModal);
499    
500    var declineBtn = document.getElementById('cookieDeclineAllBtn');
501    if (declineBtn) declineBtn.addEventListener('click', declineAll);
502
503    var modalSave = document.getElementById('modalSaveBtn');
504    var modalDecline = document.getElementById('modalDeclineAllBtn');
505    if (modalSave) modalSave.addEventListener('click', saveCustom);
506    if (modalDecline) modalDecline.addEventListener('click', declineAll);
507
508    var modal = document.getElementById('cookieModal');
509    if (modal) {
510        modal.addEventListener('click', function(e) {
511            if (e.target === modal) hideModal();
512        });
513    }
514
515//     var settingsLink = document.getElementById('cookieSettingsLink');
516//     if (settingsLink) {
517//         settingsLink.addEventListener('click', function(e) {
518//             e.preventDefault();
519//             var prefs = loadPreferences();
520//             if (prefs) {
521//                 showModal();
522//             } else {
523//                 showBanner();
524//             }
525//         });
526//     }
527    
528    var settingsLink = document.getElementById('cookieSettingsLink');
529    if (settingsLink) {
530        settingsLink.addEventListener('click', function(e) {
531            e.preventDefault();
532            showModal(); 
533        });
534    }
535    
536    var settingsLink = document.getElementById('cookieSettingsLinkBtn');
537    if (settingsLink) {
538        settingsLink.addEventListener('click', function(e) {
539            e.preventDefault();
540            showModal(); 
541        });
542    }
543    
544    if (document.querySelector('main article.article-container')) {
545			var fired = false;
546			window.addEventListener('scroll', () => {
547				if (fired === false) {
548					fired = true;
549					setTimeout(() => {
550						(function(){
551							var sNode = document.createElement('script');
552							sNode.src = '/c/s2/InfiniteScroll.js';
553							sNode.async = true;
554							document.body.appendChild(sNode);
555						})();
556					}, 200);
557				}
558			});
559		}
560
561});

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.