Skip to content

Commit b5cb6b9

Browse files
committed
Restore 1 day interval to re-show pop up ad
1 parent 06a033a commit b5cb6b9

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
{% import '@phpbb_ads/phpbb_ads_macro.html' as ad %}
22
<script>
3-
(function($, window, document, phpbb) {
3+
(() => {
44
'use strict';
55

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+
);
1032
}
1133
});
12-
})(jQuery, window, document, phpbb);
34+
})();
1335
</script>

0 commit comments

Comments
 (0)