Hello everyone,
First off, its my first time posting here, so I apologize if I break any forum rules.
Now, I am trying to make an injector to append Adsense units into any website using javascript. My idea was to have a chrome extension that runs at document_start, and append Adsense with this code:
Either way, it doesn't work. Do you have any ideas on how to inject Adsense? Or is this a fool's errand?
Thank you for any help!
Note: I am aware this is against Adsense ToS. I do not intend to misuse this code :)
First off, its my first time posting here, so I apologize if I break any forum rules.
Now, I am trying to make an injector to append Adsense units into any website using javascript. My idea was to have a chrome extension that runs at document_start, and append Adsense with this code:
Code
function injectTortugaAds (pubID, adSlot)
{
var actualCode = '(adsbygoogle = window.adsbygoogle || []).push({google_ad_client: "ca-pub-' + pubID + '", enable_page_level_ads: true});';
var script = document.createElement('script');
script.textContent = actualCode;
(document.head || document.documentElement).appendChild(script);
//------------------------------------------------------------
var externalScript = document.createElement("script");
externalScript.type = "text/javascript";
externalScript.setAttribute('async', 'async');
externalScript.src = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
document.getElementsByTagName('body')[0].appendChild(externalScript);
var ins = document.createElement("ins");
ins.setAttribute('class', 'adsbygoogle');
ins.setAttribute('style', 'display:block;');/*add other styles if required*/
ins.setAttribute('data-ad-client', 'ca-pub-' + pubID);
ins.setAttribute('data-ad-slot', adSlot);
ins.setAttribute('data-ad-format', 'auto');
document.getElementsByTagName('body')[0].appendChild(ins);
var inlineScript = document.createElement("script");
inlineScript.type = "text/javascript";
inlineScript.text = '(adsbygoogle = window.adsbygoogle || []).push({});'
document.getElementsByTagName('body')[0].appendChild(inlineScript);
//--------------------------------------------------------------
[].forEach.call(document.querySelectorAll('.adsbygoogle'), function () {
(adsbygoogle = window.adsbygoogle || []).push({});
});
}Thank you for any help!
Note: I am aware this is against Adsense ToS. I do not intend to misuse this code :)

