|
1 | 1 | {% import '@phpbb_ads/phpbb_ads_macro.html' as ad %} |
2 | 2 | <script> |
3 | | - (function($, window, document, phpbb) { |
| 3 | + (() => { |
4 | 4 | 'use strict'; |
5 | 5 |
|
6 | | - $(window).on('load', function() { |
7 | | - if (!localStorage.getItem('phpbb_ads_pop_up')) { |
8 | | - localStorage.setItem('phpbb_ads_pop_up', 'true'); |
9 | | - phpbb.alert('{{ lang('ADVERTISEMENT')|upper|e('js') }}', `{{ ad.renderAds(AD_POP_UP, AD_POP_UP_ID, AD_POP_UP_CENTER, 'margin: 0;') }}`); |
| 6 | + const STORAGE_KEY = 'phpbb_ads_pop_up'; |
| 7 | + const SHOW_INTERVAL_DAYS = 1; // now set to 1 day |
| 8 | + |
| 9 | + const shouldShowAd = () => { |
| 10 | + const lastShown = localStorage.getItem(STORAGE_KEY); |
| 11 | + |
| 12 | + if (!lastShown) { |
| 13 | + return true; // never shown before |
| 14 | + } |
| 15 | + |
| 16 | + const lastShownDate = new Date(parseInt(lastShown, 10)); |
| 17 | + const now = new Date(); |
| 18 | + const diffDays = (now - lastShownDate) / (1000 * 60 * 60 * 24); |
| 19 | + |
| 20 | + return diffDays >= SHOW_INTERVAL_DAYS; |
| 21 | + }; |
| 22 | + |
| 23 | + window.addEventListener('load', () => { |
| 24 | + if (shouldShowAd()) { |
| 25 | + // Save the current timestamp |
| 26 | + localStorage.setItem(STORAGE_KEY, Date.now().toString()); |
| 27 | + |
| 28 | + phpbb.alert( |
| 29 | + '{{ lang('ADVERTISEMENT')|upper|e('js') }}', |
| 30 | + `{{ ad.renderAds(AD_POP_UP, AD_POP_UP_ID, AD_POP_UP_CENTER, 'margin: 0;') }}` |
| 31 | + ); |
10 | 32 | } |
11 | 33 | }); |
12 | | - })(jQuery, window, document, phpbb); |
| 34 | + })(); |
13 | 35 | </script> |
0 commit comments