adblocker-enabled.js
2 years ago
adblocker-enabled.min.js
1 year ago
ga-adblock-counter.js
4 years ago
ga-adblock-counter.min.js
1 year ago
public.php
1 year ago
adblocker-enabled.js
63 lines
| 1 | /** |
| 2 | * Check if an ad blocker is enabled. |
| 3 | * |
| 4 | * @param function callback A callback function that is executed after the check has been done. |
| 5 | * The 'isEnabled' (bool) variable is passed as the callback's first argument. |
| 6 | */ |
| 7 | window.advanced_ads_check_adblocker = (function (callback) { |
| 8 | let pendingCallbacks = []; |
| 9 | let isEnabled = null; |
| 10 | |
| 11 | function RAF(RAF_callback) { |
| 12 | const fn = |
| 13 | window.requestAnimationFrame || |
| 14 | window.mozRequestAnimationFrame || |
| 15 | window.webkitRequestAnimationFrame || |
| 16 | function (RAF_callback) { |
| 17 | return setTimeout(RAF_callback, 16); |
| 18 | }; |
| 19 | |
| 20 | fn.call(window, RAF_callback); |
| 21 | } |
| 22 | |
| 23 | RAF(function () { |
| 24 | // Create a bait. |
| 25 | const ad = document.createElement('div'); |
| 26 | ad.innerHTML = ' '; |
| 27 | ad.setAttribute('class', 'ad_unit ad-unit text-ad text_ad pub_300x250'); |
| 28 | ad.setAttribute( |
| 29 | 'style', |
| 30 | 'width: 1px !important; height: 1px !important; position: absolute !important; left: 0px !important; top: 0px !important; overflow: hidden !important;' |
| 31 | ); |
| 32 | document.body.appendChild(ad); |
| 33 | |
| 34 | RAF(function () { |
| 35 | const styles = window.getComputedStyle?.(ad); |
| 36 | const mozBinding = styles?.getPropertyValue('-moz-binding'); |
| 37 | |
| 38 | isEnabled = |
| 39 | (styles && styles.getPropertyValue('display') === 'none') || |
| 40 | (typeof mozBinding === 'string' && |
| 41 | mozBinding.indexOf('about:') !== -1); |
| 42 | |
| 43 | // Call pending callbacks. |
| 44 | for (var i = 0, length = pendingCallbacks.length; i < length; i++) { |
| 45 | pendingCallbacks[i](isEnabled); |
| 46 | } |
| 47 | pendingCallbacks = []; |
| 48 | }); |
| 49 | }); |
| 50 | |
| 51 | return function (callback) { |
| 52 | if ('undefined' === typeof advanced_ads_adblocker_test) { |
| 53 | isEnabled = true; |
| 54 | } |
| 55 | if (isEnabled === null) { |
| 56 | pendingCallbacks.push(callback); |
| 57 | return; |
| 58 | } |
| 59 | // Run the callback immediately |
| 60 | callback(isEnabled); |
| 61 | }; |
| 62 | })(); |
| 63 |