PageSourceSearch

https://nunatsiaq.com/wp-content/themes/nunatsiaq-news/js/adblock-notice.js?ver=1785123145

js nunatsiaq.com collected 2026-10-02 03:02:40 UTC 5,033 bytes, 176 lines download raw bytes

1(function () {
2    'use strict';
3
4    var config = window.nunatsiaqAdblockNotice || {};
5    var storageKey = config.storageKey || 'nunatsiaq-adblock-dismissed';
6    var dismissDays = Number(config.dismissDays) || 7;
7    var dialog = document.getElementById('adblock-notice');
8
9    if (!dialog) {
10        return;
11    }
12
13    function wasDismissedRecently() {
14        try {
15            var stored = localStorage.getItem(storageKey);
16            if (!stored) {
17                return false;
18            }
19
20            var dismissedAt = parseInt(stored, 10);
21            if (Number.isNaN(dismissedAt)) {
22                return false;
23            }
24
25            var dismissMs = dismissDays * 24 * 60 * 60 * 1000;
26            return Date.now() - dismissedAt < dismissMs;
27        } catch (error) {
28            return false;
29        }
30    }
31
32    function rememberDismissal() {
33        try {
34            localStorage.setItem(storageKey, String(Date.now()));
35        } catch (error) {
36            // Ignore storage failures.
37        }
38    }
39
40    function isBaitBlocked() {
41        var bait = document.createElement('div');
42        bait.innerHTML = '&nbsp;';
43        bait.className = 'adsbox pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links ad-banner adsbox';
44        bait.setAttribute('aria-hidden', 'true');
45        bait.style.cssText = 'position:absolute;top:-1px;left:-1px;width:1px;height:1px;pointer-events:none;';
46        document.body.appendChild(bait);
47
48        var style = window.getComputedStyle(bait);
49        var blocked = bait.offsetHeight === 0
50            || bait.clientHeight === 0
51            || style.display === 'none'
52            || style.visibility === 'hidden';
53
54        bait.remove();
55        return blocked;
56    }
57
58    function isAdSanityBlocked() {
59        var ads = document.querySelectorAll('.adsanity-inner, .adsanity-single, .adsanity-group');
60        if (!ads.length) {
61            return null;
62        }
63
64        for (var i = 0; i < ads.length; i++) {
65            var ad = ads[i];
66            if (ad.offsetHeight > 0 && ad.innerHTML.replace(/\s+/g, '').length > 0) {
67                return false;
68            }
69        }
70
71        return true;
72    }
73
74    function detectAdBlocker() {
75        return new Promise(function (resolve) {
76            window.setTimeout(function () {
77                var baitBlocked = isBaitBlocked();
78                var adsBlocked = isAdSanityBlocked();
79
80                if (adsBlocked === true) {
81                    resolve(true);
82                    return;
83                }
84
85                if (adsBlocked === false) {
86                    resolve(false);
87                    return;
88                }
89
90                resolve(baitBlocked);
91            }, 120);
92        });
93    }
94
95    function getFocusableElements() {
96        return dialog.querySelectorAll(
97            'a[href], button:not([disabled]), textarea, input, select, [tabindex]:not([tabindex="-1"])'
98        );
99    }
100
101    function trapFocus(event) {
102        if (event.key !== 'Tab' || !dialog.classList.contains('is-open')) {
103            return;
104        }
105
106        var focusable = getFocusableElements();
107        if (!focusable.length) {
108            return;
109        }
110
111        var first = focusable[0];
112        var last = focusable[focusable.length - 1];
113
114        if (event.shiftKey && document.activeElement === first) {
115            event.preventDefault();
116            last.focus();
117        } else if (!event.shiftKey && document.activeElement === last) {
118            event.preventDefault();
119            first.focus();
120        }
121    }
122
123    function openDialog() {
124        dialog.hidden = false;
125        dialog.classList.add('is-open');
126        document.body.classList.add('adblock-notice-open');
127
128        var primaryAction = dialog.querySelector('[data-adblock-action="refresh"]');
129        if (primaryAction) {
130            primaryAction.focus();
131        }
132
133        document.addEventListener('keydown', trapFocus);
134    }
135
136    function closeDialog() {
137        dialog.classList.remove('is-open');
138        dialog.hidden = true;
139        document.body.classList.remove('adblock-notice-open');
140        document.removeEventListener('keydown', trapFocus);
141    }
142
143    dialog.addEventListener('click', function (event) {
144        var action = event.target.closest('[data-adblock-action]');
145        if (!action) {
146            return;
147        }
148
149        if (action.getAttribute('data-adblock-action') === 'refresh') {
150            window.location.reload();
151            return;
152        }
153
154        if (action.getAttribute('data-adblock-action') === 'dismiss') {
155            rememberDismissal();
156            closeDialog();
157        }
158    });
159
160    dialog.addEventListener('keydown', function (event) {
161        if (event.key === 'Escape') {
162            rememberDismissal();
163            closeDialog();
164        }
165    });
166
167    if (wasDismissedRecently()) {
168        return;
169    }
170
171    detectAdBlocker().then(function (blocked) {
172        if (blocked) {
173            openDialog();
174        }
175    });
176}());

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.