Skip to content

Commit 0f0acda

Browse files
committed
optimize javascript for pop up ad
1 parent b5cb6b9 commit 0f0acda

1 file changed

Lines changed: 8 additions & 23 deletions

File tree

styles/all/template/includes/phpbb_ads_pop_up.html

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,18 @@
33
(() => {
44
'use strict';
55

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());
6+
const key = 'phpbb_ads_pop_up';
7+
const interval_days = 1;
8+
const lastShown = localStorage.getItem(key);
279

10+
if (!lastShown || Date.now() - parseInt(lastShown, 10) >= interval_days * 86400000) {
11+
localStorage.setItem(key, Date.now());
12+
window.addEventListener('load', () => {
2813
phpbb.alert(
2914
'{{ lang('ADVERTISEMENT')|upper|e('js') }}',
3015
`{{ ad.renderAds(AD_POP_UP, AD_POP_UP_ID, AD_POP_UP_CENTER, 'margin: 0;') }}`
3116
);
32-
}
33-
});
17+
});
18+
}
3419
})();
3520
</script>

0 commit comments

Comments
 (0)