diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2022-04-19 00:53:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-19 00:53:04 +0300 |
commit | 40ed028a7ee4487033a2ff6f1a3e3df11ad96718 (patch) | |
tree | 6c0a6e3fb7013fa4b5e81e18de7a873c6d4f2a6e /plugins/CoreHome/templates | |
parent | ac98a890c70ffe22bd80948b23fa559a81636a3d (diff) |
Perform adblock test after page has finished loading, not immediately. (#19106)
Diffstat (limited to 'plugins/CoreHome/templates')
-rw-r--r-- | plugins/CoreHome/templates/_adblockDetect.twig | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/plugins/CoreHome/templates/_adblockDetect.twig b/plugins/CoreHome/templates/_adblockDetect.twig index f60d2ac0e3..22d02e8c2f 100644 --- a/plugins/CoreHome/templates/_adblockDetect.twig +++ b/plugins/CoreHome/templates/_adblockDetect.twig @@ -1,42 +1,44 @@ <div id="bottomAd" style="font-size: 2px;"> </div> <script type="text/javascript"> - if ('undefined' === (typeof hasBlockedContent) || hasBlockedContent !== false) { - {# if hasBlockedContent was "false" most likely nothing was blocked #} - (function () { - {# most likely jQuery is not available, have to use vanilla JS here #} - var body = document.getElementsByTagName('body'); + window.addEventListener('DOMContentLoaded', function () { + if ('undefined' === (typeof hasBlockedContent) || hasBlockedContent !== false) { + {# if hasBlockedContent was "false" most likely nothing was blocked #} + (function () { + {# most likely jQuery is not available, have to use vanilla JS here #} + var body = document.getElementsByTagName('body'); - if (!body || !body[0]) { - return; - } + if (!body || !body[0]) { + return; + } - var bottomAd = document.getElementById('bottomAd'); - var wasMostLikelyCausedByAdblock = false; + var bottomAd = document.getElementById('bottomAd'); + var wasMostLikelyCausedByAdblock = false; - if (!bottomAd) { - wasMostLikelyCausedByAdblock = true; - } else if (bottomAd.style && bottomAd.style.display === 'none') { - wasMostLikelyCausedByAdblock = true; - } else if ('undefined' !== (typeof bottomAd.clientHeight) && bottomAd.clientHeight === 0) { - wasMostLikelyCausedByAdblock = true; - } + if (!bottomAd) { + wasMostLikelyCausedByAdblock = true; + } else if (bottomAd.style && bottomAd.style.display === 'none') { + wasMostLikelyCausedByAdblock = true; + } else if ('undefined' !== (typeof bottomAd.clientHeight) && bottomAd.clientHeight === 0) { + wasMostLikelyCausedByAdblock = true; + } - if (wasMostLikelyCausedByAdblock) { - var shouldGetHiddenElement = document.getElementById("should-get-hidden"); - var warning = document.createElement('p'); - warning.innerText = '{{ 'CoreHome_AdblockIsMaybeUsed'|translate|e('js') }}'; + if (wasMostLikelyCausedByAdblock) { + var shouldGetHiddenElement = document.getElementById("should-get-hidden"); + var warning = document.createElement('p'); + warning.innerText = '{{ 'CoreHome_AdblockIsMaybeUsed'|translate|e('js') }}'; - if (shouldGetHiddenElement) { - shouldGetHiddenElement.appendChild(warning); - } else { - body[0].insertBefore(warning, body[0].firstChild); - warning.style.color = 'red'; - warning.style.fontWeight = 'bold'; - warning.style.marginLeft = '16px'; - warning.style.marginBottom = '16px'; - warning.style.fontSize = '20px'; + if (shouldGetHiddenElement) { + shouldGetHiddenElement.appendChild(warning); + } else { + body[0].insertBefore(warning, body[0].firstChild); + warning.style.color = 'red'; + warning.style.fontWeight = 'bold'; + warning.style.marginLeft = '16px'; + warning.style.marginBottom = '16px'; + warning.style.fontSize = '20px'; + } } - } - })(); - } + })(); + } + }); </script>
\ No newline at end of file |