Last active
April 14, 2020 19:47
-
-
Save nachovz/e649d2de2e078846d1f3cdd52438b9df to your computer and use it in GitHub Desktop.
Inyección de ads en infinite scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(document.querySelector(".text-editor") || {}).className += ' ndg_inject'; | |
document.addEventListener('ndg:infinitescroll', function(e){ | |
(document.querySelectorAll(".text-editor") || []).forEach(function(art){ | |
if(!art.className.includes("ndg_inject") && art.hasChildNodes()){ | |
var eachChild = art.firstChild; | |
var cont = true; | |
var counter = 1; | |
while(cont){ | |
if(eachChild.nodeName === "P"){ | |
if(counter % 3 === 0){ | |
googletag.cmd.push(function() { | |
var slot = googletag.defineSlot('/57869717/NewDream/Box1', [300, 250]) | |
.setTargeting('test', 'infinitescroll') | |
.addService(googletag.pubads()); | |
var adUnit = document.createElement('div'); | |
adUnit.id = slot.getSlotElementId(); | |
adUnit.setAttribute('style','width:300px;height:250px;overflow:hidden;'); | |
eachChild.parentNode.insertBefore(adUnit, eachChild.nextElementSibling); | |
googletag.display(slot); | |
googletag.pubads().refresh([slot]); | |
}); | |
} | |
counter++; | |
} | |
if(!!eachChild.nextElementSibling){ | |
eachChild = eachChild.nextElementSibling; | |
}else{ | |
cont=false; | |
} | |
} | |
art.className += " ndg_inject"; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment