You are leaving AARP.org and going to the website of our trusted provider. The provider’s terms, conditions and policies apply. Please return to AARP.org to learn more about other benefits.
Got it! Please don't show me this again for 90 days.
Thank You
Your email address is now confirmed.
Manage your email preferences and tell us which topics interest you so that we can prioritize the information you receive.
Explore all that AARP has to offer.
Thank You, Vets! In Honor of Veterans Day, Receive Up to 30% Off Membership. Learn More
NoneNoneNone// ===============================================
// AdBlock detector
//
// Attempts to detect the presence of Ad Blocker software
// and notify listener of its existence.
// Copyright (c) 2015 IAB
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ===============================================
/**
* @name window.adblockDetector
*
* IAB Adblock detector.
* Usage: window.adblockDetector.init(options);
*
* Options object settings
*
* @prop debug: boolean
* Flag to indicate additional debug output should be printed to console
*
* @prop found: @function
* Callback function to fire if adblock is detected
*
* @prop notfound: @function
* Callback function to fire if adblock is not detected.
* NOTE: this function may fire multiple times and give false negative
* responses during a test until adblock is successfully detected.
*
* @prop complete: @function
* Callback function to fire once a round of testing is complete.
* The test result (boolean) is included as a parameter to callback
*
* example: window.adblockDetector.init(
{
found: function(){ ...},
notFound: function(){...}
}
);
*
*
*/
"use strict";
(function(win) {
var version = '1.0';
var ofs = 'offset',
cl = 'client';
var noop = function() {};
var testedOnce = false;
var testExecuting = false;
var isOldIEevents = (win.addEventListener === undefined);
/**
* Options set with default options initialized
*
*/
var _options = {
loopDelay: 50,
maxLoop: 5,
debug: true,
found: noop, // function to fire when adblock detected
notfound: noop, // function to fire if adblock not detected after testing
complete: noop // function to fire after testing completes, passing result as parameter
}
function parseAsJson(data) {
var result, fnData;
try {
result = JSON.parse(data);
} catch (ex) {
try {
fnData = new Function("return " + data);
result = fnData();
} catch (ex) {
log('Failed secondary JSON parse', true);
}
}
return result;
}
/**
* Ajax helper object to download external scripts.
* Initialize object with an options object
* Ex:
{
url : 'http://example.org/url_to_download',
method: 'POST|GET',
success: callback_function,
fail: callback_function
}
*/
var AjaxHelper = function(opts) {
var xhr = new XMLHttpRequest();
this.success = opts.success || noop;
this.fail = opts.fail || noop;
var me = this;
var method = opts.method || 'get';
/**
* Abort the request
*/
this.abort = function() {
try {
xhr.abort();
} catch (ex) {}
}
function stateChange(vals) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
me.success(xhr.response);
} else {
// failed
me.fail(xhr.status);
}
}
}
xhr.onreadystatechange = stateChange;
function start() {
xhr.open(method, opts.url, true);
xhr.send();
}
start();
}
/**
* Object tracking the various block lists
*/
var BlockListTracker = function() {
var me = this;
var externalBlocklistData = {};
/**
* Add a new external URL to track
*/
this.addUrl = function(url) {
externalBlocklistData[url] = {
url: url,
state: 'pending',
format: null,
data: null,
result: null
}
return externalBlocklistData[url];
}
/**
* Loads a block list definition
*/
this.setResult = function(urlKey, state, data) {
var obj = externalBlocklistData[urlKey];
if (obj == null) {
obj = this.addUrl(urlKey);
}
obj.state = state;
if (data == null) {
obj.result = null;
return;
}
if (typeof data === 'string') {
try {
data = parseAsJson(data);
obj.format = 'json';
} catch (ex) {
obj.format = 'easylist';
// parseEasyList(data);
}
}
obj.data = data;
return obj;
}
}
var listeners = []; // event response listeners
var baitNode = null;
var quickBait = {
cssClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links'
};
var baitTriggers = {
nullProps: [ofs + 'Parent'],
zeroProps: []
};
baitTriggers.zeroProps = [
ofs + 'Height', ofs + 'Left', ofs + 'Top', ofs + 'Width', ofs +
'Height',
cl + 'Height', cl + 'Width'
];
// result object
var exeResult = {
quick: null,
remote: null
};
var findResult = null; // result of test for ad blocker
var timerIds = {
test: 0,
download: 0
};
function isFunc(fn) {
return typeof(fn) == 'function';
}
/**
* Make a DOM element
*/
function makeEl(tag, attributes) {
var k, v, el, attr = attributes;
var d = document;
el = d.createElement(tag);
if (attr) {
for (k in attr) {
if (attr.hasOwnProperty(k)) {
el.setAttribute(k, attr[k]);
}
}
}
return el;
}
function attachEventListener(dom, eventName, handler) {
if (isOldIEevents) {
dom.attachEvent('on' + eventName, handler);
} else {
dom.addEventListener(eventName, handler, false);
}
}
function log(message, isError) {
if (!_options.debug && !isError) {
return;
}
if (win.console && win.console.log) {
if (isError) {
console.error('[ABD] ' + message);
} else {
console.log('[ABD] ' + message);
}
}
}
var ajaxDownloads = [];
/**
* Load and execute the URL inside a closure function
*/
function loadExecuteUrl(url) {
var ajax, result;
blockLists.addUrl(url);
// setup call for remote list
ajax = new AjaxHelper({
url: url,
success: function(data) {
log('downloaded file ' + url); // todo - parse and store until use
result = blockLists.setResult(url,
'success', data);
try {
var intervalId = 0,
retryCount = 0;
var tryExecuteTest = function(listData) {
if (!testExecuting) {
beginTest(listData, true);
return true;
}
return false;
}
if (findResult == true) {
return;
}
if (tryExecuteTest(result.data)) {
return;
} else {
log('Pause before test execution');
intervalId = setInterval(function() {
if (tryExecuteTest(
result.data) ||
retryCount++ > 5) {
clearInterval(
intervalId);
}
}, 250);
}
} catch (ex) {
log(ex.message + ' url: ' + url, true);
}
},
fail: function(status) {
log(status, true);
blockLists.setResult(url, 'error', null);
}
});
ajaxDownloads.push(ajax);
}
/**
* Fetch the external lists and initiate the tests
*/
function fetchRemoteLists() {
var i, url;
var opts = _options;
for (i = 0; i