Created
October 6, 2015 09:24
-
-
Save stuwilli/b3a799a18537026aa170 to your computer and use it in GitHub Desktop.
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
(function() { | |
function getFrame() { | |
if (!document.getElementById('akami-research-frame')) { | |
var iframe = document.createElement('iframe'); | |
iframe.id = 'akami-research-frame'; | |
iframe.src = 'about:blank'; | |
iframe.style.width = '1px'; | |
iframe.style.height = '1px'; | |
iframe.style.border = 'none'; | |
document.body.appendChild(iframe); | |
} | |
return document.getElementById('akami-research-frame'); | |
} | |
function silenceConsole(context) { | |
context.console = (context.console = context.console || {}); | |
for (var k in context.console) { | |
context.console[k] = function() {}; | |
} | |
} | |
function checkFreewheel(callback) { | |
var script = document.createElement('script'); | |
script.src = '//adm.fwmrm.net/p/release/latest-JS/adm/prd/AdManager.js'; | |
script.onload = function() { | |
//IE doesn't fire onerror when a script is blocked, so we need to check for ad manager | |
if ('ActiveXObject' in window) { | |
if (getFrame().contentWindow._fw_admanager !== undefined) { | |
callback(false); | |
} else { | |
callback(true); | |
} | |
} else { | |
callback(false); | |
} | |
}; | |
script.onerror = function() { | |
callback(true); | |
}; | |
//Stop iframe console messages | |
silenceConsole(getFrame().contentWindow); | |
//Need to load linkTag inside an iframe so we don't reinitialize it in the parent window | |
getFrame().contentDocument.body.appendChild(script); | |
} | |
function renderPixel(url) { | |
var img = document.createElement('img'); | |
img.src = url; | |
img.width = 1; | |
img.height = 1; | |
img.style.display = 'none'; | |
img.className = 'akamiResearch'; | |
document.body.appendChild(img); | |
} | |
try { | |
//Test if Freewheel is blocked | |
checkFreewheel(function(result) { | |
if (result) { | |
//ad blocking is enabled | |
renderPixel('http://static.dnitv.com/'+ location.hostname +'/option1/true'); | |
} else { | |
//no ad blocker detected | |
renderPixel('http://static.dnitv.com/'+ location.hostname +'/option1/false'); | |
} | |
return; | |
}); | |
} catch (e) {} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment