1/* ALI: THIS CODE IS USED TO DISPLAY ADS MID-CONTENT ON THE HOMEPAGE, FOR MOBILE AND DESKTOP */ 2/* NEW SCRIPT (3-5-2024) */ 3/* NOTE: TO ENABLE CONSOLE LOGGING, PUT THIS AFTER THE 'const' VARIABLES ON renderpage-monarch.html: console_logging="on" */ 4 5//ADS SHUFFLING SCRIPT START 6 7// Turn ON/OFF transition in the ads 8var ads_transition = "on"; 9 10// If ccsetting is "inmobi", we let script ads display and shuffle (but disable if that's a problem) 11var cc_marketing_setting = "off"; 12if (ccsetting == "off" || ccsetting == "inmobi") { 13 cc_marketing_setting = "on"; 14} 15 16var horiz_lg_ads = []; 17var horiz_lg_ads_id = []; 18var square_ads = []; 19var square_ads_id = []; 20 21$(document).ready(function () { 22 23 // THIS CODE ADDED 10-24-2024 TO NOT SHUFFLE OUT HARD CODED (LARGE HORIZ) ADS THAT DO NOT CONTAIN "<script" SO AD PLUGG ADS USING A SCRIPT IN THE HEADER DON'T SHUFFLE OUT. 24 const all_ad_local_lghoriz = document.getElementsByClassName("ad_local_lghoriz"); 25 for (let i = 0, n = 0; i < all_ad_local_lghoriz.length; i++, n++) { 26 let desktop__ad1 = all_ad_local_lghoriz[i].getAttribute("data-desktop-ad1"); 27 let desktop__ad2 = all_ad_local_lghoriz[i].getAttribute("data-desktop-ad2"); 28 if (desktop__ad1 !== "ERROR" && desktop__ad1) { 29 if ((decodeURIComponent(desktop__ad1).indexOf('Hard Coded Ad') !== -1) && (decodeURIComponent(desktop__ad1).indexOf('<script') == -1)) { 30 // THIS CODE ADDED 10-31-2024 31 all_ad_local_lghoriz[i].innerHTML = ""; 32 postscribe(all_ad_local_lghoriz[i], decodeURIComponent(desktop__ad1)); 33 all_ad_local_lghoriz[i].style.cssText = "display:block !important; height: 90px;"; 34 all_ad_local_lghoriz[i].classList.add('ad_local_lghoriz_static'); 35 all_ad_local_lghoriz[i].classList.remove('ad_local_lghoriz'); 36 } 37 } else if (desktop__ad2 !== "ERROR" && desktop__ad2) { 38 if ((decodeURIComponent(desktop__ad2).indexOf('Hard Coded Ad') !== -1) && (decodeURIComponent(desktop__ad2).indexOf('<script') == -1)) { 39 // THIS CODE ADDED 10-31-2024 40 all_ad_local_lghoriz[i].innerHTML = ""; 41 postscribe(all_ad_local_lghoriz[i], decodeURIComponent(desktop__ad2)); 42 all_ad_local_lghoriz[i].style.cssText = "display:block !important; height: 90px;"; 43 all_ad_local_lghoriz[i].classList.add('ad_local_lghoriz_static'); 44 all_ad_local_lghoriz[i].classList.remove('ad_local_lghoriz'); 45 } 46 // THIS CODE BLOCKED OUT 11-26-2024 47 } /* else { 48 all_ad_local_lghoriz[i].classList.add('ad_local_lghoriz_static'); 49 all_ad_local_lghoriz[i].classList.remove('ad_local_lghoriz'); 50 } */ 51 } 52 // END 10-24-2024 CODE 53 54 const ad_local_lghoriz = document.getElementsByClassName("ad_local_lghoriz"); 55 const ad_local_square = document.getElementsByClassName("ad_local_square"); 56 const ad_type_square = document.getElementsByClassName("ad_type_square"); 57 const squaread_insertpoint = document.getElementsByClassName("squaread_insertpoint"); 58 const header_home_ad = document.getElementsByClassName("header_home_ad")[0]; 59 var screen_type = "large"; 60 var is_user_idle = false; 61 62 var horiz_lg_ads_timer = []; 63 var horiz_lg_ads_counter = []; 64 var square_ads_timer = []; 65 var square_ads_counter = []; 66 67 //ADD TRANSITION CODE TO ad_local_lghoriz AND ad_type_square 68 const ad_lghoriz = document.querySelectorAll('.ad_local_lghoriz'); 69 const ad_square = document.querySelectorAll('.ad_type_square'); 70 ad_lghoriz.forEach(element => { element.style.transition = 'height 0.5s ease'; }); 71 ad_square.forEach(element => { element.style.transition = 'height 0.5s ease'; }); 72 73 74 75 76 //SHOW ADS ACCORDING TO THE SCREEN SIZE 77 function move_square_ads() { 78 for (let i = 0, n = 0; i < ad_local_lghoriz.length; i++, n++) { 79 let mobile_ad1 = ad_local_lghoriz[i].getAttribute("data-mobile-ad1"); 80 let mobile_ad2 = ad_local_lghoriz[i].getAttribute("data-mobile-ad2"); 81 82 if (mobile_ad1 !== "ERROR" && mobile_ad1) { 83 if (mobile_ad1 == "ad_type_square") { 84 if (ad_type_square[n]) { 85 if (typeof console_logging !== "undefined" && console_logging == "on") { 86 console.log("Square Ad " + (n + 1) + " is moved"); 87 } 88 $(".ad_local_lghoriz")[i].append(ad_type_square[n]); 89 squaread_insertpoint[n].style.display = "none"; 90 } 91 } else if (mobile_ad1 == "header_home_ad") { 92 if (typeof console_logging !== "undefined" && console_logging == "on") {
93 console.log("Header Home Ad is moved"); 94 } 95 96 // THIS LINE REPLACED WITH CODE BELOW ON 11-26-2024 FOR FIREFOX/CONSOLE DISPLAY ISSUE. 97 // $(".ad_local_lghoriz")[i].append(header_home_ad); 98 let header_home_ad_element = $(".ad_local_lghoriz").eq(i); 99 header_home_ad_element.append(header_home_ad); 100 header_home_ad_element.hide().show(0); 101 102 n--; 103 } else { 104 // THIS CODE ADDED 10-31-2024 105 //ad_local_lghoriz[i].innerHTML = decodeURIComponent(mobile_ad1); 106 ad_local_lghoriz[i].innerHTML = ""; 107 postscribe(ad_local_lghoriz[i], decodeURIComponent(mobile_ad1)); 108 n--; 109 } 110 } else if (mobile_ad2 !== "ERROR" && mobile_ad2) { 111 if (mobile_ad2 == "ad_type_square") { 112 if (ad_type_square[n]) { 113 if (typeof console_logging !== "undefined" && console_logging == "on") { 114 console.log("Square Ad " + (n + 1) + " is moved"); 115 } 116 $(".ad_local_lghoriz")[i].append(ad_type_square[n]); 117 squaread_insertpoint[n].style.display = "none"; 118 } 119 } else if (mobile_ad1 == "header_home_ad") { 120 if (typeof console_logging !== "undefined" && console_logging == "on") { 121 console.log("Header Home Ad is moved"); 122 } 123 124 // THIS LINE REPLACED WITH CODE BELOW ON 11-26-2024 FOR FIREFOX/CONSOLE DISPLAY ISSUE. 125 // $(".ad_local_lghoriz")[i].append(header_home_ad); 126 let header_home_ad_element = $(".ad_local_lghoriz").eq(i); 127 header_home_ad_element.append(header_home_ad); 128 header_home_ad_element.hide().show(0); 129 130 n--; 131 } else { 132 // THIS CODE ADDED 10-31-2024 133 //ad_local_lghoriz[i].innerHTML = decodeURIComponent(mobile_ad2); 134 ad_local_lghoriz[i].innerHTML = ""; 135 postscribe(ad_local_lghoriz[i], decodeURIComponent(mobile_ad2)); 136 n--; 137 } 138 } else { 139 n--; 140 } 141 } 142 } 143 144 145 function revert_square_ads() { 146 if (typeof console_logging !== "undefined" && console_logging == "on") { 147 console.log("Revert Square Ads"); 148 console.log("Revert Header Home Ad if moved previously"); 149 } 150 $(".header .container .row .text-right").append(header_home_ad); 151 let ads_to_move = $(".ad_local_lghoriz .ad_type_square").length; 152 for (let i = 0; i < ads_to_move; i++) { 153 if (typeof console_logging !== "undefined" && console_logging == "on") { 154 console.log("Square Ad: " + (i + 1) + " is back to its location"); 155 } 156 squaread_insertpoint[i].style.display = ""; 157 $(".squaread_insertpoint")[i].prepend($(".ad_local_lghoriz .ad_type_square")[0]); 158 } 159 } 160 161 function display_desktop_ads() { 162 for (let i = 0, n = 0; i < ad_local_lghoriz.length; i++, n++) { 163 let desktop_ad1 = ad_local_lghoriz[i].getAttribute("data-desktop-ad1"); 164 let desktop_ad2 = ad_local_lghoriz[i].getAttribute("data-desktop-ad2"); 165 166 if (desktop_ad1 !== "ERROR" && desktop_ad1) { 167 if (typeof console_logging !== "undefined" && console_logging == "on") { 168 console.log("data-desktop-ad1 is set to Horiz Ad: " + (i + 1)); 169 } 170 // THIS CODE ADDED 10-31-2024 171 //ad_local_lghoriz[i].innerHTML = decodeURIComponent(desktop_ad1); 172 ad_local_lghoriz[i].innerHTML = ""; 173 postscribe(ad_local_lghoriz[i], decodeURIComponent(desktop_ad1), { 174 done: function() { 175 ad_local_lghoriz[i].style.cssText = "display:block !important; height: 90px;"; 176 } 177 }); 178 } else if (desktop_ad2 !== "ERROR" && desktop_ad2) { 179 if (typeof console_logging !== "undefined" && console_logging == "on") { 180 console.log("data-desktop-ad2 is set to Horiz Ad: " + (i + 1)); 181 } 182 // THIS CODE ADDED 10-31-2024 183 //ad_local_lghoriz[i].innerHTML = decodeURIComponent(desktop_ad2); 184 ad_local_lghoriz[i].innerHTML = ""; 185 postscribe(ad_local_lghoriz[i], decodeURIComponent(desktop_ad2), { 186 done: function() { 187 ad_local_lghoriz[i].style.cssText = "display:block !important; height: 90px;"; 188 } 189 }); 190 } 191 } 192 } 193 194 //LOAD ADS FROM JSON FILE AND SHUFFLE ON VISIBILITY OF THE ADS AFTER 30 SECONDS (UPDATED 11-7-2024) 195function load_json_ads() { 196 if (ads.length > 0) { 197 if (typeof console_logging !== "undefined" && console_logging == "on") { 198 console.log("JSON contains ads"); 199 } 200 201 202 // MODIFIED 10-22-2024 203 for (let i = 0; i < ads.length; i++) { 204 205 if (decodeURIComponent(ads[i].ad_code).indexOf('<script') !== -1) { // NEW LINE, 10-23-2024 206 // if (decodeURIComponent(ads[i].ad_code).indexOf('script type="text/plain"') !== -1) { 207 208 if(cc_marketing_setting == "on"){ 209 if (ads[i].ad_type == "horiz_lg") { 210 horiz_lg_ads.push(processScriptTag(decodeURIComponent(ads[i].ad_code))); 211 horiz_lg_ads_id.push(ads[i].ad_id); 212 } else if (ads[i].ad_type == "square") { 213 square_ads.push(processScriptTag(decodeURIComponent(ads[i].ad_code)).substring(30).slice(0, -7)); 214 square_ads_id.push(ads[i].ad_id); 215 } 216 } 217 }else{ 218 if (ads[i].ad_type == "horiz_lg") { 219 horiz_lg_ads.push(decodeURIComponent(ads[i].ad_code)); 220 horiz_lg_ads_id.push(ads[i].ad_id); 221 } else if (ads[i].ad_type == "square") { 222 square_ads.push(decodeURIComponent(ads[i].ad_code).substring(30).slice(0, -7)); 223 square_ads_id.push(ads[i].ad_id); 224 } 225 } 226 } 227 228 if (square_ads_id.length == 2){ 229 if (ad_local_square.length > 1) { 230 ad_local_square[0].setAttribute("data-id", square_ads_id[1]); 231 ad_local_square[1].setAttribute("data-id", square_ads_id[0]); 232 } 233 } 234 235 if (typeof PREFS_LOCAL_AD_SHUFFLER !== "undefined" && PREFS_LOCAL_AD_SHUFFLER == "aggressive") { 236 setTimeout(function() { show_aggressive_ads();}, PREFS_LOCAL_AD_SHUFFLE_TIMER); 237 } else if (typeof PREFS_LOCAL_AD_SHUFFLER !== "undefined" && PREFS_LOCAL_AD_SHUFFLER == "normal") { 238 if (typeof console_logging !== "undefined" && console_logging == "on") { 239 console.log("Show Normal Ads"); 240 } 241 setInterval(check_ads_visibility, 1000); 242 } 243 } else { 244 if (typeof console_logging !== "undefined" && console_logging == "on") { 245 console.log("JSON does not contains ads."); 246 } 247 } 248} 249 250 251 252 253 function show_aggressive_ads() { 254 if (typeof console_logging !== "undefined" && console_logging == "on") { 255 console.log("Show Aggressive Ads"); 256 } 257 258 let aggressive_ads_ids = []; 259 if (ad_local_lghoriz.length > 0) { 260 for (let i = 0; i < ad_local_lghoriz.length; i++) { 261 262// THIS LINE CHANGED 11-26-2024: 263// let new_ad_id = get_Random_square_ad(ad_local_lghoriz[i].getAttribute("data-id")); 264 let new_ad_id = get_Random_horiz_ad(ad_local_lghoriz[i].getAttribute("data-id")); 265 266 aggressive_ads_ids.push(horiz_lg_ads_id[new_ad_id]); 267 268 //ad_local_lghoriz[i].innerHTML = horiz_lg_ads[new_ad_id]; 269 270 // THIS CODE ADDED 10-31-2024 271 ad_local_lghoriz[i].innerHTML = ""; 272 postscribe(ad_local_lghoriz[i], horiz_lg_ads[new_ad_id], { 273 done: function() { 274 ad_local_lghoriz[i].style.cssText = "display:block !important; transition:height 0.5s ease; height:" + ad_local_lghoriz[i].style.height + ";"; 275 if (ads_transition == "on") { 276 setTimeout(() => { 277 if(ad_local_lghoriz[i].getElementsByTagName('img').length > 0){ 278 ad_local_lghoriz[i].style.height = ad_local_lghoriz[i].getElementsByTagName('img')[0].scrollHeight + 'px'; 279 }else{ 280 ad_local_lghoriz[i].style.removeProperty('height'); 281 } 282 }, 500); 283 } 284 } 285 }); 286 287 ad_local_lghoriz[i].setAttribute("data-id", horiz_lg_ads_id[new_ad_id]); 288 } 289 } 290 291 if (ad_local_square.length > 0) { 292 for (let n = 0; n < ad_local_square.length; n++) { 293 let new_ad_id = get_Random_square_ad(ad_local_square[n].getAttribute("data-id")); 294 aggressive_ads_ids.push(square_ads_id[new_ad_id]); 295 296 //ad_local_square[n].innerHTML = square_ads[new_ad_id]; 297 298 // THIS CODE ADDED 10-31-2024 299 ad_local_square[n].innerHTML = ""; 300 postscribe(ad_local_square[n], square_ads[new_ad_id], { 301 done: function() { 302 if (ads_transition == "on") { 303 setTimeout(() => { 304 if(ad_local_square[n].getElementsByTagName('img').length > 0){ 305 ad_local_square[n].parentElement.style.height = ad_local_square[n].getElementsByTagName('img')[0].scrollHeight + 'px'; 306 }else{ 307 ad_local_square[n].parentElement.style.removeProperty('height'); 308 } 309 }, 500); 310 } 311 } 312 }); 313 314 ad_local_square[n].setAttribute("data-id", square_ads_id[new_ad_id]); 315 } 316 } 317 318 if (typeof setting_ad_clicks_impressions !== "undefined" && setting_ad_clicks_impressions == "enabled") { 319 add_impression(aggressive_ads_ids); 320 } 321 322 setInterval(check_ads_visibility, 1000); 323 } 324 325 function check_ads_visibility() { 326 if (document.visibilityState === "visible") { 327 if (!is_user_idle){ 328 if (screen_type == "large") { 329 if (ad_local_lghoriz.length > 0 && horiz_lg_ads.length > 1) { 330 for (let i = 0; i < ad_local_lghoriz.length; i++) { 331 if (ad_local_lghoriz[i].hasChildNodes()) { 332 let rect = ad_local_lghoriz[i].getBoundingClientRect(); 333 if (rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth)) { 334 if (!horiz_lg_ads_timer[i]) { 335 if (typeof console_logging !== "undefined" && console_logging == "on") { 336 console.log("Horiz ad " + (i + 1) + ": timer added."); 337 } 338 horiz_lg_ads_counter[i] = 0; 339 horiz_lg_ads_timer[i] = setInterval(function () { 340 let new_ad_id = get_Random_horiz_ad(ad_local_lghoriz[i].getAttribute("data-id")); 341 let add_horiz_ids = new Array(horiz_lg_ads_id[new_ad_id]); 342 horiz_lg_ads_counter[i] = horiz_lg_ads_counter[i] + 1; 343 344 if (typeof setting_ad_clicks_impressions !== "undefined" && setting_ad_clicks_impressions == "enabled") { 345 add_impression(add_horiz_ids); 346 } 347 348 //ad_local_lghoriz[i].innerHTML = horiz_lg_ads[new_ad_id]; 349 350 // THIS CODE ADDED 10-31-2024 351 ad_local_lghoriz[i].innerHTML = ""; 352 postscribe(ad_local_lghoriz[i], horiz_lg_ads[new_ad_id], { 353 done: function() { 354 ad_local_lghoriz[i].style.cssText = "display:block !important; transition:height 0.5s ease; height:" + ad_local_lghoriz[i].style.height + ";"; 355 if (ads_transition == "on") { 356 setTimeout(() => { 357 if(ad_local_lghoriz[i].getElementsByTagName('img').length > 0){ 358 ad_local_lghoriz[i].style.height = ad_local_lghoriz[i].getElementsByTagName('img')[0].scrollHeight + 'px'; 359 }else{ 360 ad_local_lghoriz[i].style.removeProperty('height'); 361 } 362 }, 500); 363 } 364 } 365 }); 366 367 ad_local_lghoriz[i].setAttribute("data-id", horiz_lg_ads_id[new_ad_id]); 368 if (typeof console_logging !== "undefined" && console_logging == "on") { 369 console.log("horiz ad " + (i+1) + " changed " + horiz_lg_ads_counter[i] + " times"); 370 } 371 if (horiz_lg_ads_counter[i] && horiz_lg_ads_counter[i] >= PREFS_LOCAL_AD_IDLE_LOAD_TIMES) { 372 is_user_idle = true; 373 clearInterval(horiz_lg_ads_timer[i]); 374 horiz_lg_ads_timer[i] = null; 375 horiz_lg_ads_counter[i] = null; 376 if (typeof console_logging !== "undefined" && console_logging == "on") { 377 console.log("User is idle, horiz ad " + (i+1) + " stopped shuffling"); 378 } 379 } 380 381 }, PREFS_LOCAL_AD_SHUFFLE_TIMER); 382 } 383 } else { 384 if (horiz_lg_ads_timer[i]) { 385 if (typeof console_logging !== "undefined" && console_logging == "on") { 386 console.log("Horiz ad " + (i + 1) + ": timer removed."); 387 } 388 clearInterval(horiz_lg_ads_timer[i]); 389 horiz_lg_ads_timer[i] = null; 390 } 391 } 392 } 393 } 394 } 395 } 396 397 if (ad_local_square.length > 0 && square_ads.length > 1) { 398 for (let n = 0; n < ad_local_square.length; n++) { 399 let r
399ect = ad_local_square[n].parentElement.getBoundingClientRect(); 400 if (rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth)) { 401 if (!square_ads_timer[n]) { 402 if (typeof console_logging !== "undefined" && console_logging == "on") { 403 console.log("Square ad " + (n + 1) + ": timer added."); 404 } 405 square_ads_counter[n] = 0; 406 square_ads_timer[n] = setInterval(function () { 407 let new_ad_id = get_Random_square_ad(ad_local_square[n].getAttribute("data-id")); 408 let add_square_ids = new Array(square_ads_id[new_ad_id]); 409 square_ads_counter[n] = square_ads_counter[n] + 1; 410 411 if (typeof setting_ad_clicks_impressions !== "undefined" && setting_ad_clicks_impressions == "enabled") { 412 add_impression(add_square_ids); 413 } 414 415 //ad_local_square[n].innerHTML = square_ads[new_ad_id]; 416 417 // THIS CODE ADDED 10-31-2024 418 ad_local_square[n].innerHTML = ""; 419 postscribe(ad_local_square[n], square_ads[new_ad_id], { 420 done: function() { 421 if (ads_transition == "on") { 422 setTimeout(() => { 423 if(ad_local_square[n].getElementsByTagName('img').length > 0){ 424 ad_local_square[n].parentElement.style.height = ad_local_square[n].getElementsByTagName('img')[0].scrollHeight + 'px'; 425 }else{ 426 ad_local_square[n].parentElement.style.removeProperty('height'); 427 } 428 }, 500); 429 } 430 } 431 }); 432 433 ad_local_square[n].setAttribute("data-id", square_ads_id[new_ad_id]); 434 if (typeof console_logging !== "undefined" && console_logging == "on") { 435 console.log("Square ad " + (n+1) + " changed " + square_ads_counter[n] + " times"); 436 } 437 if (square_ads_counter[n] && square_ads_counter[n] >= PREFS_LOCAL_AD_IDLE_LOAD_TIMES) { 438 is_user_idle = true; 439 clearInterval(square_ads_timer[n]); 440 square_ads_timer[n] = null; 441 square_ads_counter[n] = null; 442 if (typeof console_logging !== "undefined" && console_logging == "on") { 443 console.log("User is idle, Square ad " + (n+1) + " stopped shuffling"); 444 } 445 } 446 447 }, PREFS_LOCAL_AD_SHUFFLE_TIMER); 448 } 449 } else { 450 if (square_ads_timer[n]) { 451 if (typeof console_logging !== "undefined" && console_logging == "on") { 452 console.log("Square ad " + (n + 1) + ": timer removed."); 453 } 454 clearInterval(square_ads_timer[n]); 455 square_ads_timer[n] = null; 456 } 457 } 458 } 459 } 460 } 461 } else { 462 stop_timer(); 463 } 464 } 465 466 function stop_timer() { 467 if (typeof console_logging !== "undefined" && console_logging == "on") { 468 console.log("STOP SHUFFLING ADS"); 469 } 470 if (ad_local_lghoriz.length > 0) { 471 for (let i = 0; i < ad_local_lghoriz.length; i++) { 472 clearInterval(horiz_lg_ads_timer[i]); 473 horiz_lg_ads_timer[i] = null; 474 horiz_lg_ads_counter[i] = null; 475 } 476 } 477 if (ad_local_square.length > 0) { 478 for (let n = 0; n < ad_local_square.length; n++) { 479 clearInterval(square_ads_timer[n]); 480 square_ads_timer[n] = null; 481 square_ads_counter[n] = null; 482 } 483 } 484 } 485 486 function get_Random_horiz_ad(except_ad) { 487 if (horiz_lg_ads_id.length <= 0) { 488 return 0; 489 } else if (typeof except_ad !== "undefined" && horiz_lg_ads_id.length == 1) { 490 if (horiz_lg_ads_id[0] === except_ad) return 0; 491 } 492 493 var n = Math.floor(Math.random() * horiz_lg_ads_id.length); 494 if (horiz_lg_ads_id[n] === except_ad) { 495 return get_Random_horiz_ad(except_ad); 496 } 497 return n; 498 } 499 500 function get_Random_square_ad(except_ad) { 501 if (square_ads_id.length <= 0) { 502 return 0; 503 } else if (typeof except_ad !== "undefined" && square_ads_id.length == 1) { 504 if (square_ads_id[0] === except_ad) return 0; 505 } 506 var n = Math.floor(Math.random() * square_ads_id.length); 507 if (square_ads_id[n] === except_ad) { 508 return get_Random_square_ad(except_ad); 509 }else if (square_ads_id.length == 2){ 510 if(square_ads_id[n] === ad_local_square[0].getAttribute("data-id")){ 511 if(square_ads_id[0] === ad_local_square[0].getAttribute("data-id")){ 512 return 1; 513 }else{ 514 return 0; 515 } 516 } 517 } 518 return n; 519 } 520 521 function add_impression(ads_id) { 522 if (typeof setting_ad_clicks_impressions !== "undefined" && setting_ad_clicks_impressions == "enabled") { 523 var xhr = new XMLHttpRequest(); 524 var url = "/api/roar/ad_impression"; 525 xhr.open("POST", url, true); 526 xhr.setRequestHeader("Content-Type", "application/json"); 527 xhr.onreadystatechange = function () { 528 if (xhr.readyState === 4 && xhr.status === 200) { 529 //console.log(xhr.responseText); 530 } 531 }; 532 var data = JSON.stringify({ ads_id: ads_id }); 533 xhr.send(data); 534 } 535 } 536 537 function display_ads(screen_size) { 538 if (screen_size.matches) { 539 if (typeof console_logging !== "undefined" && console_logging == "on") { 540 console.log("Screen Size: Small"); 541 } 542 screen_type = "small"; 543 $(".ad_local_lghoriz").empty(); 544 move_square_ads(); 545 } else { 546 if (typeof console_logging !== "undefined" && console_logging == "on") { 547 console.log("Screen Size: Large"); 548 } 549 if (screen_type !== "large") { 550 revert_square_ads(); 551 screen_type = "large"; 552 } 553 display_desktop_ads(); 554 } 555 } 556 557 $(document).on('keypress click mousemove resize scroll',function(){ 558 is_user_idle = false;
559 560 if (ad_local_lghoriz.length > 0) { 561 for (let i = 0; i < ad_local_lghoriz.length; i++) { 562 horiz_lg_ads_counter[i] = 0; 563 } 564 } 565 if (ad_local_square.length > 0) { 566 for (let n = 0; n < ad_local_square.length; n++) { 567 square_ads_counter[n] = 0; 568 } 569 } 570 }); 571 572 var screen_size = window.matchMedia("(max-width: 767px)"); 573 574 display_ads(screen_size); 575 576 screen_size.addEventListener("change", function () { 577 display_ads(screen_size); 578 stop_timer(); 579 }); 580 581 if (typeof ads !== "undefined" && typeof PREFS_LOCAL_AD_SHUFFLER !== "undefined" && PREFS_LOCAL_AD_SHUFFLER !== "off") { 582 if (typeof console_logging !== "undefined" && console_logging == "on") { 583 console.log("Execute Local Ad Shuffler Script"); 584 } 585 load_json_ads(); 586 } else { 587 if (typeof console_logging !== "undefined" && console_logging == "on") { 588 console.log("Ads json not found or PREFS_LOCAL_AD_SHUFFLER=off"); 589 } 590 } 591 592 //FIND ADS FROM COMMENTS AND ADD IMPRESSION TO SERVER 593 function filterNone() { 594 return NodeFilter.FILTER_ACCEPT; 595 } 596 597 function find_ads_id(e) { 598 let onload_ads_id = []; 599 let iterator = document.createNodeIterator(e, NodeFilter.SHOW_COMMENT, filterNone, false); 600 while (true) { 601 let node = iterator.nextNode(); 602 if (node == null) { 603 break; 604 } 605 if (node.nodeValue.indexOf("ad_init_ctr") !== -1) { 606 onload_ads_id.push(node.nodeValue.replace("ad_init_ctr:", "")); 607 } 608 } 609 return onload_ads_id; 610 } 611 612 if (typeof console_logging !== "undefined" && console_logging == "on") { 613 console.log(find_ads_id(document.body)); 614 } 615 616 if (typeof setting_ad_clicks_impressions !== "undefined" && setting_ad_clicks_impressions == "enabled") { 617 add_impression(find_ads_id(document.body)); 618 } 619}); 620 621 622// UPDATED 11-7-2024 623function update_json_ads() { 624 horiz_lg_ads = []; 625 horiz_lg_ads_id = []; 626 square_ads = []; 627 square_ads_id = []; 628 629 for (let i = 0; i < ads.length; i++) { 630 631 if (decodeURIComponent(ads[i].ad_code).indexOf('<script') !== -1) { // 10-23-2024 if ad_code contains is a script tag then check for c
631ookie consent before adding to ads list 632 if(cc_marketing_setting == "on"){ 633 if (ads[i].ad_type == "horiz_lg") { 634 horiz_lg_ads.push(processScriptTag(decodeURIComponent(ads[i].ad_code))); 635 horiz_lg_ads_id.push(ads[i].ad_id); 636 } else if (ads[i].ad_type == "square") { 637 square_ads.push(processScriptTag(decodeURIComponent(ads[i].ad_code)).substring(30).slice(0, -7)); 638 square_ads_id.push(ads[i].ad_id); 639 } 640 } 641 }else{ 642 if (ads[i].ad_type == "horiz_lg") { 643 horiz_lg_ads.push(decodeURIComponent(ads[i].ad_code)); 644 horiz_lg_ads_id.push(ads[i].ad_id); 645 } else if (ads[i].ad_type == "square") { 646 square_ads.push(decodeURIComponent(ads[i].ad_code).substring(30).slice(0, -7)); 647 square_ads_id.push(ads[i].ad_id); 648 } 649 } 650 } 651} 652 653//ADS SHUFFLING SCRIPT END
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.