1
document.getElementsByTagName('body')[0].addEventListener('click', function(e) {
2
if(localStorage.getItem('popunder_count') === null) {
3
localStorage.setItem('popunder_count', 0);
4
}
5
if (
6
(e.target.tagName == 'A')
7
|| ((e.target.tagName == 'IMG') && (e.target.parentNode.tagName == 'A'))
8
) {
9
var count = parseInt(localStorage.getItem('popunder_count')) + 1;
10
if(count > 12) {
11
count = 1;
12
}
13
if(
14
count === 2
15
|| count === 4
16
|| count === 9
17
|| count === 12
18
) {
19
var item = window.popunderLinks[Math.floor(Math.random()*window.popunderLinks.length)];
20
if(e.target.tagName == 'IMG') {
21
var href = e.target.parentNode.href;
22
} else {
23
var href = e.target.href;
24
}
25
window.open(href, '_blank');
26
window.location.href = item;
27
e.preventDefault();
28
}
29
localStorage.setItem('popunder_count', count);
30
}
31
});