ExoDetector.detectCensorship(function(adBlockIsOn){
new_var = adBlockIsOn;
});
alert(window.new_var); // return undefined
Возвращает undefined вместо true,false
Код функции
var ExoDetector = {
domain_base: "exosrv.com",
detectCensorship: function(onComplete)
{
var testDomEl = document.createElement('iframe'),
randomNum = Math.floor(Math.random() * (10000 - 123 + 1)) + 123,
protocol = window.location.protocol,
id = 'adsbox_ex_' + randomNum,
block = false;
testDomEl.setAttribute('height', "1px");
testDomEl.setAttribute('width', "1px");
testDomEl.setAttribute('id', id);
testDomEl.setAttribute('class', 'adsBox pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links');
testDomEl.setAttribute('style', "width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important; box-sizing: content-box !important; border-width: 0px !important;");
var testScript = document.createElement('script');
testScript.src = protocol + "//ads." + ExoDetector.domain_base + "/ads.js";
testScript.onerror = function() {
block = true;
};
document.body.appendChild(testDomEl);
document.head.appendChild(testScript);
var done = function () {
if (typeof onComplete == 'function') {
onComplete(block);
}
document.body.removeChild(testDomEl);
};
var domDetect = function () {
try {
var someAd = document.getElementById(id);
if (someAd === null
|| someAd.style.display == "none"
|| someAd.style.display == "hidden"
|| someAd.style.visibility == "hidden"
|| someAd.offsetParent === null
|| someAd.offsetHeight == 0
|| someAd.offsetLeft == 0
|| someAd.offsetTop == 0
|| someAd.offsetWidth == 0
|| someAd.clientHeight == 0
|| someAd.clientWidth == 0
) {
block = true;
}
if (window.getComputedStyle !== undefined) {
var style = window.getComputedStyle(someAd, null);
if(style && (style.getPropertyValue('display') == 'none' || style.getPropertyValue('visibility') == 'hidden')) {
block = true;
}
}
} catch (err) {
}
};
setTimeout(domDetect, 500);
setTimeout(done, 550);
}
};