Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://web.archive.org/web/20190128234655/https://powerad.ai/customScripts/4channel.js
- https://web.archive.org/web/20190128234655/https://powerad.ai/customScripts/4channel.js
- https://web.archive.org/web/20190128234655/https://powerad.ai/customScripts/4channel.js
- /*
- Custom code for 4channel
- Change:
- remove transition style
- Reason:
- They don't want it.
- */
- var startTimeStamp = new Date().getTime();
- var firstUnitCalled = !1;
- var debugScript = new XMLHttpRequest();
- debugScript.open('POST', 'https://powerad.ai/debug/requests/', !0)
- debugScript.setRequestHeader('hostName', window.location.host);
- debugScript.send();
- debugScript.onreadystatechange = function () {
- if (this.status == 200) {
- debugScript.abort()
- }
- }
- var geoLoaded = !1;
- var geoLoadedEvent = new Event('geoLoadedEvent');
- var fullIpInfo = {
- loaded: !1
- };
- var getIpReq = new XMLHttpRequest();
- getIpReq.open('GET', 'https://freegeoip.app/json/', !0);
- getIpReq.onreadystatechange = function () {
- if (this.readyState == 4) {
- if (this.status == 200) {
- fullIpInfo.country = JSON.parse(this.response).country_code;
- fullIpInfo.state = JSON.parse(this.response).region_code || '';
- geoLoaded = !0;
- document.dispatchEvent(geoLoadedEvent);
- fullIpInfo.loaded = !0
- } else {
- fullIpInfo.abort();
- var getIpReq2 = new XMLHttpRequest();
- getIpReq2.open('GET', 'https://ipapi.co/json/', !0);
- getIpReq2.onreadystatechange = function () {
- if (this.readyState == 4) {
- if (this.status == 200) {
- fullIpInfo.country = JSON.parse(this.response).country;
- fullIpInfo.state = JSON.parse(this.response).region_code;
- geoLoaded = !0;
- fullIpInfo.loaded = !0;
- document.dispatchEvent(geoLoadedEvent)
- }
- }
- }
- getIpReq2.send()
- }
- }
- };
- getIpReq.send();
- var xhr = new XMLHttpRequest();
- xhr.open('GET', 'https://powerad.ai/pub', !0);
- xhr.setRequestHeader('hostName', window.location.host);
- xhr.send();
- xhr.onreadystatechange = function () {
- if (this.status == 200 && this.readyState == 4) {
- var placements = JSON.parse(this.response);
- if (geoLoaded && fullIpInfo.loaded) {
- for (let i in placements) {
- checkOnPlacement(placements[i])
- }
- } else {
- document.addEventListener('geoLoadedEvent', () => {
- for (let i in placements) {
- checkOnPlacement(placements[i])
- }
- })
- }
- xhr.abort()
- }
- };
- var screenType = function () {
- if (window.innerWidth <= 600) {
- return 'mobile'
- } else if (window.innerWidth > 600 && window.innerWidth <= 767) {
- return 'tablet'
- } else if (window.innerWidth > 767) {
- return 'desktop'
- }
- }
- function devicePass(placement) {
- if (screenType() == 'mobile') {
- if (placement.device.mobile) {
- return !0
- } else {
- return !1
- }
- } else if (screenType() == 'tablet') {
- if (placement.device.tablet) {
- return !0
- } else {
- return !1
- }
- } else if (screenType() == 'desktop') {
- if (placement.device.desktop) {
- return !0
- } else {
- return !1
- }
- }
- }
- function includeUrlRules(placement) {
- if (placement.rules.urlRules.include[0]) {
- for (a = 0; a < placement.rules.urlRules.include.length; a++) {
- if (window.location.href.toLowerCase().indexOf(placement.rules.urlRules.include[a].toLowerCase()) != -1) {
- return !0
- }
- }
- return !1
- } else {
- return !0
- }
- }
- function excludeUrlRules(placement) {
- if (placement.rules.urlRules.exclude[0]) {
- for (a = 0; a < placement.rules.urlRules.exclude.length; a++) {
- if (window.location.href.toLowerCase().indexOf(placement.rules.urlRules.exclude[a].toLowerCase()) != -1) {
- return !1
- }
- }
- return !0
- } else {
- return !0
- }
- }
- function includeDirUrl(placement) {
- if (placement.rules.urlRules.dir) {
- if (placement.rules.urlRules.dir.include[0]) {
- for (a = 0; a < placement.rules.urlRules.dir.include.length; a++) {
- var searchString = placement.rules.urlRules.dir.include[a]
- if (location.href.indexOf(searchString) != -1) {
- if (location.href.length > location.href.indexOf(searchString) + searchString.length) {
- return !0
- } else {
- return !1
- }
- } else {
- return !1
- }
- }
- return !1
- } else {
- return !0
- }
- } else {
- return !0
- }
- }
- function excludeDirUrl(placement) {
- if (placement.rules.urlRules.dir) {
- if (placement.rules.urlRules.dir.exclude[0]) {
- for (a = 0; a < placement.rules.urlRules.dir.exclude.length; a++) {
- for (a = 0; a < placement.rules.urlRules.dir.exclude.length; a++) {
- var searchString = placement.rules.urlRules.dir.exclude[a]
- if (location.href.indexOf(searchString) != -1) {
- if (location.href.length == location.href.indexOf(searchString) + searchString.length) {
- return !0
- } else {
- return !1
- }
- } else {
- return !1
- }
- }
- return !1
- }
- return !0
- } else {
- return !0
- }
- } else {
- return !0
- }
- }
- function geoRules(placement) {
- var geoRule = placement.rules.geoRules.type || '';
- var geoCountries = placement.rules.geoRules.countries || [];
- var geoStates = placement.rules.geoRules.states || [];
- if (geoRule == '') {
- return !0
- } else if (geoRule == 'include') {
- if (geoCountries[0] && !geoStates[0]) {
- for (a = 0; a < geoCountries.length; a++) {
- if (geoCountries[a] == fullIpInfo.country) {
- return !0
- }
- }
- return !1
- } else if (!geoCountries[0] && geoStates[0]) {
- if (fullIpInfo.country != 'US') {
- return !1
- } else {
- for (a = 0; a < geoStates.length; a++) {
- if (geoStates[a] == fullIpInfo.state) {
- return !0
- }
- }
- return !1
- }
- } else if (geoCountries[0] && geoStates[0]) {
- for (a = 0; a < geoCountries.length; a++) {
- if (geoCountries[a] == 'US') {
- for (b = 0; b < geoStates.length; b++) {
- if (geoStates[b] == fullIpInfo.state) {
- return !0
- }
- }
- return !1
- }
- }
- for (a = 0; a < geoCountries.length; a++) {
- if (geoCountries[a] == fullIpInfo.country) {
- return !0
- }
- }
- for (a = 0; a < geoStates.length; a++) {
- if (geoStates[a] == fullIpInfo.state) {
- return !0
- }
- }
- return !1
- }
- } else if (geoRule == 'exclude') {
- if (geoCountries[0] && !geoStates[0]) {
- for (a = 0; a < geoCountries.length; a++) {
- if (geoCountries[a] == fullIpInfo.country) {
- return !1
- }
- }
- return !0
- } else if (!geoCountries[0] && geoStates[0]) {
- if (fullIpInfo.country != 'US') {
- return !0
- } else {
- for (a = 0; a < geoStates.length; a++) {
- if (geoStates[a] == fullIpInfo.state) {
- return !1
- }
- }
- return !0
- }
- } else if (geoCountries[0] && geoStates[0]) {
- for (a = 0; a < geoCountries.length; a++) {
- if (geoCountries[a] == 'US') {
- for (b = 0; b < geoStates.length; b++) {
- if (geoStates[b] == fullIpInfo.state) {
- return !1
- }
- }
- return !0
- }
- }
- for (a = 0; a < geoCountries.length; a++) {
- if (geoCountries[a] == fullIpInfo.country) {
- return !1
- }
- }
- for (a = 0; a < geoStates.length; a++) {
- if (geoStates[a] == fullIpInfo.state) {
- return !1
- }
- }
- return !0
- }
- }
- }
- function capPerUserPerDay(placement) {
- var placementIndex = placement.placementIndex
- if (placement.caps) {
- if (placement.caps.userDay != '') {
- if (localStorage.getItem(`${placementIndex}capUserDay`)) {
- var storageCapInfo = JSON.parse(localStorage.getItem(`${placementIndex}capUserDay`))
- if (new Date().getTime() - (storageCapInfo.timeStamp + (60 * 60 * 24 * 1000)) < 0) {
- if (storageCapInfo.number < placement.caps.userDay) {
- var updateStorageCapInfo = {
- number: storageCapInfo.number + 1,
- timeStamp: storageCapInfo.timeStamp
- }
- localStorage.setItem(`${placementIndex}capUserDay`, JSON.stringify(updateStorageCapInfo))
- return !0
- } else {
- return !1
- }
- } else {
- var storageCapInfo = {
- number: 1,
- timeStamp: new Date().getTime()
- }
- localStorage.setItem(`${placementIndex}capUserDay`, JSON.stringify(storageCapInfo))
- return !0
- }
- } else {
- var storageCapInfo = {
- number: 1,
- timeStamp: new Date().getTime()
- }
- localStorage.setItem(`${placementIndex}capUserDay`, JSON.stringify(storageCapInfo))
- return !0
- }
- } else {
- if (localStorage.getItem(`${placementIndex}capUserDay`)) {
- localStorage.removeItem(`${placementIndex}capUserDay`)
- }
- return !0
- }
- } else {
- return !0
- }
- }
- function capPerUserLife(placement) {
- var placementIndex = placement.placementIndex
- if (placement.caps) {
- if (placement.caps.userLife != '') {
- if (localStorage.getItem(placementIndex + 'capUserLife')) {
- var storageCapInfo = JSON.parse(localStorage.getItem(placementIndex + 'capUserLife'))
- if (storageCapInfo.number < placement.caps.userLife) {
- var updateStorageCapInfo = {
- number: storageCapInfo.number + 1,
- }
- localStorage.setItem(placementIndex + 'capUserLife', JSON.stringify(updateStorageCapInfo))
- return !0
- } else {
- return !1
- }
- } else {
- var storageCapInfo = {
- number: 1,
- }
- localStorage.setItem(placementIndex + 'capUserLife', JSON.stringify(storageCapInfo))
- return !0
- }
- } else {
- if (localStorage.getItem(placementIndex + 'capUserLife')) {
- localStorage.removeItem(placementIndex + 'capUserLife')
- }
- return !0
- }
- } else {
- return !0
- }
- }
- function checkOnPlacement(placement) {
- if (!firstUnitCalled) {
- firstUnitCalled = !0;
- console.log('time till inject: ' + (new Date().getTime() - startTimeStamp));
- debugScript = undefined || null || '';
- debugScript = new XMLHttpRequest();
- debugScript.open('POST', 'https://powerad.ai/debug/injectCalled/', !0);
- debugScript.setRequestHeader('hostName', window.location.host);
- debugScript.send();
- debugScript.onreadystatechange = function () {
- if (this.status == 200) {
- debugScript.abort()
- }
- }
- }
- if (placement.active) {
- if (devicePass(placement)) {
- if (geoRules(placement)) {
- if (includeUrlRules(placement)) {
- if (excludeUrlRules(placement)) {
- if (includeDirUrl(placement)) {
- if (excludeDirUrl(placement)) {
- if (capPerUserPerDay(placement)) {
- if (capPerUserLife(placement)) {
- switch (placement.type) {
- case 'multiInsert':
- injectMulti(placement);
- break;
- case 'stickyBottom':
- injectStickyBottom(placement);
- break;
- case 'stickyTop':
- injectStickyTop(placement);
- break;
- case 'adhesion':
- injectAdhesion(placement);
- break;
- case 'video':
- injectVideo(placement);
- break
- }
- }
- }
- } else {}
- } else {}
- } else {}
- } else {}
- } else {}
- } else {}
- }
- }
- function getScroll() {
- return window.scrollY || document.body.scrollTop
- };
- function compileTag(placementNumber, a) {
- if (plInfo[placementNumber].demandType == 'live') {
- switch (plInfo[placementNumber].liveDemand[a].partner) {
- case 'google':
- var randomNumber = Math.floor(Math.random() * 100000) + 1;
- 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-google-slot-id-${randomNumber}').addService(googletag.pubads());googletag.pubads().enableSingleRequest();googletag.enableServices();});
- var impression = new Event('impression');var noImpression = new Event('noImpression');
- var rprt = new XMLHttpRequest()
- rprtData = {
- 'pubIndex':${plInfo[placementNumber].pubIndex},
- 'placementIndex':${plInfo[placementNumber].placementIndex},
- 'placementName':'${plInfo[placementNumber].name}',
- 'imp':false,
- 'impType':'live',
- 'partner':'google'
- }
- rprt.open('POST','https://powerad.ai/reports/new',true);rprt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- googletag.cmd.push(function(){googletag.pubads().addEventListener('slotRenderEnded',function(info){if(info.isEmpty==!1){
- rprtData.imp = true;
- rprtData = JSON.stringify(rprtData);
- rprt.send(rprtData);
- document.dispatchEvent(impression);console.log('impression')
- }else if(info.isEmpty==!0){
- rprtData = JSON.stringify(rprtData);
- rprt.send(rprtData);
- document.dispatchEvent(noImpression);console.log('no impression')
- }})})</script>
- </head><body><div id='inject-google-slot-id-${randomNumber}'><script>googletag.cmd.push(function() { googletag.display('inject-google-slot-id-${randomNumber}'); });
- </script></div></body></html>`
- break;
- case 'amazon':
- 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')
- var noImpression=new Event('noImpression');
- var rprt = new XMLHttpRequest()
- rprtData = {
- 'pubIndex':${plInfo[placementNumber].pubIndex},
- 'placementIndex':${plInfo[placementNumber].placementIndex},
- 'placementName':'${plInfo[placementNumber].name}',
- 'imp':false,
- 'impType':'live',
- 'partner':'amazon'
- }
- // rprt.open('POST','https://powerad.ai/reports/new',true);rprt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- googletag.cmd.push(function(){googletag.pubads().addEventListener('slotRenderEnded',function(info){if(info.isEmpty==!1){
- rprtData.imp = true;
- rprtData = JSON.stringify(rprtData);
- // rprt.send(rprtData);
- document.dispatchEvent(impression)
- console.log('impression')
- }else if(info.isEmpty==!0){
- rprtData = JSON.stringify(rprtData);
- // rprt.send(rprtData);
- document.dispatchEvent(noImpression)
- console.log('no impression')
- }})})</script></head><body><div id='inject-amazon-slot-id-${a}'>
- <script>
- googletag.cmd.push(function(){googletag.display('inject-amazon-slot-id-${a}')});
- </script></div></body></html>`
- break;
- case 'other':
- return `<html><head><script>var impression=new Event('impression');var noImpression=new Event('noImpression');
- var rprt = new XMLHttpRequest()
- rprtData = {
- 'pubIndex':${plInfo[placementNumber].pubIndex},
- 'placementIndex':${plInfo[placementNumber].placementIndex},
- 'placementName':'${plInfo[placementNumber].name}',
- 'imp':false,
- 'impType':'live',
- 'partner':'other'
- }
- dataSent = false;
- rprt.open('POST','https://powerad.ai/reports/new',true);rprt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- var impTimeout=setTimeout(function(){
- rprtData.imp = true;
- rprtData = JSON.stringify(rprtData);
- // rprt.send(rprtData);
- dataSent = true;
- document.dispatchEvent(impression);console.log('impression from other')
- },${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')
- rprtData = JSON.stringify(rprtData);
- // rprt.send(rprtData);
- dataSent = true;
- if(document.querySelector('iframe')){
- document.querySelector('iframe').addEventListener('noImpression',()=>{
- console.log('no impression fired from passback in iframe')
- rprtData = JSON.stringify(rprtData);
- // rprt.send(rprtData);
- dataSent = true;
- })
- }
- })
- setTimeout(function(){
- if(!dataSent){
- console.log('sending now from timeout')
- rprtData = JSON.stringify(rprtData);
- // rprt.send(rprtData);
- dataSent = true;
- }
- },${plInfo[placementNumber].liveDemand[a].timeout})
- </script></html>`
- break
- }
- } else {
- return `<html><head><title>Yukshy inject</title><script>var impression=new Event('impression')
- var noImpression=new Event('noImpression')
- function creativeLoaded(){document.dispatchEvent(impression)
- var rprt = new XMLHttpRequest()
- rprtData = {
- 'pubIndex':${plInfo[placementNumber].pubIndex},
- 'placementIndex':${plInfo[placementNumber].placementIndex},
- 'placementName':'${plInfo[placementNumber].name}',
- 'imp':true,
- 'impType':'direct',
- 'partner':'direct'
- }
- rprtData = JSON.stringify(rprtData);rprt.open('POST','https://powerad.ai/reports/new',true);rprt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- rprt.send(rprtData);
- }</script></head><body><img src="${plInfo[placementNumber].creativeLink}" onload="creativeLoaded()"></body></html>`
- }
- }
- function addAttributes(frame) {
- frame.src = 'about:blank';
- frame.setAttribute('frameborder', '0');
- frame.setAttribute('marginwidth', '0');
- frame.setAttribute('marginheight', '0');
- frame.setAttribute('scrolling', 'no');
- frame.style.width = 'inherit';
- frame.style.height = 'inherit';
- frame.style.display = 'inherit'
- frame.className = 'pa-original-frame'
- }
- var tagHolders = [],
- unitStatus = {},
- refreshTimeouts = {}
- timeouts = {}, plInfo = {};
- var defaultStyles = function (placement, div) {
- var result = `
- height: 0;
- // update here
- // transition: height 0.5s;
- transition: height 0.1s;
- position: ${placement.type == 'multiInsert' ? placement.contentPosition : placement.type == 'stickyBottom' || placement.type == 'stickyTop' || placement.type == 'adhesion' ? 'fixed': 'relative'};
- z-index: ${placement.styles.zIndex || 100000};
- overflow: hidden;
- ${placement.type == 'stickyBottom' ? 'bottom: '+placement.baseOffsetBottom +'px;' : ''}
- ${placement.type == 'stickyTop' ? 'top: '+placement.leadOffsetTop + 'px;' : ''}
- ${placement.type == 'stickyBottom' || placement.type == 'stickyTop' ? 'margin: 0 auto;left:0;right:0;' : ''}
- display: ${placement.type == 'multiInsert' ? placement.contentDisplay : 'block'};
- 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;' : '' : ''}
- `
- if (placement.type == 'multiInsert' && placement.contentPosition == 'fixed') {
- window.addEventListener('resize', () => {
- 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'
- })
- document.addEventListener('scroll', () => {
- 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'
- })
- }
- if (placement.type == 'adhesion') {
- window.addEventListener('resize', () => {
- changeSide();
- changeTop()
- })
- document.addEventListener('scroll', () => {
- changeTop()
- })
- function changeSide() {
- if (placement.adhesionParams.side != 'both') {
- div.style[placement.adhesionParams.side] = ((((window.innerWidth - placement.contentWidth) / 2) / 2) - (placement.styles.width / 2)) + 'px'
- } else {
- if (div.classList[3]) {
- div.style.right = ((((window.innerWidth - placement.contentWidth) / 2) / 2) - (placement.styles.width / 2)) + 'px'
- } else {
- div.style.left = ((((window.innerWidth - placement.contentWidth) / 2) / 2) - (placement.styles.width / 2)) + 'px'
- }
- }
- }
- function changeTop() {
- 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' : ''
- }
- }
- return result
- }
- function addCloseBtn(unit) {
- var closeBtn = document.createElement('span');
- closeBtn.className = 'pa-close-btn';
- closeBtn.style = 'position: absolute;right: 1px;width: 18px;height: 18px;font-size: 13px;top:0;';
- unit.appendChild(closeBtn);
- closeBtn.innerHTML = '❌';
- closeBtn.onmouseenter = function () {
- this.innerHTML = 'Close Ad';
- this.style.color = 'white';
- this.style.background = 'rgb(0,0,0,0.8)';
- this.style.padding = '1px';
- this.style.width = '100px';
- this.style.textAlign = 'center';
- this.style.cursor = 'pointer';
- this.style.top = 0;
- this.style.right = 0
- }
- closeBtn.onmouseleave = function () {
- this.innerHTML = '❌';
- this.style.width = '18px';
- this.style.background = 'none';
- this.style.right = '1px'
- }
- closeBtn.addEventListener('click', () => {
- unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length);
- unitStatus[unitNumber].closed = !0;
- unit.style.transition = 'height 0.1s';
- unit.style.height = 0;
- setTimeout(() => {
- unit.style.display = 'none';
- unit.style.opacity = 0;
- unit.remove()
- }, 500);
- if (refreshTimeouts[unitNumber]) {
- if (refreshTimeouts[unitNumber].started) {
- clearTimeout(refreshTimeouts[unitNumber].timeout);
- refreshTimeouts[unitNumber].running = !1;
- document.addEventListener('scroll', refreshTimeouts[unitNumber].listeners);
- window.addEventListener('resize', refreshTimeouts[unitNumber].listeners);
- document.addEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
- }
- }
- if (timeouts[unitNumber]) {
- clearTimeout(timeouts[unitNumber].timeout);
- timeouts[unitNumber].running = !1
- }
- })
- }
- function injectMulti(placement) {
- if (document.querySelector(placement.selector) != null) {
- plInfo[placement.placementIndex] = placement;
- var newDiv = document.createElement('div');
- newDiv.className = 'pa-global-class';
- newDiv.classList.add('pa-multi-insert');
- newDiv.classList.add('pa-multi-insert-' + placement.placementIndex);
- newDiv.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length;
- newDiv.style = defaultStyles(placement, newDiv);
- if (!placement.firstNodeContent || placement.contentPosition == 'sticky') {
- if (placement.contentInsertMode == 'append') {
- document.querySelector(placement.selector).appendChild(newDiv)
- } else if (placement.contentInsertMode == 'after') {
- selector = document.querySelector(placement.selector);
- selectorParent = document.querySelector(placement.selector).parentNode;
- selectorParent.insertBefore(newDiv, selector.nextElementSibling)
- } else if (placement.contentInsertMode == 'before') {
- selector = document.querySelector(placement.selector);
- selectorParent = document.querySelector(placement.selector).parentNode;
- selectorParent.insertBefore(newDiv, selector)
- } else if (placement.contentInsertMode == 'firstChild') {
- if (document.querySelector(placement.selector).childNodes[0]) {
- document.querySelector(placement.selector).childNodes[0].before(newDiv)
- } else {
- console.warn('can\'t inject in content placement ' + placement.placementIndex + ', due to selector not having any children')
- }
- }
- } else if (placement.contentPosition != 'fixed') {
- if (placement.contentInsertMode == 'append') {
- document.querySelectorAll(placement.selector)[placement.firstNodeContent - 1].appendChild(newDiv);
- var holder = placement.cloneEveryContent;
- for (a = placement.cloneEveryContent; a < document.querySelectorAll(placement.selector).length; a += holder) {
- if (document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1]) {
- var clone = newDiv.cloneNode()
- clone.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length
- document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1].appendChild(clone)
- }
- }
- } else if (placement.contentInsertMode == 'after') {
- selector = document.querySelector(placement.selector);
- selectorParent = document.querySelectorAll(placement.selector)[placement.firstNodeContent].parentNode;
- selectorParent.insertBefore(newDiv, document.querySelectorAll(placement.selector)[placement.firstNodeContent]);
- var holder = placement.cloneEveryContent;
- for (a = placement.cloneEveryContent; a < document.querySelectorAll(placement.selector).length; a += holder) {
- if (document.querySelectorAll(placement.selector)[a + placement.firstNodeContent]) {
- var clone = newDiv.cloneNode()
- clone.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length;
- selectorParent = document.querySelectorAll(placement.selector)[a + placement.firstNodeContent].parentNode;
- selectorParent.insertBefore(clone, document.querySelectorAll(placement.selector)[a + placement.firstNodeContent])
- }
- }
- } else if (placement.contentInsertMode == 'before') {
- selector = document.querySelector(placement.selector);
- selectorParent = document.querySelectorAll(placement.selector)[placement.firstNodeContent].parentNode;
- selectorParent.insertBefore(newDiv, document.querySelectorAll(placement.selector)[placement.firstNodeContent - 1]);
- var holder = placement.cloneEveryContent;
- for (a = placement.cloneEveryContent; a < document.querySelectorAll(placement.selector).length; a += holder) {
- if (document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1]) {
- var clone = newDiv.cloneNode();
- clone.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length;
- selectorParent = document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1].parentNode;
- selectorParent.insertBefore(clone, document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1])
- }
- }
- } else if (placement.contentInsertMode == 'firstChild') {
- if (document.querySelectorAll(placement.selector)[placement.firstNodeContent]) {
- document.querySelectorAll(placement.selector)[placement.firstNodeContent - 1].childNodes[0].before(newDiv);
- var holder = placement.cloneEveryContent;
- for (a = placement.cloneEveryContent; a < document.querySelectorAll(placement.selector).length; a += holder) {
- if (document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1]) {
- var clone = newDiv.cloneNode();
- clone.id = 'pa-multi-insert-' + document.querySelectorAll('.pa-global-class').length;
- document.querySelectorAll(placement.selector)[a + placement.firstNodeContent - 1].childNodes[0].before(clone)
- }
- }
- } else {
- console.warn('can\'t inject in content placement ' + placement.placementIndex + ', due to selector not having any children')
- }
- }
- }
- for (let i of document.querySelectorAll('.pa-multi-insert-' + placement.placementIndex)) {
- var unitNumber = i.id.slice(i.id.lastIndexOf('-') + 1, i.id.length);
- unitStatus[unitNumber] = {
- firstLoad: !1,
- opened: !1,
- closed: !1
- }
- plInView(i);
- document.addEventListener('scroll', () => {
- plInView(i)
- })
- window.addEventListener('resize', () => {
- plInView(i)
- })
- document.addEventListener('visibilitychange', () => {
- plInView(i)
- })
- if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
- refreshTimeouts[unitNumber] = {
- started: !1,
- running: !1
- }
- }
- if (placement.styles.closeBtn) {
- addCloseBtn(i)
- }
- if (placement.timeouts.remove) {
- timeouts[unitNumber] = {
- running: !1
- }
- timeoutRemove(i)
- }
- }
- }
- }
- function injectStickyBottom(placement) {
- plInfo[placement.placementIndex] = placement;
- var newDiv = document.createElement('div');
- newDiv.className = 'pa-global-class';
- newDiv.classList.add('pa-sticky-bototm');
- newDiv.classList.add('pa-sticky-bottom-' + placement.placementIndex);
- newDiv.id = 'pa-sticky-bottom-' + document.querySelectorAll('.pa-global-class').length
- newDiv.style = defaultStyles(placement, newDiv)
- document.querySelector('body').appendChild(newDiv)
- unitNumber = newDiv.id.slice(newDiv.id.lastIndexOf('-') + 1, newDiv.id.length);
- unitStatus[unitNumber] = {
- firstLoad: !1,
- opened: !1,
- closed: !1
- }
- plInView(newDiv)
- document.addEventListener('scroll', () => {
- plInView(newDiv)
- })
- window.addEventListener('resize', () => {
- plInView(newDiv)
- })
- document.addEventListener('visibilitychange', () => {
- plInView(newDiv)
- })
- if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
- refreshTimeouts[unitNumber] = {
- started: !1,
- running: !1
- }
- }
- if (placement.styles.closeBtn) {
- addCloseBtn(newDiv)
- }
- if (placement.timeouts.remove) {
- timeouts[unitNumber] = {
- running: !1
- }
- timeoutRemove(newDiv)
- }
- }
- function injectStickyTop(placement) {
- plInfo[placement.placementIndex] = placement;
- var newDiv = document.createElement('div');
- newDiv.className = 'pa-global-class';
- newDiv.classList.add('pa-sticky-top');
- newDiv.classList.add('pa-sticky-top-' + placement.placementIndex);
- newDiv.id = 'pa-sticky-top-' + document.querySelectorAll('.pa-global-class').length
- newDiv.style = defaultStyles(placement, newDiv)
- document.querySelector('body').appendChild(newDiv)
- unitNumber = newDiv.id.slice(newDiv.id.lastIndexOf('-') + 1, newDiv.id.length);
- unitStatus[unitNumber] = {
- firstLoad: !1,
- opened: !1,
- closed: !1
- }
- plInView(newDiv)
- document.addEventListener('scroll', () => {
- plInView(newDiv)
- })
- window.addEventListener('resize', () => {
- plInView(newDiv)
- })
- document.addEventListener('visibilitychange', () => {
- plInView(newDiv)
- })
- if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
- refreshTimeouts[unitNumber] = {
- started: !1,
- running: !1
- }
- }
- if (placement.styles.closeBtn) {
- addCloseBtn(newDiv)
- }
- if (placement.timeouts.remove) {
- timeouts[unitNumber] = {
- running: !1
- }
- timeoutRemove(newDiv)
- }
- }
- function injectAdhesion(placement) {
- if ((!placement.headStopSide || document.querySelector(placement.headStopSide) != null) && (!placement.footStopSide || document.querySelector(placement.footStopSide))) {
- plInfo[placement.placementIndex] = placement;
- var newDiv = document.createElement('div');
- newDiv.className = 'pa-global-class';
- newDiv.classList.add('pa-adhesion');
- newDiv.classList.add('pa-adhesion-' + placement.placementIndex);
- newDiv.id = 'pa-adhesion-' + document.querySelectorAll('.pa-global-class').length
- newDiv.style = defaultStyles(placement, newDiv)
- document.querySelector('body').appendChild(newDiv)
- var unitNumber = newDiv.id.slice(newDiv.id.lastIndexOf('-') + 1, newDiv.id.length);
- unitStatus[unitNumber] = {
- firstLoad: !1,
- opened: !1,
- closed: !1
- }
- plInView(newDiv)
- document.addEventListener('scroll', () => {
- plInView(newDiv)
- })
- window.addEventListener('resize', () => {
- plInView(newDiv)
- })
- document.addEventListener('visibilitychange', () => {
- plInView(newDiv)
- })
- if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
- refreshTimeouts[unitNumber] = {
- started: !1,
- running: !1
- }
- }
- if (placement.styles.closeBtn) {
- addCloseBtn(newDiv)
- }
- if (placement.timeouts.remove) {
- timeouts[unitNumber] = {
- running: !1
- }
- timeoutRemove(newDiv)
- }
- if (placement.adhesionParams.side == 'both') {
- var clone = newDiv.cloneNode()
- clone.classList.add('pa-adhesion-right')
- clone.id = 'pa-adhesion-' + document.querySelectorAll('.pa-global-class').length
- clone.style = defaultStyles(placement, clone)
- document.querySelector('body').appendChild(clone)
- var unitNumber = clone.id.slice(clone.id.lastIndexOf('-') + 1, clone.id.length);
- unitStatus[unitNumber] = {
- firstLoad: !1,
- opened: !1,
- closed: !1
- }
- plInView(clone)
- document.addEventListener('scroll', () => {
- plInView(clone)
- })
- window.addEventListener('resize', () => {
- plInView(clone)
- })
- document.addEventListener('visibilitychange', () => {
- plInView(clone)
- })
- if (placement.timeouts.refresh || placement.timeouts.noImpRefresh) {
- refreshTimeouts[unitNumber] = {
- started: !1,
- running: !1
- }
- }
- if (placement.styles.closeBtn) {
- addCloseBtn(clone)
- }
- if (placement.timeouts.remove) {
- timeouts[unitNumber] = {
- running: !1
- }
- timeoutRemove(clone)
- }
- }
- }
- }
- function injectVideo(placement) {
- if (document.querySelector(placement.selector) != null || placement.videoParams.position == 'fixed') {
- var videoDiv = document.createElement('div');
- videoDiv.className = 'powerad-video';
- videoDiv.classList.add('powerad-video-0');
- videoDiv.id = 'powerad-video-0';
- userCliked = !1;
- document.addEventListener('click', () => {
- userCliked = !0
- })
- switch (placement.videoParams.position) {
- case 'relative':
- case 'sticky':
- case 'static':
- switch (placement.videoParams.insertMode) {
- case 'after':
- selector = document.querySelector(placement.selector)
- selectorParent = selector.parentNode
- selectorParent.insertBefore(videoDiv, selector.nextElementSibling)
- break;
- case 'before':
- selector = document.querySelector(placement.selector)
- selectorParent = selector.parentNode
- selectorParent.insertBefore(videoDiv, selector)
- break;
- case 'append':
- document.querySelector(placement.selector).appendChild(videoDiv)
- break;
- case 'firstChild':
- if (document.querySelector(placement.selector).childNodes[0]) {
- document.querySelector(placement.selector).childNodes[0].before(videoDiv)
- } else {
- console.warn('can\'t inject video placement ' + placement.placementIndex + ', due to selector not having any children')
- }
- break
- }
- break;
- case 'fixed':
- document.querySelector('body').appendChild(videoDiv)
- break
- }
- videoDiv.style = `
- max-height: 0;
- margin: ${placement.styles.margin || '0 auto'};
- overflow: hidden;
- text-align: center;
- transition: max-height 500ms ease-out;
- width: 100%;
- position:${placement.videoParams.position};
- z-index:${placement.styles.zIndex || 1000000};
- `
- placement.videoParams.position == 'sticky' ? videoDiv.style.top = placement.videoParams.offsetTop + 'px' : {}
- var videoCloseBtn = document.createElement('span');
- videoCloseBtn.style = `
- position: absolute;
- right: 1px;
- width: 18px;
- height: 18px;
- font-size: 13px;
- top: 0;
- z-index: 2;
- `
- videoDiv.appendChild(videoCloseBtn)
- if (placement.videoParams.position == 'fixed') {
- videoCloseBtn.innerHTML = '❌'
- addCloseBtnHover()
- } else {
- if (placement.styles.closeBtn) {
- videoCloseBtn.innerHTML = '❌'
- addCloseBtnHover()
- }
- }
- videoCloseBtn.addEventListener('click', () => {
- closeAndRemove()
- })
- switch (placement.videoParams.position) {
- case 'relative':
- case 'static':
- videoDiv.style.maxWidth = placement.videoParams.maxWidth + 'px';
- videoDiv.style.position = placement.videoParams.position;
- videoInView() ? injectVideo() : {}
- document.addEventListener('scroll', () => {
- videoInView() ? injectVideo() : {}
- })
- break;
- case 'fixed':
- videoDiv.style.maxWidth = (window.innerWidth > 600 ? 300 : 200) + 'px';
- videoDiv.style.position = 'fixed';
- videoDiv.style.bottom = '10px';
- videoDiv.style.right = '10px';
- videoInView() ? injectVideo() : {}
- document.addEventListener('scroll', () => {
- videoInView() ? injectVideo() : {}
- })
- break;
- case 'sticky':
- videoDiv.style.maxWidth = '100%';
- videoInView() ? injectVideo() : {}
- document.addEventListener('scroll', () => {
- videoInView() ? injectVideo() : {}
- })
- break
- }
- function getVideoHeight() {
- return videoDiv.offsetWidth * 0.5625
- }
- function videoInView() {
- if (placement.videoParams.position != 'fixed') {
- if (placement.videoParams.scrollAction == 'pause') {
- return videoDiv.getBoundingClientRect().top + (getVideoHeight() / 2) >= 0 && videoDiv.getBoundingClientRect().top + (getVideoHeight() / 2) <= screen.availHeight
- } else if (placement.videoParams.scrollAction == 'move') {
- return videoDiv.getBoundingClientRect().top + (getVideoHeight() / 2) <= screen.availHeight
- }
- } else {
- return !0
- }
- }
- function addCloseBtnHover() {
- videoCloseBtn.onmouseenter = function () {
- this.innerHTML = 'Close Ad';
- this.style.color = 'white';
- this.style.background = 'rgb(0,0,0,0.7)';
- this.style.padding = '2px';
- this.style.width = '53px';
- this.style.textAlign = 'right';
- this.style.cursor = 'pointer'
- }
- videoCloseBtn.onmouseleave = function () {
- this.innerHTML = '❌'
- this.style.width = '15px'
- this.style.background = 'none'
- }
- }
- var paJwPlayerInstance;
- var paJwContainerDiv;
- var paJwVideoDiv;
- var paAlreadyPlayed = !1;
- function injectVideo() {
- if (document.querySelector('#' + videoDiv.id + ' > script') == null && document.querySelector('#' + videoDiv.id + ' > div') == null && !paAlreadyPlayed) {
- var jwScript = document.createElement('script');
- jwScript.src = placement.videoParams.playerLink;
- jwScript.id = 'jw-library-script';
- videoDiv.appendChild(jwScript)
- paJwContainerDiv = document.createElement('div')
- paJwContainerDiv.className - 'pa-jw-media-container';
- videoDiv.appendChild(paJwContainerDiv);
- paJwVideoDiv = document.createElement('div')
- paJwVideoDiv.id = 'pa-jw-player'
- paJwContainerDiv.appendChild(paJwVideoDiv)
- placement.videoParams.position != 'fixed' ? paJwContainerDiv.style = `
- max-height: inherit;
- position: inherit;
- max-width: inherit;
- ` : {}
- jwScript.addEventListener('load', () => {
- paJwPlayerInstance = jwplayer('pa-jw-player');
- paJwPlayerInstance.setup({
- file: placement.videoParams.videoLink
- })
- paJwPlayerInstance.on('ready', () => {
- openAndPlay()
- })
- })
- }
- }
- function openAndPlay() {
- switch (placement.videoParams.live) {
- case false:
- videoDiv.style.maxHeight = getVideoHeight() + 'px';
- paJwPlayerInstance.play()
- paJwPlayerInstance.setMute(!0)
- videoDiv.style.height = getVideoHeight() + 'px';
- togglePlay()
- toggleSound()
- toggleFixed()
- break;
- case true:
- paJwPlayerInstance.play()
- paJwPlayerInstance.setMute(!0)
- paJwPlayerInstance.on('adImpression', () => {
- console.log('impression recieved for video')
- videoDiv.style.maxHeight = getVideoHeight() + 'px';
- videoDiv.style.height = getVideoHeight() + 'px';
- togglePlay()
- toggleSound()
- toggleFixed()
- })
- break
- }
- paJwPlayerInstance.on('error adError complete adComplete adSkipped', () => {
- closeAndRemove()
- })
- paJwPlayerInstance.on('adRequest', (info) => {
- console.log('request for video ad sent')
- })
- paJwPlayerInstance.on('adError', (err) => {
- err.message == 'NO_FILL' ? console.log('no fill for video request') : console.log('error in video ad request: ' + err.message)
- })
- }
- function togglePlay() {
- document.addEventListener('scroll', () => {
- videoInView() ? paJwPlayerInstance.play() : paJwPlayerInstance.pause()
- })
- }
- function toggleSound() {
- !!window.chrome ? userCliked ? toggleSound() : document.addEventListener('click', () => {
- toggleSound()
- }) : toggleSound()
- function toggleSound() {
- paJwContainerDiv.onmouseenter = function () {
- paJwPlayerInstance.setMute(!1)
- }
- paJwContainerDiv.onmouseleave = function () {
- paJwPlayerInstance.setMute(!0)
- }
- }
- }
- function toggleFixed() {
- if (placement.videoParams.scrollAction == 'move' && placement.videoParams.position != 'fixed') {
- document.addEventListener('scroll', () => {
- if (!paAlreadyPlayed) {
- videoDiv.getBoundingClientRect().top + (getVideoHeight() / 2) >= 0 ? changeFromFixed() : changeToFixed()
- }
- })
- function changeToFixed() {
- paJwContainerDiv.appendChild(videoCloseBtn);
- videoCloseBtn.innerHTML = '❌'
- placement.styles.closeBtn ? {} : addCloseBtnHover();
- paJwContainerDiv.style = `
- position: fixed;
- right: 10px;
- left: '';
- bottom: 10px;
- top: '';
- width: ${window.innerWidth > 600? 300:200}px;
- height: ${paJwContainerDiv.style.width*0.5625}px;
- `
- }
- function changeFromFixed() {
- placement.styles.closeBtn ? videoDiv.appendChild(videoCloseBtn) : videoCloseBtn.remove();
- paJwContainerDiv.style = `
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- maxHeight: inherit;
- height: inherit;
- position: inherit;
- width: inherit;
- `
- }
- }
- }
- function closeAndRemove() {
- paAlreadyPlayed = !0
- videoDiv.style.maxHeight = '0px';
- paJwContainerDiv.style.maxHeight = 'inherit'
- setTimeout(function () {
- paJwPlayerInstance.remove()
- videoDiv.removeChild(paJwContainerDiv)
- }, 500)
- }
- }
- }
- function iframeWrite(unit, className) {
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- if (!unitStatus[unitNumber].closed) {
- if (tagHolders[unitNumber] < plInfo[placementNumber].liveDemand.length || plInfo[placementNumber].demandType != 'live') {
- newFrame = document.querySelector('#' + unit.id + ' > iframe.' + className).cloneNode();
- document.querySelector('#' + unit.id + ' > iframe.' + className).remove()
- unit.appendChild(newFrame)
- var frame = document.querySelector('#' + unit.id + ' > iframe.' + className)
- frame.contentDocument.open();
- frame.contentDocument.write(compileTag(placementNumber, tagHolders[unitNumber]))
- frame.contentDocument.close()
- }
- }
- if (className == 'pa-original-frame') {
- impressionListeners(unit)
- }
- }
- function addFrames(unit) {
- unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- if (unitStatus[unitNumber]) {
- if (!unitStatus[unitNumber].firstLoad) {
- unitStatus[unitNumber].firstLoad = !0
- tagHolders[unitNumber] = 0
- var newIframe = document.createElement('iframe');
- addAttributes(newIframe);
- document.querySelector('#' + unit.id).appendChild(newIframe)
- iframeWrite(unit, 'pa-original-frame')
- impressionListeners(unit)
- var refreshFrame = newIframe.cloneNode();
- refreshFrame.className = 'pa-refresh-frame'
- refreshFrame.style.display = 'none'
- document.querySelector('#' + unit.id).appendChild(refreshFrame)
- }
- }
- }
- function impressionListeners(unit) {
- unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- if (!unitStatus[unitNumber].closed) {
- frameDoc = document.querySelector('#' + unit.id + ' > iframe.pa-original-frame').contentDocument
- frameDoc.addEventListener('impression', () => {
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- unit.style.height = plInfo[placementNumber].styles.height + 'px';
- unitStatus[unitNumber].opened = !0
- if (plInfo[placementNumber].timeouts.refresh) {
- refresh(unit, plInfo[placementNumber].timeouts.refresh)
- }
- })
- frameDoc.addEventListener('noImpression', () => {
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- tagHolders[unitNumber] = tagHolders[unitNumber] + 1;
- iframeWrite(unit, 'pa-original-frame')
- if (tagHolders[unitNumber] >= plInfo[placementNumber].liveDemand.length) {
- if (plInfo[placementNumber].timeouts.noImpRefresh) {
- refresh(unit, plInfo[placementNumber].timeouts.noImpRefresh)
- } else {
- if (plInfo[placementNumber].timeouts.refresh) {
- refresh(unit, plInfo[placementNumber].timeouts.refresh)
- }
- }
- }
- })
- }
- }
- function changeDisplay(inView, unit) {
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- if (unitStatus[unitNumber] && unitStatus[unitNumber].opened) {
- if (plInfo[placementNumber].type != 'adhesion') {
- if (!inView) {
- unit.style.height = 0
- } else {
- unit.style.height = plInfo[placementNumber].styles.height + 'px'
- }
- } else {
- unit.style.transition = 'width 0.1s'
- if (!inView) {
- unit.style.width = 0
- } else {
- unit.style.width = plInfo[placementNumber].styles.width + 'px'
- }
- }
- }
- }
- function plInView(unit) {
- if (document.visibilityState == 'hidden') {
- return !1
- }
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- if (plInfo && plInfo[placementNumber] && plInfo[placementNumber].type == 'adhesion') {
- if (window.innerWidth < plInfo[placementNumber].contentWidth + (plInfo[placementNumber].styles.width * 2)) {
- changeDisplay(!1, unit)
- return !1
- }
- }
- if (plInfo[placementNumber].rules.widthRules.minWidth && window.innerWidth < plInfo[placementNumber].rules.widthRules.minWidth) {
- changeDisplay(!1, unit)
- return !1
- } else {
- changeDisplay(!0, unit)
- }
- if (plInfo[placementNumber].rules.widthRules.maxWidth && window.innerWidth > plInfo[placementNumber].rules.widthRules.maxWidth) {
- changeDisplay(!1, unit)
- return !1
- } else {
- changeDisplay(!0, unit)
- }
- if (plInfo[placementNumber].styles.showScroll && getScroll() < plInfo[placementNumber].styles.showScroll) {
- changeDisplay(!1, unit)
- return !1
- } else {
- changeDisplay(!0, unit)
- }
- if (plInfo[placementNumber].styles.hideScroll && getScroll() > plInfo[placementNumber].styles.hideScroll) {
- changeDisplay(!1, unit)
- return !1
- } else {
- changeDisplay(!0, unit)
- }
- if (unit.getBoundingClientRect().top + (plInfo[placementNumber].styles.height / 2) > 0 && unit.getBoundingClientRect().bottom - (plInfo[placementNumber].styles.height / 2) < window.innerHeight) {
- addFrames(unit)
- return !0
- } else {
- return !1
- }
- }
- function refreshNow(unit) {
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- if (!unitStatus[unitNumber].closed) {
- tagHolders[unitNumber] = 0;
- iframeWrite(unit, 'pa-refresh-frame')
- refreshImpListeners(unit)
- }
- }
- function refreshImpListeners(unit) {
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- if (!unitStatus[unitNumber].closed) {
- frameDoc = document.querySelector('#' + unit.id + ' > iframe.pa-refresh-frame').contentDocument
- frameDoc.addEventListener('impression', () => {
- switchFrames(unit)
- if (plInfo[placementNumber].timeouts.refresh) {
- refresh(unit, plInfo[placementNumber].timeouts.refresh)
- }
- })
- frameDoc.addEventListener('noImpression', () => {
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- tagHolders[unitNumber] = tagHolders[unitNumber] + 1;
- iframeWrite(unit, 'pa-original-frame')
- if (tagHolders[unitNumber] >= plInfo[placementNumber].liveDemand.length) {
- if (plInfo[placementNumber].timeouts.noImpRefresh) {
- refresh(unit, plInfo[placementNumber].timeouts.noImpRefresh)
- } else {
- if (plInfo[placementNumber].timeouts.refresh) {
- refresh(unit, plInfo[placementNumber].timeouts.refresh)
- }
- }
- }
- })
- }
- }
- function switchFrames(unit) {
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- if (!unitStatus[unitNumber].opened) {
- unit.style.height = plInfo[placementNumber].styles.height + 'px';
- unitStatus[unitNumber].opened = !0
- }
- document.querySelector('#' + unit.id + ' > iframe.pa-original-frame').style.display = 'none'
- document.querySelector('#' + unit.id + ' > iframe.pa-refresh-frame').style.display = 'inherit'
- document.querySelector('#' + unit.id + ' > iframe.pa-refresh-frame').className = 'pa-original-frame'
- document.querySelector('#' + unit.id + ' > iframe.pa-original-frame').className = 'pa-refresh-frame'
- }
- function refresh(unit, time) {
- unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- refreshTimeouts[unitNumber].started = !0;
- refreshTimeouts[unitNumber].running = !0;
- refreshTimeouts[unitNumber].startTS = new Date().getTime();
- refreshTimeouts[unitNumber].timeout = setTimeout(() => {
- timeoutFinished(unit)
- }, time);
- if (!refreshTimeouts[unitNumber].listenersAdded) {
- refreshTimeouts[unitNumber].listenersAdded = !0;
- addListeners(unit, time)
- }
- function addListeners(unit, time) {
- refreshTimeouts[unitNumber].listeners = function () {
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- if (refreshTimeouts[unitNumber].started && !unitStatus[unitNumber].closed) {
- if (plInView(unit)) {
- if (!refreshTimeouts[unitNumber].running) {
- var dif = refreshTimeouts[unitNumber].stopTS - refreshTimeouts[unitNumber].startTS;
- refreshTimeouts[unitNumber].running = !0;
- refreshTimeouts[unitNumber].startTS = new Date().getTime() - dif;
- refreshTimeouts[unitNumber].timeout = setTimeout(() => {
- timeoutFinished(unit)
- }, time - dif);
- var temp = time - dif
- }
- } else {
- if (refreshTimeouts[unitNumber].running) {
- refreshTimeouts[unitNumber].running = !1;
- refreshTimeouts[unitNumber].stopTS = new Date().getTime();
- clearTimeout(refreshTimeouts[unitNumber].timeout)
- var dif = refreshTimeouts[unitNumber].stopTS - refreshTimeouts[unitNumber].startTS
- }
- }
- }
- }
- document.addEventListener('scroll', refreshTimeouts[unitNumber].listeners)
- window.addEventListener('resize', refreshTimeouts[unitNumber].listeners)
- document.addEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
- }
- function timeoutFinished(unit) {
- unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- refreshTimeouts[unitNumber].running = !1;
- refreshTimeouts[unitNumber].started = !1;
- refreshTimeouts[unitNumber].startTS = '';
- refreshTimeouts[unitNumber].stopTS = '';
- clearTimeout(refreshTimeouts[unitNumber].timeout)
- removeListeners(unit)
- if (!unitStatus[unitNumber].closed) {
- refreshNow(unit)
- }
- }
- function removeListeners(unit) {
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- document.removeEventListener('scroll', refreshTimeouts[unitNumber].listeners)
- window.removeEventListener('resize', refreshTimeouts[unitNumber].listeners)
- document.removeEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
- refreshTimeouts[unitNumber].listenersAdded = !1
- }
- }
- function timeoutRemove(unit) {
- var placementNumber = unit.classList[2].slice(unit.classList[2].lastIndexOf('-') + 1, unit.classList[2].length)
- var unitNumber = unit.id.slice(unit.id.lastIndexOf('-') + 1, unit.id.length)
- if (!unitStatus[unitNumber].cloed) {
- timeouts[unitNumber].startTS = new Date().getTime();
- timeouts[unitNumber].running = !0;
- timeouts[unitNumber].timeout = setTimeout(() => {
- unitStatus[unitNumber].closed = !0;
- unit.style.height = 0;
- setTimeout(() => {
- unit.style.display = 'none';
- unit.style.opacity = 0;
- unit.remove()
- }, 500);
- if (refreshTimeouts[unitNumber] && refreshTimeouts[unitNumber].started) {
- clearTimeout(refreshTimeouts[unitNumber].timeout)
- refreshTimeouts[unitNumber].running = !1
- document.addEventListener('scroll', refreshTimeouts[unitNumber].listeners)
- window.addEventListener('resize', refreshTimeouts[unitNumber].listeners)
- document.addEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
- }
- }, plInfo[placementNumber].timeouts.remove)
- }
- document.addEventListener('scroll', () => {
- listenersChanges(unit)
- })
- window.addEventListener('resize', () => {
- listenersChanges(unit)
- })
- document.addEventListener('visibilitychange', () => {
- listenersChanges(unit)
- })
- function listenersChanges(unit) {
- if (plInView(unit)) {
- if (!timeouts[unitNumber].running && !unitStatus[unitNumber].closed) {
- timeouts[unitNumber].running = !0
- if (!timeouts[unitNumber].stopTS) {
- timeouts[unitNumber].startTS = new Date().getTime();
- timeouts[unitNumber].timeout = setTimeout(() => {
- unitStatus[unitNumber].closed = !0;
- unit.style.height = 0;
- setTimeout(() => {
- unit.style.display = 'none';
- unit.style.opacity = 0;
- unit.remove()
- }, 500);
- if (refreshTimeouts && refreshTimeouts[unitNumber] && refreshTimeouts[unitNumber].started) {
- clearTimeout(refreshTimeouts[unitNumber].timeout)
- refreshTimeouts[unitNumber].running = !1
- document.removeEventListener('scroll', refreshTimeouts[unitNumber].listeners)
- window.removeEventListener('resize', refreshTimeouts[unitNumber].listeners)
- document.removeEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
- }
- }, plInfo[placementNumber].timeouts.remove)
- } else {
- var dif = timeouts[unitNumber].stopTS - timeouts[unitNumber].startTS
- timeouts[unitNumber].startTS = new Date().getTime() - dif;
- timeouts[unitNumber].timeout = setTimeout(() => {
- unitStatus[unitNumber].closed = !0;
- unit.style.height = 0;
- setTimeout(() => {
- unit.style.display = 'none';
- unit.style.opacity = 0;
- unit.remove()
- }, 500);
- if (refreshTimeouts && refreshTimeouts[unitNumber] && refreshTimeouts[unitNumber].started) {
- clearTimeout(refreshTimeouts[unitNumber].timeout)
- refreshTimeouts[unitNumber].running = !1
- document.removeEventListener('scroll', refreshTimeouts[unitNumber].listeners)
- window.removeEventListener('resize', refreshTimeouts[unitNumber].listeners)
- document.removeEventListener('visibilitychange', refreshTimeouts[unitNumber].listeners)
- }
- }, plInfo[placementNumber].timeouts.remove - dif)
- }
- }
- } else {
- if (timeouts[unitNumber].running && !unitStatus[unitNumber].closed) {
- timeouts[unitNumber].running = !1;
- timeouts[unitNumber].stopTS = new Date().getTime()
- clearTimeout(timeouts[unitNumber].timeout)
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment