PageSourceSearch

https://megawrzuta.pl/mw/assets/js/popupConsent.js?v=2.2

js megawrzuta.pl collected 2026-10-02 03:02:24 UTC 6,206 bytes, 161 lines download raw bytes

1(function () {
2    "use strict";
3    
4    var popupCookieDuration = typeof window.popupCookieDuration !== 'undefined' ? window.popupCookieDuration : 4;
5    
6    // delay przychodzi w sekundach → konwersja do ms
7    var delaySeconds = typeof window.popupDelay !== 'undefined' ? window.popupDelay : 10; // fallback 10 s
8    var popupDelayMs = Math.max(0, Number(delaySeconds) * 1000 || 0);
9    
10    var popupConsent = $('#popupConsent');
11    var popupAccept = document.querySelector(".popupaccept");
12    // var popupClose = document.querySelectorAll(".popupclose");
13
14    // Tworzymy nazwę cookie z wartością popupCookieDuration
15    var cookieName = "popupConsent" + popupCookieDuration;
16
17    var adBlockWallIsEnabled = typeof window.adBlockWallIsEnabled !== 'undefined' ? window.adBlockWallIsEnabled : false;
18
19    // Cele w analizach Megaserwera (zdarzenia niestandardowe)
20    var goals = {
21        popupShown: 'og86li5itkqx5eng',
22        popupAccepted: 'ksjvoy0mlvbxby1j',
23        adBlockWallShown: 'rcsp65jf5xcfwwas',
24        adBlockDisabled: 'dsnfakdw1x7htlem'
25    };
26    var adBlockWallShownKey = 'adBlockWallShown';
27
28    if (adBlockWallIsEnabled) {
29        detectAdBlock(function (isBlocked) {
30            if (isBlocked) {
31                showAdBlockWall();
32            } else {
33                // Ta sama karta widziała wcześniej blokadę, a teraz adblocka nie ma = przekonany
34                if (storageGet(adBlockWallShownKey)) {
35                    storageRemove(adBlockWallShownKey);
36                    trackGoal(goals.adBlockDisabled);
37                }
38                schedulePopupConsent();
39            }
40        });
41    } else {
42        schedulePopupConsent();
43    }
44
45    // Ten sam modal, zamiast reklamy alert o blokadzie. Pokazywany 
45natychmiast,
46    // bez ciasteczka. X i "Rozumiem" przeładowują stronę = ponowne sprawdzenie
47    // (filtry kosmetyczne adblocka znikają dopiero po przeładowaniu).
48    function showAdBlockWall() {
49        $('#popupConsentAdBlock').removeClass('d-none');
50        $('#popupConsentAd').addClass('d-none');
51        $(popupAccept).removeClass('btn-light').addClass('btn-primary').text(popupAccept.getAttribute('data-ad-block-label'));
52
53        popupConsent.on('hide.bs.modal', function (event) {
54            event.preventDefault();
55            window.location.reload();
56        });
57
58        popupConsent.modal({ backdrop: 'static', keyboard: false, show: true });
59
60        // Liczymy raz na kartę — X/"Okej, jasne" przeładowują stronę i pokazują blokadę ponownie
61        if (!storageGet(adBlockWallShownKey)) {
62            storageSet(adBlockWallShownKey, '1');
63            trackGoal(goals.adBlockWallShown);
64        }
65    }
66
67    function schedulePopupConsent() {
68        if (!getCookie(cookieName)) {
69            setTimeout(function () {
70                popupConsent.modal('show');
71                trackGoal(goals.popupShown);
72            }, popupDelayMs);
73        }
74    }
75
76    // Metoda Altum: przynęta z klasami reklamowymi, ukrywana przez filtry kosmetyczne
77    // rozszerzeń (uBlock, AdBlock, AdGuard). Wbudowanej ochrony przed śledzeniem
78    // w trybie prywatnym (Firefox, Safari) celowo nie traktujemy jako adblocka.
79    function detectAdBlock(callback) {
80        var bait = document.createElement('div');
81        bait.className = 'textads banner-ads banner_ads ad-unit ad-zone ad-space adsbox';
82        bait.style.cssText = 'position:absolute;left:-9999px;top:-9999px;width:1px;height:1px;';
83        document.body.appendChild(bait);
84        var baitIsHidden = bait.offsetHeight === 0 || window.getComputedStyle(bait).display === 'none';
85        bait.parentNode.removeChild(bait);
86
87        callback(baitIsHidden);
88    }
89
90    function closePopupConsent() {
91        setCookie(cookieName, true, popupCookieDuration);
92        popupConsent.modal('hide');
93        trackGoal(goals.popupAccepted);
94    }
95
96    // Skrypt analiz ładuje się asynchronicznie, a blokada pokazuje się natychmiast —
97    // ponawiamy przez kilka sekund. Brak analiz nie może psuć popupu.
98    function trackGoal(key, attempt) {
99        attempt = attempt || 0;
100        if (window.my_analytics && typeof window.my_analytics.goal === 'function') {
101            try { window.my_analytics.goal(key); } catch (e) {}
102            return;
103        }
104        if (attempt < 20) {
105            setTimeout(function () { trackGoal(key, attempt + 1); }, 250);
106        }
107    }
108
109    function storageGet(key) {
110        try { return window.sessionStorage.getItem(key); } catch (e) { return null; }
111    }
112
113    function storageSet(key, value) {
114        try { window.sessionStorage.setItem(key, value); } catch (e) {}
115    }
116
117    function storageRemove(key) {
118        try { window.sessionStorage.removeItem(key); } catch (e) {}
119    }
120
121    popupAccept.addEventListener("click", function () {
122        if (adBlockWallIsActive()) {
123            // Regulamin zaakceptowany — po wyłączeniu adblocka nie pokazujemy już popupu z reklamą
124            setCookie(cookieName, true, popupCookieDuration);
125            window.location.reload();
126            return;
127        }
128        closePopupConsent();
129    });
130
131    function adBlockWallIsActive() {
132        var alert = document.getElementById('popupConsentAdBlock');
133        return alert !== null && !alert.classList.contains('d-none');
134    }
135    // popupClose.forEach(function(button) {
136    //     button.addEventListener("click", closePopupConsent);
137    // });
138
139    function setCookie(cname, cvalue, exdays) {
140        var d = new Date();
141        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
142        var expires = "expires=" + d.toUTCString();
143        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;SameSite=Lax";
144    }
145
146    function getCookie(cname) {
147        var name = cname + "=";
148        var decodedCookie = decodeURIComponent(document.cookie);
149        var ca = decodedCookie.split(';');
150        for (var i = 0; i < ca.length; i++) {
151            var c = ca[i];
152            while (c.charAt(0) === ' ') {
153                c = c.substring(1);
154            }
155            if (c.indexOf(name) === 0) {
156                return c.substring(name.length, c.length);
157            }
158        }
159        return "";
160    }
161})();

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.