Guest User

cocks

a guest
Jan 28th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. https://web.archive.org/web/20190128234655/https://powerad.ai/customScripts/4channel.js
  2. https://web.archive.org/web/20190128234655/https://powerad.ai/customScripts/4channel.js
  3. https://web.archive.org/web/20190128234655/https://powerad.ai/customScripts/4channel.js
  4.  
  5.  
  6. /*
  7. Custom code for 4channel
  8. Change:
  9. remove transition style
  10. Reason:
  11. They don't want it.
  12. */
  13. var startTimeStamp = new Date().getTime();
  14. var firstUnitCalled = !1;
  15. var debugScript = new XMLHttpRequest();
  16. debugScript.open('POST', 'https://powerad.ai/debug/requests/', !0)
  17. debugScript.setRequestHeader('hostName', window.location.host);
  18. debugScript.send();
  19. debugScript.onreadystatechange = function () {
  20.     if (this.status == 200) {
  21.         debugScript.abort()
  22.     }
  23. }
  24. var geoLoaded = !1;
  25. var geoLoadedEvent = new Event('geoLoadedEvent');
  26. var fullIpInfo = {
  27.     loaded: !1
  28. };
  29. var getIpReq = new XMLHttpRequest();
  30. getIpReq.open('GET', 'https://freegeoip.app/json/', !0);
  31. getIpReq.onreadystatechange = function () {
  32.     if (this.readyState == 4) {
  33.         if (this.status == 200) {
  34.             fullIpInfo.country = JSON.parse(this.response).country_code;
  35.             fullIpInfo.state = JSON.parse(this.response).region_code || '';
  36.             geoLoaded = !0;
  37.             document.dispatchEvent(geoLoadedEvent);
  38.             fullIpInfo.loaded = !0
  39.         } else {
  40.             fullIpInfo.abort();
  41.             var getIpReq2 = new XMLHttpRequest();
  42.             getIpReq2.open('GET', 'https://ipapi.co/json/', !0);
  43.             getIpReq2.onreadystatechange = function () {
  44.                 if (this.readyState == 4) {
  45.                     if (this.status == 200) {
  46.                         fullIpInfo.country = JSON.parse(this.response).country;
  47.                         fullIpInfo.state = JSON.parse(this.response).region_code;
  48.                         geoLoaded = !0;
  49.                         fullIpInfo.loaded = !0;
  50.                         document.dispatchEvent(geoLoadedEvent)
  51.                     }
  52.                 }
  53.             }
  54.             getIpReq2.send()
  55.         }
  56.     }
  57. };
  58. getIpReq.send();
  59. var xhr = new XMLHttpRequest();
  60. xhr.open('GET', 'https://powerad.ai/pub', !0);
  61. xhr.setRequestHeader('hostName', window.location.host);
  62. xhr.send();
  63. xhr.onreadystatechange = function () {
  64.     if (this.status == 200 && this.readyState == 4) {
  65.         var placements = JSON.parse(this.response);
  66.         if (geoLoaded && fullIpInfo.loaded) {
  67.             for (let i in placements) {
  68.                 checkOnPlacement(placements[i])
  69.             }
  70.         } else {
  71.             document.addEventListener('geoLoadedEvent', () => {
  72.                 for (let i in placements) {
  73.                     checkOnPlacement(placements[i])
  74.                 }
  75.             })
  76.         }
  77.         xhr.abort()
  78.     }
  79. };
  80. var screenType = function () {
  81.     if (window.innerWidth <= 600) {
  82.         return 'mobile'
  83.     } else if (window.innerWidth > 600 && window.innerWidth <= 767) {
  84.         return 'tablet'
  85.     } else if (window.innerWidth > 767) {
  86.         return 'desktop'
  87.     }
  88. }
  89.  
  90. function devicePass(placement) {
  91.     if (screenType() == 'mobile') {
  92.         if (placement.device.mobile) {
  93.             return !0
  94.         } else {
  95.             return !1
  96.         }
  97.     } else if (screenType() == 'tablet') {
  98.         if (placement.device.tablet) {
  99.             return !0
  100.         } else {
  101.             return !1
  102.         }
  103.     } else if (screenType() == 'desktop') {
  104.         if (placement.device.desktop) {
  105.             return !0
  106.         } else {
  107.             return !1
  108.         }
  109.     }
  110. }
  111.  
  112. function includeUrlRules(placement) {
  113.     if (placement.rules.urlRules.include[0]) {
  114.         for (a = 0; a < placement.rules.urlRules.include.length; a++) {
  115.             if (window.location.href.toLowerCase().indexOf(placement.rules.urlRules.include[a].toLowerCase()) != -1) {
  116.                 return !0
  117.             }
  118.         }
  119.         return !1
  120.     } else {
  121.         return !0
  122.     }
  123. }
  124.  
  125. function excludeUrlRules(placement) {
  126.     if (placement.rules.urlRules.exclude[0]) {
  127.         for (a = 0; a < placement.rules.urlRules.exclude.length; a++) {
  128.             if (window.location.href.toLowerCase().indexOf(placement.rules.urlRules.exclude[a].toLowerCase()) != -1) {
  129.                 return !1
  130.             }
  131.         }
  132.         return !0
  133.     } else {
  134.         return !0
  135.     }
  136. }
  137.  
  138. function includeDirUrl(placement) {
  139.     if (placement.rules.urlRules.dir) {
  140.         if (placement.rules.urlRules.dir.include[0]) {
  141.             for (a = 0; a < placement.rules.urlRules.dir.include.length; a++) {
  142.                 var searchString = placement.rules.urlRules.dir.include[a]
  143.                 if (location.href.indexOf(searchString) != -1) {
  144.                     if (location.href.length > location.href.indexOf(searchString) + searchString.length) {
  145.                         return !0
  146.                     } else {
  147.                         return !1
  148.                     }
  149.                 } else {
  150.                     return !1
  151.                 }
  152.             }
  153.             return !1
  154.         } else {
  155.             return !0
  156.         }
  157.     } else {
  158.         return !0
  159.     }
  160. }
  161.  
  162. function excludeDirUrl(placement) {
  163.     if (placement.rules.urlRules.dir) {
  164.         if (placement.rules.urlRules.dir.exclude[0]) {
  165.             for (a = 0; a < placement.rules.urlRules.dir.exclude.length; a++) {
  166.                 for (a = 0; a < placement.rules.urlRules.dir.exclude.length; a++) {
  167.                     var searchString = placement.rules.urlRules.dir.exclude[a]
  168.                     if (location.href.indexOf(searchString) != -1) {
  169.                         if (location.href.length == location.href.indexOf(searchString) + searchString.length) {
  170.                             return !0
  171.                         } else {
  172.                             return !1
  173.                         }
  174.                     } else {
  175.                         return !1
  176.                     }
  177.                 }
  178.                 return !1
  179.             }
  180.             return !0
  181.         } else {
  182.             return !0
  183.         }
  184.     } else {
  185.         return !0
  186.     }
  187. }
  188.  
  189. function geoRules(placement) {
  190.     var geoRule = placement.rules.geoRules.type || '';
  191.     var geoCountries = placement.rules.geoRules.countries || [];
  192.     var geoStates = placement.rules.geoRules.states || [];
  193.     if (geoRule == '') {
  194.         return !0
  195.     } else if (geoRule == 'include') {
  196.         if (geoCountries[0] && !geoStates[0]) {
  197.             for (a = 0; a < geoCountries.length; a++) {
  198.                 if (geoCountries[a] == fullIpInfo.country) {
  199.                     return !0
  200.                 }
  201.             }
  202.             return !1
  203.         } else if (!geoCountries[0] && geoStates[0]) {
  204.             if (fullIpInfo.country != 'US') {
  205.                 return !1
  206.             } else {
  207.                 for (a = 0; a < geoStates.length; a++) {
  208.                     if (geoStates[a] == fullIpInfo.state) {
  209.                         return !0
  210.                     }
  211.                 }
  212.                 return !1
  213.             }
  214.         } else if (geoCountries[0] && geoStates[0]) {
  215.             for (a = 0; a < geoCountries.length; a++) {
  216.                 if (geoCountries[a] == 'US') {
  217.                     for (b = 0; b < geoStates.length; b++) {
  218.                         if (geoStates[b] == fullIpInfo.state) {
  219.                             return !0
  220.                         }
  221.                     }
  222.                     return !1
  223.                 }
  224.             }
  225.             for (a = 0; a < geoCountries.length; a++) {
  226.                 if (geoCountries[a] == fullIpInfo.country) {
  227.                     return !0
  228.                 }
  229.             }
  230.             for (a = 0; a < geoStates.length; a++) {
  231.                 if (geoStates[a] == fullIpInfo.state) {
  232.                     return !0
  233.                 }
  234.             }
  235.             return !1
  236.         }
  237.     } else if (geoRule == 'exclude') {
  238.         if (geoCountries[0] && !geoStates[0]) {
  239.             for (a = 0; a < geoCountries.length; a++) {
  240.                 if (geoCountries[a] == fullIpInfo.country) {
  241.                     return !1
  242.                 }
  243.             }
  244.             return !0
  245.         } else if (!geoCountries[0] && geoStates[0]) {
  246.             if (fullIpInfo.country != 'US') {
  247.                 return !0
  248.             } else {
  249.                 for (a = 0; a < geoStates.length; a++) {
  250.                     if (geoStates[a] == fullIpInfo.state) {
  251.                         return !1
  252.                     }
  253.                 }
  254.                 return !0
  255.             }
  256.         } else if (geoCountries[0] && geoStates[0]) {
  257.             for (a = 0; a < geoCountries.length; a++) {
  258.                 if (geoCountries[a] == 'US') {
  259.                     for (b = 0; b < geoStates.length; b++) {
  260.                         if (geoStates[b] == fullIpInfo.state) {
  261.                             return !1
  262.                         }
  263.                     }
  264.                     return !0
  265.                 }
  266.             }
  267.             for (a = 0; a < geoCountries.length; a++) {
  268.                 if (geoCountries[a] == fullIpInfo.country) {
  269.                     return !1
  270.                 }
  271.             }
  272.             for (a = 0; a < geoStates.length; a++) {
  273.                 if (geoStates[a] == fullIpInfo.state) {
  274.                     return !1
  275.                 }
  276.             }
  277.             return !0
  278.         }
  279.     }
  280. }
  281.  
  282. function capPerUserPerDay(placement) {
  283.     var placementIndex = placement.placementIndex
  284.     if (placement.caps) {
  285.         if (placement.caps.userDay != '') {
  286.             if (localStorage.getItem(`${placementIndex}capUserDay`)) {
  287.                 var storageCapInfo = JSON.parse(localStorage.getItem(`${placementIndex}capUserDay`))
  288.                 if (new Date().getTime() - (storageCapInfo.timeStamp + (60 * 60 * 24 * 1000)) < 0) {
  289.                     if (storageCapInfo.number < placement.caps.userDay) {
  290.                         var updateStorageCapInfo = {
  291.                             number: storageCapInfo.number + 1,
  292.                             timeStamp: storageCapInfo.timeStamp
  293.                         }
  294.                         localStorage.setItem(`${placementIndex}capUserDay`, JSON.stringify(updateStorageCapInfo))
  295.                         return !0
  296.                     } else {
  297.                         return !1
  298.                     }
  299.                 } else {
  300.                     var storageCapInfo = {
  301.                         number: 1,
  302.                         timeStamp: new Date().getTime()
  303.                     }
  304.                     localStorage.setItem(`${placementIndex}capUserDay`, JSON.stringify(storageCapInfo))
  305.                     return !0
  306.                 }
  307.             } else {
  308.                 var storageCapInfo = {
  309.                     number: 1,
  310.                     timeStamp: new Date().getTime()
  311.                 }
  312.                 localStorage.setItem(`${placementIndex}capUserDay`, JSON.stringify(storageCapInfo))
  313.                 return !0
  314.             }
  315.         } else {
  316.             if (localStorage.getItem(`${placementIndex}capUserDay`)) {
  317.                 localStorage.removeItem(`${placementIndex}capUserDay`)
  318.             }
  319.             return !0
  320.         }
  321.     } else {
  322.         return !0
  323.     }
  324. }
  325.  
  326. function capPerUserLife(placement) {
  327.     var placementIndex = placement.placementIndex
  328.     if (placement.caps) {
  329.         if (placement.caps.userLife != '') {
  330.             if (localStorage.getItem(placementIndex + 'capUserLife')) {
  331.                 var storageCapInfo = JSON.parse(localStorage.getItem(placementIndex + 'capUserLife'))
  332.                 if (storageCapInfo.number < placement.caps.userLife) {
  333.                     var updateStorageCapInfo = {
  334.                         number: storageCapInfo.number + 1,
  335.                     }
  336.                     localStorage.setItem(placementIndex + 'capUserLife', JSON.stringify(updateStorageCapInfo))
  337.                     return !0
  338.                 } else {
  339.                     return !1
  340.                 }
  341.             } else {
  342.                 var storageCapInfo = {
  343.                     number: 1,
  344.                 }
  345.                 localStorage.setItem(placementIndex + 'capUserLife', JSON.stringify(storageCapInfo))
  346.                 return !0
  347.             }
  348.         } else {
  349.             if (localStorage.getItem(placementIndex + 'capUserLife')) {
  350.                 localStorage.removeItem(placementIndex + 'capUserLife')
  351.             }
  352.             return !0
  353.         }
  354.     } else {
  355.         return !0
  356.     }
  357. }
  358.  
  359. function checkOnPlacement(placement) {
  360.     if (!firstUnitCalled) {
  361.         firstUnitCalled = !0;
  362.         console.log('time till inject: ' + (new Date().getTime() - startTimeStamp));
  363.         debugScript = undefined || null || '';
  364.         debugScript = new XMLHttpRequest();
  365.         debugScript.open('POST', 'https://powerad.ai/debug/injectCalled/', !0);
  366.         debugScript.setRequestHeader('hostName', window.location.host);
  367.         debugScript.send();
  368.         debugScript.onreadystatechange = function () {
  369.             if (this.status == 200) {
  370.                 debugScript.abort()
  371.             }
  372.         }
  373.     }
  374.     if (placement.active) {
  375.         if (devicePass(placement)) {
  376.             if (geoRules(placement)) {
  377.                 if (includeUrlRules(placement)) {
  378.                     if (excludeUrlRules(placement)) {
  379.                         if (includeDirUrl(placement)) {
  380.                             if (excludeDirUrl(placement)) {
  381.                                 if (capPerUserPerDay(placement)) {
  382.                                     if (capPerUserLife(placement)) {
  383.                                         switch (placement.type) {
  384.                                         case 'multiInsert':
  385.                                             injectMulti(placement);
  386.                                             break;
  387.                                         case 'stickyBottom':
  388.                                             injectStickyBottom(placement);
  389.                                             break;
  390.                                         case 'stickyTop':
  391.                                             injectStickyTop(placement);
  392.                                             break;
  393.                                         case 'adhesion':
  394.                                             injectAdhesion(placement);
  395.                                             break;
  396.                                         case 'video':
  397.                                             injectVideo(placement);
  398.                                             break
  399.                                         }
  400.                                     }
  401.                                 }
  402.                             } else {}
  403.                         } else {}
  404.                     } else {}
  405.                 } else {}
  406.             } else {}
  407.         } else {}
  408.     }
  409. }
  410.  
  411. function getScroll() {
  412.     return window.scrollY || document.body.scrollTop
  413. };
  414.  
  415. function compileTag(placementNumber, a) {
  416.     if (plInfo[placementNumber].demandType == 'live') {
  417.         switch (plInfo[placementNumber].liveDemand[a].partner) {
  418.         case 'google':
  419.             var randomNumber = Math.floor(Math.random() * 100000) + 1;
  420.             return `
  421.   <html><head>
  422.   <script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
  423.   <script>var googletag = googletag || {};googletag.cmd = googletag.cmd || [];googletag.cmd.push(function() {googletag.defineSlot('/90814396/${plInfo[placementNumber].liveDemand[a].unitName}', [${plInfo[placementNumber].styles.width}, ${plInfo[placementNumber].styles.height}], 'inject-google-slot-id-${randomNumber}').addService(googletag.pubads());googletag.pubads().enableSingleRequest();googletag.enableServices();});
  424.   var impression = new Event('impression');var noImpression = new Event('noImpression');
  425.  
  426.  
  427.   var rprt = new XMLHttpRequest()
  428.   rprtData = {
  429.   'pubIndex':${plInfo[placementNumber].pubIndex},
  430.   'placementIndex':${plInfo[placementNumber].placementIndex},
  431.   'placementName':'${plInfo[placementNumber].name}',
  432.   'imp':false,
  433.   'impType':'live',
  434.   'partner':'google'
  435.   }
  436.   rprt.open('POST','https://powerad.ai/reports/new',true);rprt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  437.  
  438.  
  439.   googletag.cmd.push(function(){googletag.pubads().addEventListener('slotRenderEnded',function(info){if(info.isEmpty==!1){
  440.  
  441.   rprtData.imp = true;
  442.   rprtData = JSON.stringify(rprtData);
  443.   rprt.send(rprtData);
  444.  
  445.  
  446.   document.dispatchEvent(impression);console.log('impression')
  447.  
  448.  
  449.   }else if(info.isEmpty==!0){
  450.  
  451.   rprtData = JSON.stringify(rprtData);
  452.   rprt.send(rprtData);
  453.  
  454.   document.dispatchEvent(noImpression);console.log('no impression')
  455.  
  456.  
  457.  
  458.   }})})</script>
  459.   </head><body><div id='inject-google-slot-id-${randomNumber}'><script>googletag.cmd.push(function() { googletag.display('inject-google-slot-id-${randomNumber}'); });
  460.   </script></div></body></html>`
  461.             break;
  462.         case 'amazon':
  463.             return `<html><head><script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script><script>var googletag=googletag||{};googletag.cmd=googletag.cmd||[];googletag.cmd.push(function(){googletag.defineSlot('/90814396/${plInfo[placementNumber].liveDemand[a].unitName}',[[${plInfo[placementNumber].styles.width},${plInfo[placementNumber].styles.height}]],'inject-amazon-slot-id-${a}').addService(googletag.pubads());googletag.pubads().disableInitialLoad();googletag.pubads().enableSingleRequest();googletag.enableServices()});</script><script type='text/javascript'>!function(a9,a,p,s,t,A,g){if(a[a9])return;function q(c,r){a[a9]._Q.push([c,r])}a[a9]={init:function(){q("i",arguments)},fetchBids:function(){q("f",arguments)},setDisplayBids:function(){},targetingKeys:function(){return[]},_Q:[]};A=p.createElement(s);A.async=!0;A.src=t;g=p.getElementsByTagName(s)[0];g.parentNode.insertBefore(A,g)}("apstag",window,document,"script","//c.amazon-adsystem.com/aax2/apstag.js");apstag.init({pubID:'79e40b05-e673-4b6c-85f9-79252a7f96a5',adServer:'googletag',bidTimeout:2e3});apstag.fetchBids({slots:[{slotID:'inject-amazon-slot-id-${a}',slotName:'/90814396/${plInfo[placementNumber].liveDemand[a].unitName}',sizes:[${plInfo[placementNumber].styles.width},${plInfo[placementNumber].styles.height}]}]},function(bids){googletag.cmd.push(function(){apstag.setDisplayBids();googletag.pubads().refresh()})});var impression=new Event('impression')
  464.   var noImpression=new Event('noImpression');
  465.  
  466.   var rprt = new XMLHttpRequest()
  467.   rprtData = {
  468.   'pubIndex':${plInfo[placementNumber].pubIndex},
  469.   'placementIndex':${plInfo[placementNumber].placementIndex},
  470.   'placementName':'${plInfo[placementNumber].name}',
  471.   'imp':false,
  472.   'impType':'live',
  473.   'partner':'amazon'
  474.   }
  475.   // rprt.open('POST','https://powerad.ai/reports/new',true);rprt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  476.  
  477.   googletag.cmd.push(function(){googletag.pubads().addEventListener('slotRenderEnded',function(info){if(info.isEmpty==!1){
  478.  
  479.   rprtData.imp = true;
  480.   rprtData = JSON.stringify(rprtData);
  481.   // rprt.send(rprtData);
  482.  
  483.   document.dispatchEvent(impression)
  484.   console.log('impression')
  485.  
  486.   }else if(info.isEmpty==!0){
  487.  
  488.   rprtData = JSON.stringify(rprtData);
  489.   // rprt.send(rprtData);
  490.  
  491.   document.dispatchEvent(noImpression)
  492.   console.log('no impression')
  493.  
  494.   }})})</script></head><body><div id='inject-amazon-slot-id-${a}'>
  495.   <script>
  496.   googletag.cmd.push(function(){googletag.display('inject-amazon-slot-id-${a}')});
  497.   </script></div></body></html>`
  498.             break;
  499.         case 'other':
  500.             return `<html><head><script>var impression=new Event('impression');var noImpression=new Event('noImpression');
  501.  
  502.   var rprt = new XMLHttpRequest()
  503.   rprtData = {
  504.   'pubIndex':${plInfo[placementNumber].pubIndex},
  505.   'placementIndex':${plInfo[placementNumber].placementIndex},
  506.   'placementName':'${plInfo[placementNumber].name}',
  507.   'imp':false,
  508.   'impType':'live',
  509.   'partner':'other'
  510.   }
  511.   dataSent = false;
  512.   rprt.open('POST','https://powerad.ai/reports/new',true);rprt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  513.   var impTimeout=setTimeout(function(){
  514.  
  515.   rprtData.imp = true;
  516.   rprtData = JSON.stringify(rprtData);
  517.   // rprt.send(rprtData);
  518.   dataSent = true;
  519.  
  520.   document.dispatchEvent(impression);console.log('impression from other')
  521.  
  522.   },${plInfo[placementNumber].liveDemand[a].timeout})</script>${plInfo[placementNumber].liveDemand[a].headTag}</head><body>${plInfo[placementNumber].liveDemand[a].bodyTag}</body><script>document.addEventListener('noImpression',()=>{console.log('no impression event fired from passback')
  523.  
  524.   rprtData = JSON.stringify(rprtData);
  525.   // rprt.send(rprtData);
  526.   dataSent = true;
  527.  
  528.  
  529.   if(document.querySelector('iframe')){
  530.   document.querySelector('iframe').addEventListener('noImpression',()=>{
  531.   console.log('no impression fired from passback in iframe')
  532.  
  533.   rprtData = JSON.stringify(rprtData);
  534.   // rprt.send(rprtData);
  535.   dataSent = true;
  536.  
  537.  
  538.   })
  539.   }
  540.  
  541.   })
  542.  
  543.   setTimeout(function(){
  544.   if(!dataSent){
  545.   console.log('sending now from timeout')
  546.   rprtData = JSON.stringify(rprtData);
  547.   // rprt.send(rprtData);
  548.   dataSent = true;
  549.   }
  550.   },${plInfo[placementNumber].liveDemand[a].timeout})
  551.  
  552.  
  553.   </script></html>`
  554.             break
  555.         }
  556.     } else {
  557.         return `<html><head><title>Yukshy inject</title><script>var impression=new Event('impression')
  558.   var noImpression=new Event('noImpression')
  559.   function creativeLoaded(){document.dispatchEvent(impression)
  560.  
  561.   var rprt = new XMLHttpRequest()
  562.   rprtData = {
  563.   'pubIndex':${plInfo[placementNumber].pubIndex},
  564.   'placementIndex':${plInfo[placementNumber].placementIndex},
  565.   'placementName':'${plInfo[placementNumber].name}',
  566.   'imp':true,
  567.   'impType':'direct',
  568.   'partner':'direct'
  569.   }
  570.   rprtData = JSON.stringify(rprtData);rprt.open('POST','https://powerad.ai/reports/new',true);rprt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  571.   rprt.send(rprtData);
  572.   }</script></head><body><img src="${plInfo[placementNumber].creativeLink}" onload="creativeLoaded()"></body></html>`
  573.     }
  574. }
  575.  
  576. function addAttributes(frame) {
  577.     frame.src = 'about:blank';
  578.     frame.setAttribute('frameborder', '0');
  579.     frame.setAttribute('marginwidth', '0');
  580.     frame.setAttribute('marginheight', '0');
  581.     frame.setAttribute('scrolling', 'no');
  582.     frame.style.width = 'inherit';
  583.     frame.style.height = 'inherit';
  584.     frame.style.display = 'inherit'
  585.     frame.className = 'pa-original-frame'
  586. }
  587. var tagHolders = [],
  588.     unitStatus = {},
  589.     refreshTimeouts = {}
  590. timeouts = {}, plInfo = {};
  591. var defaultStyles = function (placement, div) {
  592.     var result = `
  593.     height: 0;
  594.     // update here
  595.     // transition: height 0.5s;
  596.     transition: height 0.1s;
  597.     position: ${placement.type == 'multiInsert' ? placement.contentPosition : placement.type == 'stickyBottom' || placement.type == 'stickyTop' || placement.type == 'adhesion' ? 'fixed': 'relative'};
  598.     z-index: ${placement.styles.zIndex || 100000};
  599.     overflow: hidden;
  600.     ${placement.type == 'stickyBottom' ? 'bottom: '+placement.baseOffsetBottom +'px;' : ''}
  601.     ${placement.type == 'stickyTop' ? 'top: '+placement.leadOffsetTop + 'px;' : ''}
  602.  
  603.     ${placement.type == 'stickyBottom' || placement.type == 'stickyTop' ? 'margin: 0 auto;left:0;right:0;' : ''}
  604.     display: ${placement.type == 'multiInsert' ? placement.contentDisplay : 'block'};
  605.     width: ${placement.styles.width}px;${placement.styles.margin ? 'margin:'+placement.styles.margin+';' : ''}${placement.type == 'multiInsert' && placement.contentPosition == 'sticky' ? 'top: ' + ((window.innerHeight / 2) - (placement.styles.height / 2)) + 'px;' : ''}${placement.type == 'multiInsert' && placement.contentPosition == 'fixed' ? placement.inContentParams.stickyFootStop ? document.querySelector(placement.selector).getBoundingClientRect().top + document.querySelector(placement.selector).getBoundingClientRect().height + placement.inContentParams.fixedTopOffset > (window.innerHeight / 2) - (placement.styles.height / 2) ? 'top: '+ (document.querySelector(placement.selector).getBoundingClientRect().height + document.querySelector(placement.selector).getBoundingClientRect().top + placement.inContentParams.fixedTopOffset) +  'px;' : document.querySelector(placement.inContentParams.stickyFootStop).getBoundingClientRect().top < ((window.innerHeight/2)+(placement.styles.height/2)+placement.inContentParams.stickyFootOffset) ? 'top: ' + (document.querySelector(placement.inContentParams.stickyFootStop).getBoundingClientRect().top - div.offsetHeight - placement.inContentParams.stickyFootOffset - placement.styles.height) + 'px;' : 'top: '+ ((window.innerHeight / 2) - (placement.styles.height / 2)) + 'px;' : document.querySelector(placement.selector).getBoundingClientRect().top + document.querySelector(placement.selector).getBoundingClientRect().height + placement.inContentParams.fixedTopOffset > ((window.innerHeight / 2) - (placement.styles.height / 2)) ? 'top: '+ (document.querySelector(placement.selector).getBoundingClientRect().height + document.querySelector(placement.selector).getBoundingClientRect().top + placement.inContentParams.fixedTopOffset) + 'px;'  : 'top: '+ ((window.innerHeight / 2) - (placement.styles.height / 2)) + 'px;' : ''}${placement.type == 'multiInsert' && placement.contentPosition == 'sticky' ? placement.inContentParams.marginLeft == 'auto' ? 'margin-left: '+(document.querySelector(placement.selector).offsetWidth - placement.styles.width) / 2 + 'px;' : 'margin-left: '+placement.inContentParams.marginLeft+'px;' : ''}${placement.type == 'multiInsert' && placement.contentPosition == 'sticky' ? placement.inContentParams.marginRight == 'auto' ? 'margin-right: '+(document.querySelector(placement.selector).offsetWidth - placement.styles.width) / 2 + 'px;' : 'margin-right: '+placement.inContentParams.marginRight+'px;' : ''}${placement.type == 'multiInsert' && placement.contentPosition == 'fixed' ? 'left: ' + ((document.querySelector(placement.selector).getBoundingClientRect().left + (document.querySelector(placement.selector).offsetWidth - placement.styles.width) / 2) - placement.inContentParams.offsetLeft + placement.inContentParams.offsetRight) + 'px;' : ''}${placement.type == 'adhesion' ? placement.adhesionParams.side != 'both' ?[placement.adhesionParams.side]+': '+ ((((window.innerWidth - placement.contentWidth)/2)/2)-(placement.styles.width/2))+'px;' : div.classList[3] ? 'right: '+ ((((window.innerWidth - placement.contentWidth)/2)/2)-(placement.styles.width/2))+'px;' : 'left: '+ ((((window.innerWidth - placement.contentWidth)/2)/2)-(placement.styles.width/2))+'px;' :''}${placement.type == 'adhesion' ? placement.headStopSide && placement.footStopSide ? document.querySelector(placement.headStopSide).getBoundingClientRect().top + document.querySelector(placement.headStopSide).getBoundingClientRect().height + placement.adhesionParams.headOffset > (window.innerHeight/2)-(placement.styles.height/2) ? 'top: '+(document.querySelector(placement.headStopSide).getBoundingClientRect().top + document.querySelector(placement.headStopSide).getBoundingClientRect().height + placement.adhesionParams.headOffset) + 'px;' : document.querySelector(placement.footStopSide).getBoundingClientRect().top < (window.innerHeight/2)+(placement.styles.height/2)+placement.adhesionParams.footOffset ? 'top: '+(document.querySelector(placement.footStopSide).getBoundingClientRect().top - placement.adhesionParams.footOffset - placement.styles.height)+'px;' : 'top: '+((window.innerHeight/2)-(placement.styles.height/2))+'px;' : placement.headStopSide && !placement.footStopSide ? document.querySelector(placement.headStopSide).getBoundingClientRect().top + document.querySelector(placement.headStopSide).getBoundingClientRect().height + placement.adhesionParams.headOffset > (window.innerHeight/2)-(placement.styles.height/2) ? 'top: '+(document.querySelector(placement.headStopSide).getBoundingClientRect().top + document.querySelector(placement.headStopSide).getBoundingClientRect().height + placement.adhesionParams.headOffset) + 'px;' : 'top: '+((window.innerHeight/2)-(placement.styles.height/2))+'px;' : !placement.headStopSide && placement.footStopSide ? document.querySelector(placement.footStopSide).getBoundingClientRect().top < (window.innerHeight/2)+(placement.styles.height/2)+placement.adhesionParams.footOffset ? 'top: '+(document.querySelector(placement.footStopSide).getBoundingClientRect().top - placement.adhesionParams.footOffset - placement.styles.height)+'px;' : 'top: '+((window.innerHeight/2)-(placement.styles.height/2))+'px;' : !placement.headStopSide && !placement.footStopSide ? 'top: '+((window.innerHeight/2)-(placement.styles.height/2))+'px;' : '' : ''}
  606.   `
  607.     if (placement.type == 'multiInsert' && placement.contentPosition == 'fixed') {
  608.         window.addEventListener('resize', () => {
  609.             div.style.left = ((document.querySelector(placement.selector).getBoundingClientRect().left + (document.querySelector(placement.selector).offsetWidth - placement.styles.width) / 2) - placement.inContentParams.offsetLeft + placement.inContentParams.offsetRight) + 'px'
  610.         })
  611.         document.addEventListener('scroll', () => {
  612.             placement.inContentParams.stickyFootStop ? document.querySelector(placement.selector).getBoundingClientRect().top + document.querySelector(placement.selector).getBoundingClientRect().height + placement.inContentParams.fixedTopOffset > (window.innerHeight / 2) - (placement.styles.height / 2) ? div.style.top = (document.querySelector(placement.selector).getBoundingClientRect().height + document.querySelector(placement.selector).getBoundingClientRect().top + placement.inContentParams.fixedTopOffset) + 'px' : document.querySelector(placement.inContentParams.stickyFootStop).getBoundingClientRect().top < ((window.innerHeight / 2) + (placement.styles.height / 2) + placement.inContentParams.stickyFootOffset) ? div.style.top = document.querySelector(placement.inContentParams.stickyFootStop).getBoundingClientRect().top - placement.styles.height - placement.inContentParams.stickyFootOffset + 'px' : div.style.top = (window.innerHeight / 2) - (placement.styles.height / 2) + 'px' : document.querySelector(placement.selector).getBoundingClientRect().top + document.querySelector(placement.selector).getBoundingClientRect().height + placement.inContentParams.fixedTopOffset > (window.innerHeight / 2) - (placement.styles.height / 2) ? div.style.top = (document.querySelector(placement.selector).getBoundingClientRect().height + document.querySelector(placement.selector).getBoundingClientRect().top + placement.inContentParams.fixedTopOffset) + 'px' : div.style.top = (window.innerHeight / 2) - (placement.styles.height / 2) + 'px'
  613.         })
  614.     }
  615.     if (placement.type == 'adhesion') {
  616.         window.addEventListener('resize', () => {
  617.             changeSide();
  618.             changeTop()
  619.         })
  620.         document.addEventListener('scroll', () => {
  621.             changeTop()
  622.         })
  623.  
  624.         function changeSide() {
  625.             if (placement.adhesionParams.side != 'both') {
  626.                 div.style[placement.adhesionParams.side] = ((((window.innerWidth - placement.contentWidth) / 2) / 2) - (placement.styles.width / 2)) + 'px'
  627.             } else {
  628.                 if (div.classList[3]) {
  629.                     div.style.right = ((((window.innerWidth - placement.contentWidth) / 2) / 2) - (placement.styles.width / 2)) + 'px'
  630.                 } else {
  631.                     div.style.left = ((((window.innerWidth - placement.contentWidth) / 2) / 2) - (placement.styles.width / 2)) + 'px'
  632.                 }
  633.             }
  634.         }
  635.  
  636.         function changeTop() {
  637.             placement.headStopSide && placement.footStopSide ? document.querySelector(placement.headStopSide).getBoundingClientRect().top + document.querySelector(placement.headStopSide).getBoundingClientRect().height + placement.adhesionParams.headOffset > (window.innerHeight / 2) - (placement.styles.height / 2) ? div.style.top = (document.querySelector(placement.headStopSide).getBoundingClientRect().top + document.querySelector(placement.headStopSide).getBoundingClientRect().height + placement.adhesionParams.headOffset) + 'px' : document.querySelector(placement.footStopSide).getBoundingClientRect().top < (window.innerHeight / 2) + (placement.styles.height / 2) + placement.adhesionParams.footOffset ? div.style.top = (document.querySelector(placement.footStopSide).getBoundingClientRect().top - placement.adhesionParams.footOffset - placement.styles.height) + 'px' : div.style.top = ((window.innerHeight / 2) - (placement.styles.height / 2)) + 'px' : placement.headStopSide && !placement.footStopSide ? document.querySelector(placement.headStopSide).getBoundingClientRect().top + document.querySelector(placement.headStopSide).getBoundingClientRect().height + placement.adhesionParams.headOffset > (window.innerHeight / 2) - (placement.styles.height / 2) ? div.style.top = (document.querySelector(placement.headStopSide).getBoundingClientRect().top + document.querySelector(placement.headStopSide).getBoundingClientRect().height + placement.adhesionParams.headOffset) + 'px' : div.style.top = ((window.innerHeight / 2) - (placement.styles.height / 2)) + 'px' : !placement.headStopSide && placement.footStopSide ? document.querySelector(placement.footStopSide).getBoundingClientRect().top < (window.innerHeight / 2) + (placement.styles.height / 2) + placement.adhesionParams.footOffset ? div.style.top = (document.querySelector(placement.footStopSide).getBoundingClientRect().top - placement.adhesionParams.footOffset - placement.styles.height) + 'px' : div.style.top = ((window.innerHeight / 2) - (placement.styles.height / 2)) + 'px' : !placement.headStopSide && !placement.footStopSide ? div.style.top = ((window.innerHeight / 2) - (placement.styles.height / 2)) + 'px' : ''
  638.         }
  639.     }
  640.     return result
  641. }
  642.  
  643. function addCloseBtn(unit) {
  644.     var closeBtn = document.createElement('span');
  645.     closeBtn.className = 'pa-close-btn';
  646.     closeBtn.style = 'position: absolute;right: 1px;width: 18px;height: 18px;font-size: 13px;top:0;';
  647.     unit.appendChild(closeBtn);
  648.     closeBtn.innerHTML = '&#10060';
  649.     closeBtn.onmouseenter = function () {
  650.         this.innerHTML = 'Close Ad';
  651.         this.style.color = 'white';
  652.         this.style.background = 'rgb(0,0,0,0.8)';
  653.         this.style.padding = '1px';
  654.         this.style.width = '100px';
  655.         this.style.textAlign = 'center';
  656.         this.style.cursor = 'pointer';
  657.         this.style.top = 0;
  658.         this.style.right = 0
  659.     }
  660.     closeBtn.onmouseleave = function () {
  661.         this.innerHTML = '&#10060';
  662.         this.style.width = '18px';
  663.         this.style.background = 'none';
  664.         this.style.right = '1px'
  665.     }
  666.     closeBtn.addEventListener('click', () => {
  667.         unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length);
  668.         unitStatus[unitNumber].closed = !0;
  669.         unit.style.transition = 'height 0.1s';
  670.         unit.style.height = 0;
  671.         setTimeout(() => {
  672.             unit.style.display = 'none';
  673.             unit.style.opacity = 0;
  674.             unit.remove()
  675.         }, 500);
  676.         if (refreshTimeouts[unitNumber]) {
  677.             if (refreshTimeouts[unitNumber].started) {
  678.                 clearTimeout(refreshTimeouts[unitNumber].timeout);
  679.                 refreshTimeouts[unitNumber].running = !1;
  680.                 document.addEventListener('scroll', refreshTimeouts[unitNumber].listeners);
  681.                 window.addEventListener('resize', refreshTimeouts[unitNumber].listeners);
  682.                 document.addEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
  683.             }
  684.         }
  685.         if (timeouts[unitNumber]) {
  686.             clearTimeout(timeouts[unitNumber].timeout);
  687.             timeouts[unitNumber].running = !1
  688.         }
  689.     })
  690. }
  691.  
  692. function injectMulti(placement) {
  693.     if (document.querySelector(placement.selector) != null) {
  694.         plInfo[placement.placementIndex] = placement;
  695.         var newDiv = document.createElement('div');
  696.         newDiv.className = 'pa-global-class';
  697.         newDiv.classList.add('pa-multi-insert');
  698.         newDiv.classList.add('pa-multi-insert-' + placement.placementIndex);
  699.         newDiv.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length;
  700.         newDiv.style = defaultStyles(placement, newDiv);
  701.         if (!placement.firstNodeContent || placement.contentPosition == 'sticky') {
  702.             if (placement.contentInsertMode == 'append') {
  703.                 document.querySelector(placement.selector).appendChild(newDiv)
  704.             } else if (placement.contentInsertMode == 'after') {
  705.                 selector = document.querySelector(placement.selector);
  706.                 selectorParent = document.querySelector(placement.selector).parentNode;
  707.                 selectorParent.insertBefore(newDiv, selector.nextElementSibling)
  708.             } else if (placement.contentInsertMode == 'before') {
  709.                 selector = document.querySelector(placement.selector);
  710.                 selectorParent = document.querySelector(placement.selector).parentNode;
  711.                 selectorParent.insertBefore(newDiv, selector)
  712.             } else if (placement.contentInsertMode == 'firstChild') {
  713.                 if (document.querySelector(placement.selector).childNodes[0]) {
  714.                     document.querySelector(placement.selector).childNodes[0].before(newDiv)
  715.                 } else {
  716.                     console.warn('can\'t inject in content placement ' + placement.placementIndex + ', due to selector not having any children')
  717.                 }
  718.             }
  719.         } else if (placement.contentPosition != 'fixed') {
  720.             if (placement.contentInsertMode == 'append') {
  721.                 document.querySelectorAll(placement.selector)[placement.firstNodeContent - 1].appendChild(newDiv);
  722.                 var holder = placement.cloneEveryContent;
  723.                 for (a = placement.cloneEveryContent; a < document.querySelectorAll(placement.selector).length; a += holder) {
  724.                     if (document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1]) {
  725.                         var clone = newDiv.cloneNode()
  726.                         clone.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length
  727.                         document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1].appendChild(clone)
  728.                     }
  729.                 }
  730.             } else if (placement.contentInsertMode == 'after') {
  731.                 selector = document.querySelector(placement.selector);
  732.                 selectorParent = document.querySelectorAll(placement.selector)[placement.firstNodeContent].parentNode;
  733.                 selectorParent.insertBefore(newDiv, document.querySelectorAll(placement.selector)[placement.firstNodeContent]);
  734.                 var holder = placement.cloneEveryContent;
  735.                 for (a = placement.cloneEveryContent; a < document.querySelectorAll(placement.selector).length; a += holder) {
  736.                     if (document.querySelectorAll(placement.selector)[a + placement.firstNodeContent]) {
  737.                         var clone = newDiv.cloneNode()
  738.                         clone.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length;
  739.                         selectorParent = document.querySelectorAll(placement.selector)[a + placement.firstNodeContent].parentNode;
  740.                         selectorParent.insertBefore(clone, document.querySelectorAll(placement.selector)[a + placement.firstNodeContent])
  741.                     }
  742.                 }
  743.             } else if (placement.contentInsertMode == 'before') {
  744.                 selector = document.querySelector(placement.selector);
  745.                 selectorParent = document.querySelectorAll(placement.selector)[placement.firstNodeContent].parentNode;
  746.                 selectorParent.insertBefore(newDiv, document.querySelectorAll(placement.selector)[placement.firstNodeContent - 1]);
  747.                 var holder = placement.cloneEveryContent;
  748.                 for (a = placement.cloneEveryContent; a < document.querySelectorAll(placement.selector).length; a += holder) {
  749.                     if (document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1]) {
  750.                         var clone = newDiv.cloneNode();
  751.                         clone.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length;
  752.                         selectorParent = document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1].parentNode;
  753.                         selectorParent.insertBefore(clone, document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1])
  754.                     }
  755.                 }
  756.             } else if (placement.contentInsertMode == 'firstChild') {
  757.                 if (document.querySelectorAll(placement.selector)[placement.firstNodeContent]) {
  758.                     document.querySelectorAll(placement.selector)[placement.firstNodeContent - 1].childNodes[0].before(newDiv);
  759.                     var holder = placement.cloneEveryContent;
  760.                     for (a = placement.cloneEveryContent; a < document.querySelectorAll(placement.selector).length; a += holder) {
  761.                         if (document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1]) {
  762.                             var clone = newDiv.cloneNode();
  763.                             clone.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length;
  764.                             document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1].childNodes[0].before(clone)
  765.                         }
  766.                     }
  767.                 } else {
  768.                     console.warn('can\'t inject in content placement ' + placement.placementIndex + ', due to selector not having any children')
  769.                 }
  770.             }
  771.         }
  772.         for (let i of document.querySelectorAll('.pa-multi-insert-' + placement.placementIndex)) {
  773.             var unitNumber = i.id.slice(i.id.lastIndexOf('-') + 1, i.id.length);
  774.             unitStatus[unitNumber] = {
  775.                 firstLoad: !1,
  776.                 opened: !1,
  777.                 closed: !1
  778.             }
  779.             plInView(i);
  780.             document.addEventListener('scroll', () => {
  781.                 plInView(i)
  782.             })
  783.             window.addEventListener('resize', () => {
  784.                 plInView(i)
  785.             })
  786.             document.addEventListener('visibilitychange', () => {
  787.                 plInView(i)
  788.             })
  789.             if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
  790.                 refreshTimeouts[unitNumber] = {
  791.                     started: !1,
  792.                     running: !1
  793.                 }
  794.             }
  795.             if (placement.styles.closeBtn) {
  796.                 addCloseBtn(i)
  797.             }
  798.             if (placement.timeouts.remove) {
  799.                 timeouts[unitNumber] = {
  800.                     running: !1
  801.                 }
  802.                 timeoutRemove(i)
  803.             }
  804.         }
  805.     }
  806. }
  807.  
  808. function injectStickyBottom(placement) {
  809.     plInfo[placement.placementIndex] = placement;
  810.     var newDiv = document.createElement('div');
  811.     newDiv.className = 'pa-global-class';
  812.     newDiv.classList.add('pa-sticky-bototm');
  813.     newDiv.classList.add('pa-sticky-bottom-' + placement.placementIndex);
  814.     newDiv.id = 'pa-sticky-bottom-' + document.querySelectorAll('.pa-global-class').length
  815.     newDiv.style = defaultStyles(placement, newDiv)
  816.     document.querySelector('body').appendChild(newDiv)
  817.     unitNumber = newDiv.id.slice(newDiv.id.lastIndexOf('-') + 1, newDiv.id.length);
  818.     unitStatus[unitNumber] = {
  819.         firstLoad: !1,
  820.         opened: !1,
  821.         closed: !1
  822.     }
  823.     plInView(newDiv)
  824.     document.addEventListener('scroll', () => {
  825.         plInView(newDiv)
  826.     })
  827.     window.addEventListener('resize', () => {
  828.         plInView(newDiv)
  829.     })
  830.     document.addEventListener('visibilitychange', () => {
  831.         plInView(newDiv)
  832.     })
  833.     if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
  834.         refreshTimeouts[unitNumber] = {
  835.             started: !1,
  836.             running: !1
  837.         }
  838.     }
  839.     if (placement.styles.closeBtn) {
  840.         addCloseBtn(newDiv)
  841.     }
  842.     if (placement.timeouts.remove) {
  843.         timeouts[unitNumber] = {
  844.             running: !1
  845.         }
  846.         timeoutRemove(newDiv)
  847.     }
  848. }
  849.  
  850. function injectStickyTop(placement) {
  851.     plInfo[placement.placementIndex] = placement;
  852.     var newDiv = document.createElement('div');
  853.     newDiv.className = 'pa-global-class';
  854.     newDiv.classList.add('pa-sticky-top');
  855.     newDiv.classList.add('pa-sticky-top-' + placement.placementIndex);
  856.     newDiv.id = 'pa-sticky-top-' + document.querySelectorAll('.pa-global-class').length
  857.     newDiv.style = defaultStyles(placement, newDiv)
  858.     document.querySelector('body').appendChild(newDiv)
  859.     unitNumber = newDiv.id.slice(newDiv.id.lastIndexOf('-') + 1, newDiv.id.length);
  860.     unitStatus[unitNumber] = {
  861.         firstLoad: !1,
  862.         opened: !1,
  863.         closed: !1
  864.     }
  865.     plInView(newDiv)
  866.     document.addEventListener('scroll', () => {
  867.         plInView(newDiv)
  868.     })
  869.     window.addEventListener('resize', () => {
  870.         plInView(newDiv)
  871.     })
  872.     document.addEventListener('visibilitychange', () => {
  873.         plInView(newDiv)
  874.     })
  875.     if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
  876.         refreshTimeouts[unitNumber] = {
  877.             started: !1,
  878.             running: !1
  879.         }
  880.     }
  881.     if (placement.styles.closeBtn) {
  882.         addCloseBtn(newDiv)
  883.     }
  884.     if (placement.timeouts.remove) {
  885.         timeouts[unitNumber] = {
  886.             running: !1
  887.         }
  888.         timeoutRemove(newDiv)
  889.     }
  890. }
  891.  
  892. function injectAdhesion(placement) {
  893.     if ((!placement.headStopSide || document.querySelector(placement.headStopSide) != null) && (!placement.footStopSide || document.querySelector(placement.footStopSide))) {
  894.         plInfo[placement.placementIndex] = placement;
  895.         var newDiv = document.createElement('div');
  896.         newDiv.className = 'pa-global-class';
  897.         newDiv.classList.add('pa-adhesion');
  898.         newDiv.classList.add('pa-adhesion-' + placement.placementIndex);
  899.         newDiv.id = 'pa-adhesion-' + document.querySelectorAll('.pa-global-class').length
  900.         newDiv.style = defaultStyles(placement, newDiv)
  901.         document.querySelector('body').appendChild(newDiv)
  902.         var unitNumber = newDiv.id.slice(newDiv.id.lastIndexOf('-') + 1, newDiv.id.length);
  903.         unitStatus[unitNumber] = {
  904.             firstLoad: !1,
  905.             opened: !1,
  906.             closed: !1
  907.         }
  908.         plInView(newDiv)
  909.         document.addEventListener('scroll', () => {
  910.             plInView(newDiv)
  911.         })
  912.         window.addEventListener('resize', () => {
  913.             plInView(newDiv)
  914.         })
  915.         document.addEventListener('visibilitychange', () => {
  916.             plInView(newDiv)
  917.         })
  918.         if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
  919.             refreshTimeouts[unitNumber] = {
  920.                 started: !1,
  921.                 running: !1
  922.             }
  923.         }
  924.         if (placement.styles.closeBtn) {
  925.             addCloseBtn(newDiv)
  926.         }
  927.         if (placement.timeouts.remove) {
  928.             timeouts[unitNumber] = {
  929.                 running: !1
  930.             }
  931.             timeoutRemove(newDiv)
  932.         }
  933.         if (placement.adhesionParams.side == 'both') {
  934.             var clone = newDiv.cloneNode()
  935.             clone.classList.add('pa-adhesion-right')
  936.             clone.id = 'pa-adhesion-' + document.querySelectorAll('.pa-global-class').length
  937.             clone.style = defaultStyles(placement, clone)
  938.             document.querySelector('body').appendChild(clone)
  939.             var unitNumber = clone.id.slice(clone.id.lastIndexOf('-') + 1, clone.id.length);
  940.             unitStatus[unitNumber] = {
  941.                 firstLoad: !1,
  942.                 opened: !1,
  943.                 closed: !1
  944.             }
  945.             plInView(clone)
  946.             document.addEventListener('scroll', () => {
  947.                 plInView(clone)
  948.             })
  949.             window.addEventListener('resize', () => {
  950.                 plInView(clone)
  951.             })
  952.             document.addEventListener('visibilitychange', () => {
  953.                 plInView(clone)
  954.             })
  955.             if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
  956.                 refreshTimeouts[unitNumber] = {
  957.                     started: !1,
  958.                     running: !1
  959.                 }
  960.             }
  961.             if (placement.styles.closeBtn) {
  962.                 addCloseBtn(clone)
  963.             }
  964.             if (placement.timeouts.remove) {
  965.                 timeouts[unitNumber] = {
  966.                     running: !1
  967.                 }
  968.                 timeoutRemove(clone)
  969.             }
  970.         }
  971.     }
  972. }
  973.  
  974. function injectVideo(placement) {
  975.     if (document.querySelector(placement.selector) != null || placement.videoParams.position == 'fixed') {
  976.         var videoDiv = document.createElement('div');
  977.         videoDiv.className = 'powerad-video';
  978.         videoDiv.classList.add('powerad-video-0');
  979.         videoDiv.id = 'powerad-video-0';
  980.         userCliked = !1;
  981.         document.addEventListener('click', () => {
  982.             userCliked = !0
  983.         })
  984.         switch (placement.videoParams.position) {
  985.         case 'relative':
  986.         case 'sticky':
  987.         case 'static':
  988.             switch (placement.videoParams.insertMode) {
  989.             case 'after':
  990.                 selector = document.querySelector(placement.selector)
  991.                 selectorParent = selector.parentNode
  992.                 selectorParent.insertBefore(videoDiv, selector.nextElementSibling)
  993.                 break;
  994.             case 'before':
  995.                 selector = document.querySelector(placement.selector)
  996.                 selectorParent = selector.parentNode
  997.                 selectorParent.insertBefore(videoDiv, selector)
  998.                 break;
  999.             case 'append':
  1000.                 document.querySelector(placement.selector).appendChild(videoDiv)
  1001.                 break;
  1002.             case 'firstChild':
  1003.                 if (document.querySelector(placement.selector).childNodes[0]) {
  1004.                     document.querySelector(placement.selector).childNodes[0].before(videoDiv)
  1005.                 } else {
  1006.                     console.warn('can\'t inject video placement ' + placement.placementIndex + ', due to selector not having any children')
  1007.                 }
  1008.                 break
  1009.             }
  1010.             break;
  1011.         case 'fixed':
  1012.             document.querySelector('body').appendChild(videoDiv)
  1013.             break
  1014.         }
  1015.         videoDiv.style = `
  1016.                   max-height: 0;
  1017.                   margin: ${placement.styles.margin || '0 auto'};
  1018.                   overflow: hidden;
  1019.                   text-align: center;
  1020.                   transition: max-height 500ms ease-out;
  1021.                   width: 100%;
  1022.                   position:${placement.videoParams.position};
  1023.                   z-index:${placement.styles.zIndex || 1000000};
  1024.                   `
  1025.         placement.videoParams.position == 'sticky' ? videoDiv.style.top = placement.videoParams.offsetTop + 'px' : {}
  1026.         var videoCloseBtn = document.createElement('span');
  1027.         videoCloseBtn.style = `
  1028.                   position: absolute;
  1029.                   right: 1px;
  1030.                   width: 18px;
  1031.                   height: 18px;
  1032.                   font-size: 13px;
  1033.                   top: 0;
  1034.                   z-index: 2;
  1035.                   `
  1036.         videoDiv.appendChild(videoCloseBtn)
  1037.         if (placement.videoParams.position == 'fixed') {
  1038.             videoCloseBtn.innerHTML = '&#10060'
  1039.             addCloseBtnHover()
  1040.         } else {
  1041.             if (placement.styles.closeBtn) {
  1042.                 videoCloseBtn.innerHTML = '&#10060'
  1043.                 addCloseBtnHover()
  1044.             }
  1045.         }
  1046.         videoCloseBtn.addEventListener('click', () => {
  1047.             closeAndRemove()
  1048.         })
  1049.         switch (placement.videoParams.position) {
  1050.         case 'relative':
  1051.         case 'static':
  1052.             videoDiv.style.maxWidth = placement.videoParams.maxWidth + 'px';
  1053.             videoDiv.style.position = placement.videoParams.position;
  1054.             videoInView() ? injectVideo() : {}
  1055.             document.addEventListener('scroll', () => {
  1056.                 videoInView() ? injectVideo() : {}
  1057.             })
  1058.             break;
  1059.         case 'fixed':
  1060.             videoDiv.style.maxWidth = (window.innerWidth > 600 ? 300 : 200) + 'px';
  1061.             videoDiv.style.position = 'fixed';
  1062.             videoDiv.style.bottom = '10px';
  1063.             videoDiv.style.right = '10px';
  1064.             videoInView() ? injectVideo() : {}
  1065.             document.addEventListener('scroll', () => {
  1066.                 videoInView() ? injectVideo() : {}
  1067.             })
  1068.             break;
  1069.         case 'sticky':
  1070.             videoDiv.style.maxWidth = '100%';
  1071.             videoInView() ? injectVideo() : {}
  1072.             document.addEventListener('scroll', () => {
  1073.                 videoInView() ? injectVideo() : {}
  1074.             })
  1075.             break
  1076.         }
  1077.  
  1078.         function getVideoHeight() {
  1079.             return videoDiv.offsetWidth * 0.5625
  1080.         }
  1081.  
  1082.         function videoInView() {
  1083.             if (placement.videoParams.position != 'fixed') {
  1084.                 if (placement.videoParams.scrollAction == 'pause') {
  1085.                     return videoDiv.getBoundingClientRect().top + (getVideoHeight() / 2) >= 0 && videoDiv.getBoundingClientRect().top + (getVideoHeight() / 2) <= screen.availHeight
  1086.                 } else if (placement.videoParams.scrollAction == 'move') {
  1087.                     return videoDiv.getBoundingClientRect().top + (getVideoHeight() / 2) <= screen.availHeight
  1088.                 }
  1089.             } else {
  1090.                 return !0
  1091.             }
  1092.         }
  1093.  
  1094.         function addCloseBtnHover() {
  1095.             videoCloseBtn.onmouseenter = function () {
  1096.                 this.innerHTML = 'Close Ad';
  1097.                 this.style.color = 'white';
  1098.                 this.style.background = 'rgb(0,0,0,0.7)';
  1099.                 this.style.padding = '2px';
  1100.                 this.style.width = '53px';
  1101.                 this.style.textAlign = 'right';
  1102.                 this.style.cursor = 'pointer'
  1103.             }
  1104.             videoCloseBtn.onmouseleave = function () {
  1105.                 this.innerHTML = '&#10060'
  1106.                 this.style.width = '15px'
  1107.                 this.style.background = 'none'
  1108.             }
  1109.         }
  1110.         var paJwPlayerInstance;
  1111.         var paJwContainerDiv;
  1112.         var paJwVideoDiv;
  1113.         var paAlreadyPlayed = !1;
  1114.  
  1115.         function injectVideo() {
  1116.             if (document.querySelector('#' + videoDiv.id + ' > script') == null && document.querySelector('#' + videoDiv.id + ' > div') == null && !paAlreadyPlayed) {
  1117.                 var jwScript = document.createElement('script');
  1118.                 jwScript.src = placement.videoParams.playerLink;
  1119.                 jwScript.id = 'jw-library-script';
  1120.                 videoDiv.appendChild(jwScript)
  1121.                 paJwContainerDiv = document.createElement('div')
  1122.                 paJwContainerDiv.className - 'pa-jw-media-container';
  1123.                 videoDiv.appendChild(paJwContainerDiv);
  1124.                 paJwVideoDiv = document.createElement('div')
  1125.                 paJwVideoDiv.id = 'pa-jw-player'
  1126.                 paJwContainerDiv.appendChild(paJwVideoDiv)
  1127.                 placement.videoParams.position != 'fixed' ? paJwContainerDiv.style = `
  1128.                         max-height: inherit;
  1129.                         position: inherit;
  1130.                         max-width: inherit;  
  1131.                       ` : {}
  1132.                 jwScript.addEventListener('load', () => {
  1133.                     paJwPlayerInstance = jwplayer('pa-jw-player');
  1134.                     paJwPlayerInstance.setup({
  1135.                         file: placement.videoParams.videoLink
  1136.                     })
  1137.                     paJwPlayerInstance.on('ready', () => {
  1138.                         openAndPlay()
  1139.                     })
  1140.                 })
  1141.             }
  1142.         }
  1143.  
  1144.         function openAndPlay() {
  1145.             switch (placement.videoParams.live) {
  1146.             case false:
  1147.                 videoDiv.style.maxHeight = getVideoHeight() + 'px';
  1148.                 paJwPlayerInstance.play()
  1149.                 paJwPlayerInstance.setMute(!0)
  1150.                 videoDiv.style.height = getVideoHeight() + 'px';
  1151.                 togglePlay()
  1152.                 toggleSound()
  1153.                 toggleFixed()
  1154.                 break;
  1155.             case true:
  1156.                 paJwPlayerInstance.play()
  1157.                 paJwPlayerInstance.setMute(!0)
  1158.                 paJwPlayerInstance.on('adImpression', () => {
  1159.                     console.log('impression recieved for video')
  1160.                     videoDiv.style.maxHeight = getVideoHeight() + 'px';
  1161.                     videoDiv.style.height = getVideoHeight() + 'px';
  1162.                     togglePlay()
  1163.                     toggleSound()
  1164.                     toggleFixed()
  1165.                 })
  1166.                 break
  1167.             }
  1168.             paJwPlayerInstance.on('error adError complete adComplete adSkipped', () => {
  1169.                 closeAndRemove()
  1170.             })
  1171.             paJwPlayerInstance.on('adRequest', (info) => {
  1172.                 console.log('request for video ad sent')
  1173.             })
  1174.             paJwPlayerInstance.on('adError', (err) => {
  1175.                 err.message == 'NO_FILL' ? console.log('no fill for video request') : console.log('error in video ad request: ' + err.message)
  1176.             })
  1177.         }
  1178.  
  1179.         function togglePlay() {
  1180.             document.addEventListener('scroll', () => {
  1181.                 videoInView() ? paJwPlayerInstance.play() : paJwPlayerInstance.pause()
  1182.             })
  1183.         }
  1184.  
  1185.         function toggleSound() {
  1186.             !!window.chrome ? userCliked ? toggleSound() : document.addEventListener('click', () => {
  1187.                 toggleSound()
  1188.             }) : toggleSound()
  1189.  
  1190.             function toggleSound() {
  1191.                 paJwContainerDiv.onmouseenter = function () {
  1192.                     paJwPlayerInstance.setMute(!1)
  1193.                 }
  1194.                 paJwContainerDiv.onmouseleave = function () {
  1195.                     paJwPlayerInstance.setMute(!0)
  1196.                 }
  1197.             }
  1198.         }
  1199.  
  1200.         function toggleFixed() {
  1201.             if (placement.videoParams.scrollAction == 'move' && placement.videoParams.position != 'fixed') {
  1202.                 document.addEventListener('scroll', () => {
  1203.                     if (!paAlreadyPlayed) {
  1204.                         videoDiv.getBoundingClientRect().top + (getVideoHeight() / 2) >= 0 ? changeFromFixed() : changeToFixed()
  1205.                     }
  1206.                 })
  1207.  
  1208.                 function changeToFixed() {
  1209.                     paJwContainerDiv.appendChild(videoCloseBtn);
  1210.                     videoCloseBtn.innerHTML = '&#10060'
  1211.                     placement.styles.closeBtn ? {} : addCloseBtnHover();
  1212.                     paJwContainerDiv.style = `
  1213.                           position: fixed;
  1214.                           right: 10px;
  1215.                           left: '';
  1216.                           bottom: 10px;
  1217.                           top: '';
  1218.                           width: ${window.innerWidth > 600? 300:200}px;
  1219.                           height: ${paJwContainerDiv.style.width*0.5625}px;
  1220.                         `
  1221.                 }
  1222.  
  1223.                 function changeFromFixed() {
  1224.                     placement.styles.closeBtn ? videoDiv.appendChild(videoCloseBtn) : videoCloseBtn.remove();
  1225.                     paJwContainerDiv.style = `
  1226.                         left: 0;
  1227.                         right: 0;
  1228.                         top: 0;
  1229.                         bottom: 0;
  1230.                         maxHeight: inherit;
  1231.                         height: inherit;
  1232.                         position: inherit;
  1233.                         width: inherit;
  1234.                         `
  1235.                 }
  1236.             }
  1237.         }
  1238.  
  1239.         function closeAndRemove() {
  1240.             paAlreadyPlayed = !0
  1241.             videoDiv.style.maxHeight = '0px';
  1242.             paJwContainerDiv.style.maxHeight = 'inherit'
  1243.             setTimeout(function () {
  1244.                 paJwPlayerInstance.remove()
  1245.                 videoDiv.removeChild(paJwContainerDiv)
  1246.             }, 500)
  1247.         }
  1248.     }
  1249. }
  1250.  
  1251. function iframeWrite(unit, className) {
  1252.     var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1253.     unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1254.     if (!unitStatus[unitNumber].closed) {
  1255.         if (tagHolders[unitNumber] < plInfo[placementNumber].liveDemand.length || plInfo[placementNumber].demandType != 'live') {
  1256.             newFrame = document.querySelector('#' + unit.id + ' > iframe.' + className).cloneNode();
  1257.             document.querySelector('#' + unit.id + ' > iframe.' + className).remove()
  1258.             unit.appendChild(newFrame)
  1259.             var frame = document.querySelector('#' + unit.id + ' > iframe.' + className)
  1260.             frame.contentDocument.open();
  1261.             frame.contentDocument.write(compileTag(placementNumber, tagHolders[unitNumber]))
  1262.             frame.contentDocument.close()
  1263.         }
  1264.     }
  1265.     if (className == 'pa-original-frame') {
  1266.         impressionListeners(unit)
  1267.     }
  1268. }
  1269.  
  1270. function addFrames(unit) {
  1271.     unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1272.     if (unitStatus[unitNumber]) {
  1273.         if (!unitStatus[unitNumber].firstLoad) {
  1274.             unitStatus[unitNumber].firstLoad = !0
  1275.             tagHolders[unitNumber] = 0
  1276.             var newIframe = document.createElement('iframe');
  1277.             addAttributes(newIframe);
  1278.             document.querySelector('#' + unit.id).appendChild(newIframe)
  1279.             iframeWrite(unit, 'pa-original-frame')
  1280.             impressionListeners(unit)
  1281.             var refreshFrame = newIframe.cloneNode();
  1282.             refreshFrame.className = 'pa-refresh-frame'
  1283.             refreshFrame.style.display = 'none'
  1284.             document.querySelector('#' + unit.id).appendChild(refreshFrame)
  1285.         }
  1286.     }
  1287. }
  1288.  
  1289. function impressionListeners(unit) {
  1290.     unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1291.     if (!unitStatus[unitNumber].closed) {
  1292.         frameDoc = document.querySelector('#' + unit.id + ' > iframe.pa-original-frame').contentDocument
  1293.         frameDoc.addEventListener('impression', () => {
  1294.             var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1295.             var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1296.             unit.style.height = plInfo[placementNumber].styles.height + 'px';
  1297.             unitStatus[unitNumber].opened = !0
  1298.             if (plInfo[placementNumber].timeouts.refresh) {
  1299.                 refresh(unit, plInfo[placementNumber].timeouts.refresh)
  1300.             }
  1301.         })
  1302.         frameDoc.addEventListener('noImpression', () => {
  1303.             var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1304.             var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1305.             tagHolders[unitNumber] = tagHolders[unitNumber] + 1;
  1306.             iframeWrite(unit, 'pa-original-frame')
  1307.             if (tagHolders[unitNumber] >= plInfo[placementNumber].liveDemand.length) {
  1308.                 if (plInfo[placementNumber].timeouts.noImpRefresh) {
  1309.                     refresh(unit, plInfo[placementNumber].timeouts.noImpRefresh)
  1310.                 } else {
  1311.                     if (plInfo[placementNumber].timeouts.refresh) {
  1312.                         refresh(unit, plInfo[placementNumber].timeouts.refresh)
  1313.                     }
  1314.                 }
  1315.             }
  1316.         })
  1317.     }
  1318. }
  1319.  
  1320. function changeDisplay(inView, unit) {
  1321.     var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1322.     var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1323.     if (unitStatus[unitNumber] && unitStatus[unitNumber].opened) {
  1324.         if (plInfo[placementNumber].type != 'adhesion') {
  1325.             if (!inView) {
  1326.                 unit.style.height = 0
  1327.             } else {
  1328.                 unit.style.height = plInfo[placementNumber].styles.height + 'px'
  1329.             }
  1330.         } else {
  1331.             unit.style.transition = 'width 0.1s'
  1332.             if (!inView) {
  1333.                 unit.style.width = 0
  1334.             } else {
  1335.                 unit.style.width = plInfo[placementNumber].styles.width + 'px'
  1336.             }
  1337.         }
  1338.     }
  1339. }
  1340.  
  1341. function plInView(unit) {
  1342.     if (document.visibilityState == 'hidden') {
  1343.         return !1
  1344.     }
  1345.     var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1346.     if (plInfo && plInfo[placementNumber] && plInfo[placementNumber].type == 'adhesion') {
  1347.         if (window.innerWidth < plInfo[placementNumber].contentWidth + (plInfo[placementNumber].styles.width * 2)) {
  1348.             changeDisplay(!1, unit)
  1349.             return !1
  1350.         }
  1351.     }
  1352.     if (plInfo[placementNumber].rules.widthRules.minWidth && window.innerWidth < plInfo[placementNumber].rules.widthRules.minWidth) {
  1353.         changeDisplay(!1, unit)
  1354.         return !1
  1355.     } else {
  1356.         changeDisplay(!0, unit)
  1357.     }
  1358.     if (plInfo[placementNumber].rules.widthRules.maxWidth && window.innerWidth > plInfo[placementNumber].rules.widthRules.maxWidth) {
  1359.         changeDisplay(!1, unit)
  1360.         return !1
  1361.     } else {
  1362.         changeDisplay(!0, unit)
  1363.     }
  1364.     if (plInfo[placementNumber].styles.showScroll && getScroll() < plInfo[placementNumber].styles.showScroll) {
  1365.         changeDisplay(!1, unit)
  1366.         return !1
  1367.     } else {
  1368.         changeDisplay(!0, unit)
  1369.     }
  1370.     if (plInfo[placementNumber].styles.hideScroll && getScroll() > plInfo[placementNumber].styles.hideScroll) {
  1371.         changeDisplay(!1, unit)
  1372.         return !1
  1373.     } else {
  1374.         changeDisplay(!0, unit)
  1375.     }
  1376.     if (unit.getBoundingClientRect().top + (plInfo[placementNumber].styles.height / 2) > 0 && unit.getBoundingClientRect().bottom - (plInfo[placementNumber].styles.height / 2) < window.innerHeight) {
  1377.         addFrames(unit)
  1378.         return !0
  1379.     } else {
  1380.         return !1
  1381.     }
  1382. }
  1383.  
  1384. function refreshNow(unit) {
  1385.     var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1386.     var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1387.     if (!unitStatus[unitNumber].closed) {
  1388.         tagHolders[unitNumber] = 0;
  1389.         iframeWrite(unit, 'pa-refresh-frame')
  1390.         refreshImpListeners(unit)
  1391.     }
  1392. }
  1393.  
  1394. function refreshImpListeners(unit) {
  1395.     var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1396.     var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1397.     if (!unitStatus[unitNumber].closed) {
  1398.         frameDoc = document.querySelector('#' + unit.id + ' > iframe.pa-refresh-frame').contentDocument
  1399.         frameDoc.addEventListener('impression', () => {
  1400.             switchFrames(unit)
  1401.             if (plInfo[placementNumber].timeouts.refresh) {
  1402.                 refresh(unit, plInfo[placementNumber].timeouts.refresh)
  1403.             }
  1404.         })
  1405.         frameDoc.addEventListener('noImpression', () => {
  1406.             var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1407.             var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1408.             tagHolders[unitNumber] = tagHolders[unitNumber] + 1;
  1409.             iframeWrite(unit, 'pa-original-frame')
  1410.             if (tagHolders[unitNumber] >= plInfo[placementNumber].liveDemand.length) {
  1411.                 if (plInfo[placementNumber].timeouts.noImpRefresh) {
  1412.                     refresh(unit, plInfo[placementNumber].timeouts.noImpRefresh)
  1413.                 } else {
  1414.                     if (plInfo[placementNumber].timeouts.refresh) {
  1415.                         refresh(unit, plInfo[placementNumber].timeouts.refresh)
  1416.                     }
  1417.                 }
  1418.             }
  1419.         })
  1420.     }
  1421. }
  1422.  
  1423. function switchFrames(unit) {
  1424.     var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1425.     var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1426.     if (!unitStatus[unitNumber].opened) {
  1427.         unit.style.height = plInfo[placementNumber].styles.height + 'px';
  1428.         unitStatus[unitNumber].opened = !0
  1429.     }
  1430.     document.querySelector('#' + unit.id + ' > iframe.pa-original-frame').style.display = 'none'
  1431.     document.querySelector('#' + unit.id + ' > iframe.pa-refresh-frame').style.display = 'inherit'
  1432.     document.querySelector('#' + unit.id + ' > iframe.pa-refresh-frame').className = 'pa-original-frame'
  1433.     document.querySelector('#' + unit.id + ' > iframe.pa-original-frame').className = 'pa-refresh-frame'
  1434. }
  1435.  
  1436. function refresh(unit, time) {
  1437.     unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1438.     placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1439.     refreshTimeouts[unitNumber].started = !0;
  1440.     refreshTimeouts[unitNumber].running = !0;
  1441.     refreshTimeouts[unitNumber].startTS = new Date().getTime();
  1442.     refreshTimeouts[unitNumber].timeout = setTimeout(() => {
  1443.         timeoutFinished(unit)
  1444.     }, time);
  1445.     if (!refreshTimeouts[unitNumber].listenersAdded) {
  1446.         refreshTimeouts[unitNumber].listenersAdded = !0;
  1447.         addListeners(unit, time)
  1448.     }
  1449.  
  1450.     function addListeners(unit, time) {
  1451.         refreshTimeouts[unitNumber].listeners = function () {
  1452.             var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1453.             if (refreshTimeouts[unitNumber].started && !unitStatus[unitNumber].closed) {
  1454.                 if (plInView(unit)) {
  1455.                     if (!refreshTimeouts[unitNumber].running) {
  1456.                         var dif = refreshTimeouts[unitNumber].stopTS - refreshTimeouts[unitNumber].startTS;
  1457.                         refreshTimeouts[unitNumber].running = !0;
  1458.                         refreshTimeouts[unitNumber].startTS = new Date().getTime() - dif;
  1459.                         refreshTimeouts[unitNumber].timeout = setTimeout(() => {
  1460.                             timeoutFinished(unit)
  1461.                         }, time - dif);
  1462.                         var temp = time - dif
  1463.                     }
  1464.                 } else {
  1465.                     if (refreshTimeouts[unitNumber].running) {
  1466.                         refreshTimeouts[unitNumber].running = !1;
  1467.                         refreshTimeouts[unitNumber].stopTS = new Date().getTime();
  1468.                         clearTimeout(refreshTimeouts[unitNumber].timeout)
  1469.                         var dif = refreshTimeouts[unitNumber].stopTS - refreshTimeouts[unitNumber].startTS
  1470.                     }
  1471.                 }
  1472.             }
  1473.         }
  1474.         document.addEventListener('scroll', refreshTimeouts[unitNumber].listeners)
  1475.         window.addEventListener('resize', refreshTimeouts[unitNumber].listeners)
  1476.         document.addEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
  1477.     }
  1478.  
  1479.     function timeoutFinished(unit) {
  1480.         unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1481.         refreshTimeouts[unitNumber].running = !1;
  1482.         refreshTimeouts[unitNumber].started = !1;
  1483.         refreshTimeouts[unitNumber].startTS = '';
  1484.         refreshTimeouts[unitNumber].stopTS = '';
  1485.         clearTimeout(refreshTimeouts[unitNumber].timeout)
  1486.         removeListeners(unit)
  1487.         if (!unitStatus[unitNumber].closed) {
  1488.             refreshNow(unit)
  1489.         }
  1490.     }
  1491.  
  1492.     function removeListeners(unit) {
  1493.         var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1494.         document.removeEventListener('scroll', refreshTimeouts[unitNumber].listeners)
  1495.         window.removeEventListener('resize', refreshTimeouts[unitNumber].listeners)
  1496.         document.removeEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
  1497.         refreshTimeouts[unitNumber].listenersAdded = !1
  1498.     }
  1499. }
  1500.  
  1501. function timeoutRemove(unit) {
  1502.     var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
  1503.     var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
  1504.     if (!unitStatus[unitNumber].cloed) {
  1505.         timeouts[unitNumber].startTS = new Date().getTime();
  1506.         timeouts[unitNumber].running = !0;
  1507.         timeouts[unitNumber].timeout = setTimeout(() => {
  1508.             unitStatus[unitNumber].closed = !0;
  1509.             unit.style.height = 0;
  1510.             setTimeout(() => {
  1511.                 unit.style.display = 'none';
  1512.                 unit.style.opacity = 0;
  1513.                 unit.remove()
  1514.             }, 500);
  1515.             if (refreshTimeouts[unitNumber] && refreshTimeouts[unitNumber].started) {
  1516.                 clearTimeout(refreshTimeouts[unitNumber].timeout)
  1517.                 refreshTimeouts[unitNumber].running = !1
  1518.                 document.addEventListener('scroll', refreshTimeouts[unitNumber].listeners)
  1519.                 window.addEventListener('resize', refreshTimeouts[unitNumber].listeners)
  1520.                 document.addEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
  1521.             }
  1522.         }, plInfo[placementNumber].timeouts.remove)
  1523.     }
  1524.     document.addEventListener('scroll', () => {
  1525.         listenersChanges(unit)
  1526.     })
  1527.     window.addEventListener('resize', () => {
  1528.         listenersChanges(unit)
  1529.     })
  1530.     document.addEventListener('visibilitychange', () => {
  1531.         listenersChanges(unit)
  1532.     })
  1533.  
  1534.     function listenersChanges(unit) {
  1535.         if (plInView(unit)) {
  1536.             if (!timeouts[unitNumber].running && !unitStatus[unitNumber].closed) {
  1537.                 timeouts[unitNumber].running = !0
  1538.                 if (!timeouts[unitNumber].stopTS) {
  1539.                     timeouts[unitNumber].startTS = new Date().getTime();
  1540.                     timeouts[unitNumber].timeout = setTimeout(() => {
  1541.                         unitStatus[unitNumber].closed = !0;
  1542.                         unit.style.height = 0;
  1543.                         setTimeout(() => {
  1544.                             unit.style.display = 'none';
  1545.                             unit.style.opacity = 0;
  1546.                             unit.remove()
  1547.                         }, 500);
  1548.                         if (refreshTimeouts && refreshTimeouts[unitNumber] && refreshTimeouts[unitNumber].started) {
  1549.                             clearTimeout(refreshTimeouts[unitNumber].timeout)
  1550.                             refreshTimeouts[unitNumber].running = !1
  1551.                             document.removeEventListener('scroll', refreshTimeouts[unitNumber].listeners)
  1552.                             window.removeEventListener('resize', refreshTimeouts[unitNumber].listeners)
  1553.                             document.removeEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
  1554.                         }
  1555.                     }, plInfo[placementNumber].timeouts.remove)
  1556.                 } else {
  1557.                     var dif = timeouts[unitNumber].stopTS - timeouts[unitNumber].startTS
  1558.                     timeouts[unitNumber].startTS = new Date().getTime() - dif;
  1559.                     timeouts[unitNumber].timeout = setTimeout(() => {
  1560.                         unitStatus[unitNumber].closed = !0;
  1561.                         unit.style.height = 0;
  1562.                         setTimeout(() => {
  1563.                             unit.style.display = 'none';
  1564.                             unit.style.opacity = 0;
  1565.                             unit.remove()
  1566.                         }, 500);
  1567.                         if (refreshTimeouts && refreshTimeouts[unitNumber] && refreshTimeouts[unitNumber].started) {
  1568.                             clearTimeout(refreshTimeouts[unitNumber].timeout)
  1569.                             refreshTimeouts[unitNumber].running = !1
  1570.                             document.removeEventListener('scroll', refreshTimeouts[unitNumber].listeners)
  1571.                             window.removeEventListener('resize', refreshTimeouts[unitNumber].listeners)
  1572.                             document.removeEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
  1573.                         }
  1574.                     }, plInfo[placementNumber].timeouts.remove - dif)
  1575.                 }
  1576.             }
  1577.         } else {
  1578.             if (timeouts[unitNumber].running && !unitStatus[unitNumber].closed) {
  1579.                 timeouts[unitNumber].running = !1;
  1580.                 timeouts[unitNumber].stopTS = new Date().getTime()
  1581.                 clearTimeout(timeouts[unitNumber].timeout)
  1582.             }
  1583.         }
  1584.     }
  1585. }
Add Comment
Please, Sign In to add comment