1var wonderads; 2var hideTimeout; 3 4document.addEventListener("DOMContentLoaded", function() { 5 'use strict'; 6 7 window.wonderads = { 8 9 getPushContentApi: function () { 10 if (!wonderads.isMobile()) { 11 return false; 12 } 13 console.log('wads init'); 14 15 var sitename = window.location.host.replace('www.', ''); 16 17 fetch('https://dashboard.wonderads.cloud/api/check_pushly?sitename=' + sitename) 18 .then(function(response) { 19 if (!response.ok) throw new Error('Network response was not ok'); 20 return response.json(); 21 }) 22 .then(function(data) { 23 console.log(data); 24 if (data && data.length) { 25 var data_single = data[Math.floor((Math.random() * data.length))]; 26 if (!wonderads.isTheSameUrl(data_single.link)) { 27 window.current_push = data_single; 28 wonderads.start(data_single); 29 } 30 } 31 }) 32 .catch(function(error) { 33 console.error('Error:', error); 34 }); 35 }, 36 37 isTheSameUrl: function(link){ 38 return window.location.href.includes(link); 39 }, 40 41 sendReportClick: function () { 42 if (!window.current_push) return; 43 window.current_push.sitename = window.location.host.replace('www.',''); 44 45 fetch('https://dashboard.wonderads.cloud/api/click_pushly', { 46 method: 'POST', 47 headers: { 48 'Content-Type': 'application/json; charset=utf-8' 49 }, 50 body: JSON.stringify(window.current_push) 51 }) 52 .then(function(response) { return response.json(); }) 53 .then(function(data) { console.log(data); }) 54 .catch(function(errMsg) { console.log(errMsg); }); 55 }, 56 57 sendReportImpression: function () { 58 if (!window.current_push) return; 59 window.current_push.sitename = window.location.host.replace('www.',''); 60 61 fetch('https://dashboard.wonderads.cloud/api/impression_pushly', { 62 method: 'POST', 63 headers: { 64 'Content-Type': 'application/json; charset=utf-8' 65 }, 66 body: JSON.stringify(window.current_push) 67 }) 68 .then(function(response) { return response.json(); }) 69 .then(function(data) { console.log(data); }) 70 .catch(function(errMsg) { console.log(errMsg); }); 71 }, 72 73 isMobile: function() { 74 return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 75 }, 76 77 close: function (push_id) { 78 clearTimeout(hideTimeout); 79 var container = document.querySelector('.wonderads_container'); 80 if (container) { 81 container.style.transition = "opacity 0.4s"; 82 container.style.opacity = 0; 83 setTimeout(function(){ 84 container.style.display = 'none'; 85 }, 400); 86 } 87 }, 88 89 toggle: function(){ 90 var content = document.querySelector('.wonderads_content'); 91 var toggleBtn = document.querySelector('.wonderads_toggle'); // o .wads_toggle se usi classi miste 92 93 if (content) { 94 // Simulazione slideToggle (basica) 95 if (window.getComputedStyle(content).display === 'none') { 96 content.style.display = 'block'; 97 if (toggleBtn) toggleBtn.classList.remove('closed'); 98 } else { 99 content.style.display = 'none'; 100 if (toggleBtn) toggleBtn.classList.add('closed'); 101 } 102 } 103 }, 104 105 create: function(data){ 106 let template = wonderads.getTemplate(data); 107 console.log('wads append'); 108 document.body.insertAdjacentHTML('beforeend', template.template); 109 }, 110 111 start: function (data) { 112 console.log('wads ready'); 113 114 var scrollHandler = function() { 115 hideTimeout = setTimeout(function () { 116 var container = document.querySelector('.wonderads_container'); 117 if (container) { 118 container.style.transition = "opacity 0.4s"; 119 container.style.opacity = 0; 120 setTimeout(function() { container.style.display = 'none'; }, 400); 121 } 122 }, 120000); 123 124 if (window.scrollY > 600) { 125 wonderads.create(data); 126 window.removeEventListener('scroll', scrollHandler); 127 } 128 }; 129 130 window.addEventListener('scroll', scrollHandler); 131 }, 132 133 redirect: function (push_id, url, content_id, redir) { 134 if (redir === undefined) redir = 'php'; 135 136 wonderads.sendReportClick(); 137 138 var container = document.querySelector('.wonderads_container'); 139 if(container) { 140 container.style.display = 'none'; 141 } 142 143 var link = document.createElement("a"); 144 link.referrerPolicy = "no-referrer"; 145 link.rel = "noreferrer"; 146 link.target = '_blank'; 147 link.href = url; 148 document.body.appendChild(link); 149 link.click(); 150 document.body.removeChild(link); 151 }, 152 153 getTemplate: function(data){ 154 let view = 'wads_box'; 155 var objtemplate = {}; 156 if(view == 'wads_box'){ 157 objtemplate = { 158 template : `<div class="wonderads_container"> 159 <div id="wonderads_${view}"> 160 <a href="javascript:void(0);" id="wonderads_toggle" class="wonderads_toggle" onclick="wonderads.toggle();"></a> 161 <div class="wonderads_content"> 162 <div class="wonderads_image" onclick="wonderads.redirect('${data.id}','${data.link}','${data.id}', 'js');"> 163 <img src="${data.image}" alt="${data.title}"> 164 </div> 165 <div class="wonderads_body" onclick="wonderads.redirect('${data.id}','${data.link}','${data.id}', 'js');"> 166 <div class="wonderads_title" style="line-height: 1.2;"><a href="javascript:void(0);">${data.title}</a></div> 167 <div class="wonderads_description" style="padding-bottom: 10px;padding-top: 5px;color: black;" >${data.subtitle}</div> 168 </div> 169 <a href="javascript:void(0);" id="wonderads_close" class="wonderads_close" onclick="wonderads.close('${data.id}','${data.id}');"></a> 170 </div> 171 </div></div>` 172 } 173 } 174 return objtemplate; 175 }, 176 }; 177 178 // Init 179 if (wonderads.isMobile()) { 180 wonderads.getPushContentApi(); 181 } 182});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.