|
|
@ -1,28 +1,28 @@
|
|
|
|
'use strict'
|
|
|
|
'use strict'
|
|
|
|
;(function (win) {
|
|
|
|
;(function (win) {
|
|
|
|
var exports = {}
|
|
|
|
const exports = {}
|
|
|
|
|
|
|
|
|
|
|
|
;(function (exports) {
|
|
|
|
;(function (exports) {
|
|
|
|
var utils = {
|
|
|
|
const utils = {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Normalize URL
|
|
|
|
* Normalize URL
|
|
|
|
* @param {String} url
|
|
|
|
* @param {String} url
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
normalizeUrl: function(url) {
|
|
|
|
normalizeUrl(url) {
|
|
|
|
return this.hashUrl(url) || null
|
|
|
|
return this.hashUrl(url) || null
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get referrer.
|
|
|
|
* Get referrer.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getReferrer: function() {
|
|
|
|
getReferrer() {
|
|
|
|
return this.normalizeUrl(document.referrer)
|
|
|
|
return this.normalizeUrl(document.referrer)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get current page URL.
|
|
|
|
* Get current page URL.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getPageUrl: function() {
|
|
|
|
getPageUrl() {
|
|
|
|
return this.normalizeUrl(window.location.href)
|
|
|
|
return this.normalizeUrl(window.location.href)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -30,8 +30,8 @@
|
|
|
|
* Generated hashed URL.
|
|
|
|
* Generated hashed URL.
|
|
|
|
* @param {String} url
|
|
|
|
* @param {String} url
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
hashUrl: function(url) {
|
|
|
|
hashUrl(url) {
|
|
|
|
var a, result
|
|
|
|
let a, result
|
|
|
|
|
|
|
|
|
|
|
|
if (!url || url.indexOf('http') !== 0) {
|
|
|
|
if (!url || url.indexOf('http') !== 0) {
|
|
|
|
return null
|
|
|
|
return null
|
|
|
@ -61,10 +61,10 @@
|
|
|
|
* Generate random hash.
|
|
|
|
* Generate random hash.
|
|
|
|
* @param {String} str
|
|
|
|
* @param {String} str
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
hashCode: function(str) {
|
|
|
|
hashCode(str) {
|
|
|
|
var hash = 0,
|
|
|
|
let hash = 0
|
|
|
|
kar,
|
|
|
|
let kar
|
|
|
|
i
|
|
|
|
let i
|
|
|
|
|
|
|
|
|
|
|
|
if (str.length === 0) {
|
|
|
|
if (str.length === 0) {
|
|
|
|
return hash
|
|
|
|
return hash
|
|
|
@ -83,7 +83,7 @@
|
|
|
|
* Apply array function to non-array.
|
|
|
|
* Apply array function to non-array.
|
|
|
|
* @param {Object} a
|
|
|
|
* @param {Object} a
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
realArray: function(a) {
|
|
|
|
realArray(a) {
|
|
|
|
return Array.prototype.slice.apply(a)
|
|
|
|
return Array.prototype.slice.apply(a)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -92,7 +92,7 @@
|
|
|
|
* @param {Object} doc
|
|
|
|
* @param {Object} doc
|
|
|
|
* @param {Function} callback
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onDocLoaded: function(doc, callback) {
|
|
|
|
onDocLoaded(doc, callback) {
|
|
|
|
if (doc.readyState === 'loading') {
|
|
|
|
if (doc.readyState === 'loading') {
|
|
|
|
doc.addEventListener('DOMContentLoaded', callback)
|
|
|
|
doc.addEventListener('DOMContentLoaded', callback)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -106,8 +106,8 @@
|
|
|
|
* Check for href Window object.
|
|
|
|
* Check for href Window object.
|
|
|
|
* @param {Object} win
|
|
|
|
* @param {Object} win
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
isFriendlyWindow: function(win) {
|
|
|
|
isFriendlyWindow(win) {
|
|
|
|
var href
|
|
|
|
let href
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
href = win.location.href
|
|
|
|
href = win.location.href
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
@ -120,7 +120,7 @@
|
|
|
|
* Get default view from element.
|
|
|
|
* Get default view from element.
|
|
|
|
* @param {Object} el
|
|
|
|
* @param {Object} el
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
elementWindow: function(el) {
|
|
|
|
elementWindow(el) {
|
|
|
|
return el.ownerDocument.defaultView
|
|
|
|
return el.ownerDocument.defaultView
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -128,7 +128,7 @@
|
|
|
|
* Get viewport size.
|
|
|
|
* Get viewport size.
|
|
|
|
* @param {Object} win
|
|
|
|
* @param {Object} win
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
viewport: function(win) {
|
|
|
|
viewport(win) {
|
|
|
|
return { width: win.innerWidth, height: win.innerHeight }
|
|
|
|
return { width: win.innerWidth, height: win.innerHeight }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -136,12 +136,12 @@
|
|
|
|
* Parse query string parameters.
|
|
|
|
* Parse query string parameters.
|
|
|
|
* @param {String} qs
|
|
|
|
* @param {String} qs
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
parseQS: function(qs) {
|
|
|
|
parseQS(qs) {
|
|
|
|
if (qs.indexOf('http') === 0) {
|
|
|
|
if (qs.indexOf('http') === 0) {
|
|
|
|
qs = qs.split('?')[1]
|
|
|
|
qs = qs.split('?')[1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var i, kvs, key, val
|
|
|
|
let i, kvs, key, val
|
|
|
|
var dict = {}
|
|
|
|
const dict = {}
|
|
|
|
qs = qs.split('&')
|
|
|
|
qs = qs.split('&')
|
|
|
|
for (i = 0; i < qs.length; i++) {
|
|
|
|
for (i = 0; i < qs.length; i++) {
|
|
|
|
kvs = qs[i].split('=')
|
|
|
|
kvs = qs[i].split('=')
|
|
|
@ -162,7 +162,7 @@
|
|
|
|
* @param {String} event
|
|
|
|
* @param {String} event
|
|
|
|
* @param {String} responseMessage
|
|
|
|
* @param {String} responseMessage
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
sendToBackground: function(message, event, responseMessage) {
|
|
|
|
sendToBackground(message, event, responseMessage) {
|
|
|
|
chrome.runtime.sendMessage(message, (message) => {
|
|
|
|
chrome.runtime.sendMessage(message, (message) => {
|
|
|
|
if (message && typeof message.tracking_enabled !== 'undefined') {
|
|
|
|
if (message && typeof message.tracking_enabled !== 'undefined') {
|
|
|
|
if (message.tracking_enabled) {
|
|
|
|
if (message.tracking_enabled) {
|
|
|
@ -180,7 +180,7 @@
|
|
|
|
* @param {Function} elseCallback
|
|
|
|
* @param {Function} elseCallback
|
|
|
|
* @todo validate if utilCallback or utilElseCallback are being used.
|
|
|
|
* @todo validate if utilCallback or utilElseCallback are being used.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
askIfTrackingEnabled: function(callback, elseCallback) {
|
|
|
|
askIfTrackingEnabled(callback, elseCallback) {
|
|
|
|
utilCallback = callback
|
|
|
|
utilCallback = callback
|
|
|
|
utilElseCallback = elseCallback
|
|
|
|
utilElseCallback = elseCallback
|
|
|
|
|
|
|
|
|
|
|
@ -189,7 +189,7 @@
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'tracking_enabled_response'
|
|
|
|
'tracking_enabled_response'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
utils.SCRIPT_IN_FRIENDLY_IFRAME =
|
|
|
|
utils.SCRIPT_IN_FRIENDLY_IFRAME =
|
|
|
@ -207,7 +207,7 @@
|
|
|
|
isHP: window.location.pathname === '/',
|
|
|
|
isHP: window.location.pathname === '/',
|
|
|
|
referrer: utils.getReferrer(),
|
|
|
|
referrer: utils.getReferrer(),
|
|
|
|
rand: Math.floor(Math.random() * 10e12),
|
|
|
|
rand: Math.floor(Math.random() * 10e12),
|
|
|
|
startTime: new Date().getTime()
|
|
|
|
startTime: new Date().getTime(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -218,8 +218,8 @@
|
|
|
|
* @param {Array} opt_assets
|
|
|
|
* @param {Array} opt_assets
|
|
|
|
* @param {Array} opt_pageTags
|
|
|
|
* @param {Array} opt_pageTags
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
log: function(event, opt_assets, opt_pageTags) {
|
|
|
|
log(event, opt_assets, opt_pageTags) {
|
|
|
|
var opt_video_assets
|
|
|
|
let opt_video_assets
|
|
|
|
if (event === 'video' || event === 'invalid-video') {
|
|
|
|
if (event === 'video' || event === 'invalid-video') {
|
|
|
|
opt_video_assets = opt_assets || []
|
|
|
|
opt_video_assets = opt_assets || []
|
|
|
|
opt_assets = []
|
|
|
|
opt_assets = []
|
|
|
@ -227,9 +227,9 @@
|
|
|
|
opt_video_assets = []
|
|
|
|
opt_video_assets = []
|
|
|
|
opt_assets = opt_assets || []
|
|
|
|
opt_assets = opt_assets || []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var result = {
|
|
|
|
const result = {
|
|
|
|
doc: this.pageMeta,
|
|
|
|
doc: this.pageMeta,
|
|
|
|
event: event,
|
|
|
|
event,
|
|
|
|
video_assets: opt_video_assets,
|
|
|
|
video_assets: opt_video_assets,
|
|
|
|
assets: opt_assets,
|
|
|
|
assets: opt_assets,
|
|
|
|
version: '3',
|
|
|
|
version: '3',
|
|
|
@ -238,11 +238,11 @@
|
|
|
|
timestamp: new Date().getTime(),
|
|
|
|
timestamp: new Date().getTime(),
|
|
|
|
pageVis: document.visibilityState,
|
|
|
|
pageVis: document.visibilityState,
|
|
|
|
pageFoc: document.hasFocus(),
|
|
|
|
pageFoc: document.hasFocus(),
|
|
|
|
pageTags: opt_pageTags || []
|
|
|
|
pageTags: opt_pageTags || [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.msgNum++
|
|
|
|
this.msgNum++
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
utils.LogGenerator = LogGenerator
|
|
|
|
utils.LogGenerator = LogGenerator
|
|
|
@ -252,7 +252,7 @@
|
|
|
|
exports.utils = utils
|
|
|
|
exports.utils = utils
|
|
|
|
})(exports)
|
|
|
|
})(exports)
|
|
|
|
;(function (exports) {
|
|
|
|
;(function (exports) {
|
|
|
|
var SizeMatcher = {
|
|
|
|
const SizeMatcher = {
|
|
|
|
VALID_AD_SIZES: [
|
|
|
|
VALID_AD_SIZES: [
|
|
|
|
[300, 50],
|
|
|
|
[300, 50],
|
|
|
|
[320, 50],
|
|
|
|
[320, 50],
|
|
|
@ -272,7 +272,7 @@
|
|
|
|
[970, 250],
|
|
|
|
[970, 250],
|
|
|
|
[970, 400],
|
|
|
|
[970, 400],
|
|
|
|
[970, 415],
|
|
|
|
[970, 415],
|
|
|
|
[1280, 100]
|
|
|
|
[1280, 100],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
PX_SIZE_TOL: 10,
|
|
|
|
PX_SIZE_TOL: 10,
|
|
|
@ -282,7 +282,7 @@
|
|
|
|
* @param {Int} width
|
|
|
|
* @param {Int} width
|
|
|
|
* @param {Int} height
|
|
|
|
* @param {Int} height
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getMatchedAdSize: function(width, height) {
|
|
|
|
getMatchedAdSize(width, height) {
|
|
|
|
if (!this.set) {
|
|
|
|
if (!this.set) {
|
|
|
|
this.set = this._makeSizeSet()
|
|
|
|
this.set = this._makeSizeSet()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -294,7 +294,7 @@
|
|
|
|
* Check element size.
|
|
|
|
* Check element size.
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
elementIsAdShaped: function(el) {
|
|
|
|
elementIsAdShaped(el) {
|
|
|
|
return !!this.getMatchedAdSizeForElement(el)
|
|
|
|
return !!this.getMatchedAdSizeForElement(el)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -303,22 +303,22 @@
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @todo better description
|
|
|
|
* @todo better description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getMatchedAdSizeForElement: function(el) {
|
|
|
|
getMatchedAdSizeForElement(el) {
|
|
|
|
var rect = el.getBoundingClientRect()
|
|
|
|
const rect = el.getBoundingClientRect()
|
|
|
|
return this.getMatchedAdSize(rect.width, rect.height)
|
|
|
|
return this.getMatchedAdSize(rect.width, rect.height)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Generate ad sizes.
|
|
|
|
* Generate ad sizes.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
_makeSizeSet: function() {
|
|
|
|
_makeSizeSet() {
|
|
|
|
var set = {}
|
|
|
|
const set = {}
|
|
|
|
var i
|
|
|
|
let i
|
|
|
|
var xfuz
|
|
|
|
let xfuz
|
|
|
|
var yfuz
|
|
|
|
let yfuz
|
|
|
|
var size
|
|
|
|
let size
|
|
|
|
var width
|
|
|
|
let width
|
|
|
|
var height
|
|
|
|
let height
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < this.VALID_AD_SIZES.length; i++) {
|
|
|
|
for (i = 0; i < this.VALID_AD_SIZES.length; i++) {
|
|
|
|
for (xfuz = -this.PX_SIZE_TOL; xfuz <= this.PX_SIZE_TOL; xfuz++) {
|
|
|
|
for (xfuz = -this.PX_SIZE_TOL; xfuz <= this.PX_SIZE_TOL; xfuz++) {
|
|
|
@ -331,10 +331,10 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return set
|
|
|
|
return set
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var Throttler = {
|
|
|
|
const Throttler = {
|
|
|
|
MAX_SEARCHES_PER_WINDOW: 10,
|
|
|
|
MAX_SEARCHES_PER_WINDOW: 10,
|
|
|
|
MAX_SEARCHES_PER_ELEMENT: 2,
|
|
|
|
MAX_SEARCHES_PER_ELEMENT: 2,
|
|
|
|
|
|
|
|
|
|
|
@ -357,7 +357,7 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
throttle: function(el, max) {
|
|
|
|
throttle(el, max) {
|
|
|
|
if (typeof el.searches === 'number' && el.searches >= max) {
|
|
|
|
if (typeof el.searches === 'number' && el.searches >= max) {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -370,7 +370,7 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
throttleElement: function(el) {
|
|
|
|
throttleElement(el) {
|
|
|
|
return this.throttle(el, this.MAX_SEARCHES_PER_ELEMENT)
|
|
|
|
return this.throttle(el, this.MAX_SEARCHES_PER_ELEMENT)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -380,7 +380,7 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
throttleWin: function(win) {
|
|
|
|
throttleWin(win) {
|
|
|
|
return this.throttle(win, this.MAX_SEARCHES_PER_WINDOW)
|
|
|
|
return this.throttle(win, this.MAX_SEARCHES_PER_WINDOW)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -390,9 +390,9 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getCount: function(el) {
|
|
|
|
getCount(el) {
|
|
|
|
return el.searches || 0
|
|
|
|
return el.searches || 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -408,11 +408,11 @@
|
|
|
|
* Add search function.
|
|
|
|
* Add search function.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
TopSearcher.prototype.search = function () {
|
|
|
|
TopSearcher.prototype.search = function () {
|
|
|
|
var candidates = exports.utils.realArray(
|
|
|
|
const candidates = exports.utils.realArray(
|
|
|
|
this.doc.querySelectorAll('img, object, embed')
|
|
|
|
this.doc.querySelectorAll('img, object, embed')
|
|
|
|
),
|
|
|
|
)
|
|
|
|
html5Ad,
|
|
|
|
let html5Ad
|
|
|
|
ads = []
|
|
|
|
let ads = []
|
|
|
|
|
|
|
|
|
|
|
|
ads = ads.concat(
|
|
|
|
ads = ads.concat(
|
|
|
|
candidates.filter(function (el) {
|
|
|
|
candidates.filter(function (el) {
|
|
|
@ -444,11 +444,11 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
TopSearcher.prototype._mainGetHTMLAd = function () {
|
|
|
|
TopSearcher.prototype._mainGetHTMLAd = function () {
|
|
|
|
var styles = this.doc.querySelectorAll(
|
|
|
|
const styles = this.doc.querySelectorAll(
|
|
|
|
'div > style, div > link[rel="stylesheet"]'
|
|
|
|
'div > style, div > link[rel="stylesheet"]'
|
|
|
|
),
|
|
|
|
)
|
|
|
|
i,
|
|
|
|
let i
|
|
|
|
div
|
|
|
|
let div
|
|
|
|
for (i = 0; i < styles.length; i++) {
|
|
|
|
for (i = 0; i < styles.length; i++) {
|
|
|
|
div = styles[i].parentNode
|
|
|
|
div = styles[i].parentNode
|
|
|
|
if (
|
|
|
|
if (
|
|
|
@ -465,7 +465,7 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
TopSearcher.prototype._jumpedOut = function (el) {
|
|
|
|
TopSearcher.prototype._jumpedOut = function (el) {
|
|
|
|
var siblings, ifrs
|
|
|
|
let siblings, ifrs
|
|
|
|
siblings = exports.utils.realArray(el.parentNode.children)
|
|
|
|
siblings = exports.utils.realArray(el.parentNode.children)
|
|
|
|
ifrs = siblings.filter(function (el) {
|
|
|
|
ifrs = siblings.filter(function (el) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
@ -516,7 +516,7 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
IframeSearcher.prototype.search = function () {
|
|
|
|
IframeSearcher.prototype.search = function () {
|
|
|
|
var ad
|
|
|
|
let ad
|
|
|
|
|
|
|
|
|
|
|
|
if (this.shouldSearchWindow) {
|
|
|
|
if (this.shouldSearchWindow) {
|
|
|
|
ad = this._search()
|
|
|
|
ad = this._search()
|
|
|
@ -535,11 +535,11 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
IframeSearcher.prototype._search = function () {
|
|
|
|
IframeSearcher.prototype._search = function () {
|
|
|
|
var _this = this,
|
|
|
|
const _this = this
|
|
|
|
stdCandidates,
|
|
|
|
let stdCandidates
|
|
|
|
html5Candidates,
|
|
|
|
let html5Candidates
|
|
|
|
stdEl,
|
|
|
|
let stdEl
|
|
|
|
html5El
|
|
|
|
let html5El
|
|
|
|
|
|
|
|
|
|
|
|
stdCandidates = this.body.querySelectorAll('img, object, embed')
|
|
|
|
stdCandidates = this.body.querySelectorAll('img, object, embed')
|
|
|
|
|
|
|
|
|
|
|
@ -612,8 +612,8 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
IframeSearcher.prototype._elementIsAtLeastAsBigAsWindow = function (el) {
|
|
|
|
IframeSearcher.prototype._elementIsAtLeastAsBigAsWindow = function (el) {
|
|
|
|
var rect = el.getBoundingClientRect(),
|
|
|
|
const rect = el.getBoundingClientRect()
|
|
|
|
tol = 0.95
|
|
|
|
const tol = 0.95
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
rect.width >= tol * this.winWidth && rect.height >= tol * this.winHeight
|
|
|
|
rect.width >= tol * this.winWidth && rect.height >= tol * this.winHeight
|
|
|
@ -631,9 +631,9 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
IframeSearcher.prototype._containsLargeIframes = function () {
|
|
|
|
IframeSearcher.prototype._containsLargeIframes = function () {
|
|
|
|
var iframes = this.doc.querySelectorAll('iframe')
|
|
|
|
const iframes = this.doc.querySelectorAll('iframe')
|
|
|
|
var rect
|
|
|
|
let rect
|
|
|
|
var i
|
|
|
|
let i
|
|
|
|
for (i = 0; i < iframes.length; i++) {
|
|
|
|
for (i = 0; i < iframes.length; i++) {
|
|
|
|
rect = iframes[i].getBoundingClientRect()
|
|
|
|
rect = iframes[i].getBoundingClientRect()
|
|
|
|
if (
|
|
|
|
if (
|
|
|
@ -650,7 +650,7 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
IframeSearcher.prototype._getAdSizeMeta = function () {
|
|
|
|
IframeSearcher.prototype._getAdSizeMeta = function () {
|
|
|
|
var adSizeMeta = this.doc.querySelectorAll('meta[name="ad.size"]')
|
|
|
|
const adSizeMeta = this.doc.querySelectorAll('meta[name="ad.size"]')
|
|
|
|
if (adSizeMeta.length > 0) {
|
|
|
|
if (adSizeMeta.length > 0) {
|
|
|
|
return adSizeMeta[0].content
|
|
|
|
return adSizeMeta[0].content
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -666,7 +666,7 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getFirst(arr, testFn) {
|
|
|
|
function getFirst(arr, testFn) {
|
|
|
|
var i, el
|
|
|
|
let i, el
|
|
|
|
for (i = 0; i < arr.length; i++) {
|
|
|
|
for (i = 0; i < arr.length; i++) {
|
|
|
|
el = arr[i]
|
|
|
|
el = arr[i]
|
|
|
|
if (testFn(el)) {
|
|
|
|
if (testFn(el)) {
|
|
|
@ -692,9 +692,9 @@
|
|
|
|
* @param {Object} win
|
|
|
|
* @param {Object} win
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getFriendlyIframes(win) {
|
|
|
|
function getFriendlyIframes(win) {
|
|
|
|
var iframes = win.document.querySelectorAll('iframe')
|
|
|
|
let iframes = win.document.querySelectorAll('iframe')
|
|
|
|
iframes = exports.utils.realArray(iframes)
|
|
|
|
iframes = exports.utils.realArray(iframes)
|
|
|
|
var friendlyIframes = iframes.filter(function(ifr) {
|
|
|
|
const friendlyIframes = iframes.filter(function (ifr) {
|
|
|
|
return exports.utils.isFriendlyWindow(ifr.contentWindow)
|
|
|
|
return exports.utils.isFriendlyWindow(ifr.contentWindow)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return friendlyIframes
|
|
|
|
return friendlyIframes
|
|
|
@ -705,11 +705,11 @@
|
|
|
|
* @param {*} win
|
|
|
|
* @param {*} win
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function findAds(win) {
|
|
|
|
function findAds(win) {
|
|
|
|
var i,
|
|
|
|
let i
|
|
|
|
iframes,
|
|
|
|
let iframes
|
|
|
|
searcher,
|
|
|
|
let searcher
|
|
|
|
ad,
|
|
|
|
let ad
|
|
|
|
ads = []
|
|
|
|
let ads = []
|
|
|
|
|
|
|
|
|
|
|
|
if (win === win.top) {
|
|
|
|
if (win === win.top) {
|
|
|
|
searcher = new TopSearcher(win)
|
|
|
|
searcher = new TopSearcher(win)
|
|
|
@ -732,16 +732,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
exports.adfinder = {
|
|
|
|
exports.adfinder = {
|
|
|
|
getMatchedAdSize: SizeMatcher.getMatchedAdSize.bind(SizeMatcher),
|
|
|
|
getMatchedAdSize: SizeMatcher.getMatchedAdSize.bind(SizeMatcher),
|
|
|
|
findAds: findAds
|
|
|
|
findAds,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})(exports)
|
|
|
|
})(exports)
|
|
|
|
;(function (exports) {
|
|
|
|
;(function (exports) {
|
|
|
|
var parser = {
|
|
|
|
const parser = {
|
|
|
|
TAGS_WITH_SRC_ATTR: {
|
|
|
|
TAGS_WITH_SRC_ATTR: {
|
|
|
|
IMG: true,
|
|
|
|
IMG: true,
|
|
|
|
SCRIPT: true,
|
|
|
|
SCRIPT: true,
|
|
|
|
IFRAME: true,
|
|
|
|
IFRAME: true,
|
|
|
|
EMBED: true
|
|
|
|
EMBED: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
MAX_ATTR_LEN: 100,
|
|
|
|
MAX_ATTR_LEN: 100,
|
|
|
@ -753,8 +753,8 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getUrl: function(el, params) {
|
|
|
|
getUrl(el, params) {
|
|
|
|
var url
|
|
|
|
let url
|
|
|
|
|
|
|
|
|
|
|
|
if (this.TAGS_WITH_SRC_ATTR.hasOwnProperty(el.tagName)) {
|
|
|
|
if (this.TAGS_WITH_SRC_ATTR.hasOwnProperty(el.tagName)) {
|
|
|
|
url = el.src
|
|
|
|
url = el.src
|
|
|
@ -777,14 +777,14 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getParams: function(el) {
|
|
|
|
getParams(el) {
|
|
|
|
if (el.tagName !== 'OBJECT') {
|
|
|
|
if (el.tagName !== 'OBJECT') {
|
|
|
|
return null
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var i, child
|
|
|
|
let i, child
|
|
|
|
var params = {}
|
|
|
|
const params = {}
|
|
|
|
var children = el.children
|
|
|
|
const children = el.children
|
|
|
|
for (i = 0; i < children.length; i++) {
|
|
|
|
for (i = 0; i < children.length; i++) {
|
|
|
|
child = children[i]
|
|
|
|
child = children[i]
|
|
|
|
if (child.tagName === 'PARAM' && child.name) {
|
|
|
|
if (child.tagName === 'PARAM' && child.name) {
|
|
|
@ -798,15 +798,15 @@
|
|
|
|
* Get element position.
|
|
|
|
* Get element position.
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getPosition: function(el) {
|
|
|
|
getPosition(el) {
|
|
|
|
var rect = el.getBoundingClientRect()
|
|
|
|
const rect = el.getBoundingClientRect()
|
|
|
|
var win = exports.utils.elementWindow(el)
|
|
|
|
const win = exports.utils.elementWindow(el)
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
width: Math.round(rect.width),
|
|
|
|
width: Math.round(rect.width),
|
|
|
|
height: Math.round(rect.height),
|
|
|
|
height: Math.round(rect.height),
|
|
|
|
left: Math.round(rect.left + win.pageXOffset),
|
|
|
|
left: Math.round(rect.left + win.pageXOffset),
|
|
|
|
top: Math.round(rect.top + win.pageYOffset)
|
|
|
|
top: Math.round(rect.top + win.pageYOffset),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -818,9 +818,9 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getFlashvars: function(el, params, url) {
|
|
|
|
getFlashvars(el, params, url) {
|
|
|
|
var flashvars
|
|
|
|
let flashvars
|
|
|
|
var urlQS = url && url.split('?')[1]
|
|
|
|
const urlQS = url && url.split('?')[1]
|
|
|
|
|
|
|
|
|
|
|
|
if (el.tagName === 'EMBED') {
|
|
|
|
if (el.tagName === 'EMBED') {
|
|
|
|
flashvars = el.getAttribute('flashvars') || urlQS
|
|
|
|
flashvars = el.getAttribute('flashvars') || urlQS
|
|
|
@ -838,8 +838,8 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
findClickThru: function(el, flashvars) {
|
|
|
|
findClickThru(el, flashvars) {
|
|
|
|
var key
|
|
|
|
let key
|
|
|
|
if (el.tagName === 'IMG' && el.parentElement.tagName === 'A') {
|
|
|
|
if (el.tagName === 'IMG' && el.parentElement.tagName === 'A') {
|
|
|
|
return el.parentElement.href
|
|
|
|
return el.parentElement.href
|
|
|
|
} else if (flashvars) {
|
|
|
|
} else if (flashvars) {
|
|
|
@ -859,8 +859,8 @@
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {String} name
|
|
|
|
* @param {String} name
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getAttr: function(el, name) {
|
|
|
|
getAttr(el, name) {
|
|
|
|
var val = el.getAttribute(name)
|
|
|
|
const val = el.getAttribute(name)
|
|
|
|
|
|
|
|
|
|
|
|
if (val && val.slice && val.toString) {
|
|
|
|
if (val && val.slice && val.toString) {
|
|
|
|
return val.slice(0, this.MAX_ATTR_LEN).toString()
|
|
|
|
return val.slice(0, this.MAX_ATTR_LEN).toString()
|
|
|
@ -877,7 +877,7 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
putPropIfExists: function(obj, name, val) {
|
|
|
|
putPropIfExists(obj, name, val) {
|
|
|
|
if (val) {
|
|
|
|
if (val) {
|
|
|
|
obj[name] = val
|
|
|
|
obj[name] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -891,8 +891,8 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
putAttrIfExists: function(obj, el, name) {
|
|
|
|
putAttrIfExists(obj, el, name) {
|
|
|
|
var val = this.getAttr(el, name)
|
|
|
|
const val = this.getAttr(el, name)
|
|
|
|
this.putPropIfExists(obj, name, val)
|
|
|
|
this.putPropIfExists(obj, name, val)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -901,19 +901,19 @@
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {Boolean} opt_findClickThru
|
|
|
|
* @param {Boolean} opt_findClickThru
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
elementToJSON: function(el, opt_findClickThru) {
|
|
|
|
elementToJSON(el, opt_findClickThru) {
|
|
|
|
var pos = this.getPosition(el)
|
|
|
|
const pos = this.getPosition(el)
|
|
|
|
var params = this.getParams(el)
|
|
|
|
const params = this.getParams(el)
|
|
|
|
var url = this.getUrl(el, params)
|
|
|
|
const url = this.getUrl(el, params)
|
|
|
|
var flashvars = this.getFlashvars(el, params, url)
|
|
|
|
const flashvars = this.getFlashvars(el, params, url)
|
|
|
|
var clickThru = opt_findClickThru && this.findClickThru(el, flashvars)
|
|
|
|
const clickThru = opt_findClickThru && this.findClickThru(el, flashvars)
|
|
|
|
var json = {
|
|
|
|
const json = {
|
|
|
|
tagName: el.tagName,
|
|
|
|
tagName: el.tagName,
|
|
|
|
width: pos.width,
|
|
|
|
width: pos.width,
|
|
|
|
height: pos.height,
|
|
|
|
height: pos.height,
|
|
|
|
left: pos.left,
|
|
|
|
left: pos.left,
|
|
|
|
top: pos.top,
|
|
|
|
top: pos.top,
|
|
|
|
children: []
|
|
|
|
children: [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (params) {
|
|
|
|
if (params) {
|
|
|
@ -930,7 +930,7 @@
|
|
|
|
this.putPropIfExists(json, 'clickThru', clickThru)
|
|
|
|
this.putPropIfExists(json, 'clickThru', clickThru)
|
|
|
|
|
|
|
|
|
|
|
|
return json
|
|
|
|
return json
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.parser = { elementToJSON: parser.elementToJSON.bind(parser) }
|
|
|
|
exports.parser = { elementToJSON: parser.elementToJSON.bind(parser) }
|
|
|
@ -942,7 +942,7 @@
|
|
|
|
* Setter for ad data.
|
|
|
|
* Setter for ad data.
|
|
|
|
* @param {*} adData
|
|
|
|
* @param {*} adData
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
var ContextManager = function(adData) {
|
|
|
|
const ContextManager = function (adData) {
|
|
|
|
this.adData = adData
|
|
|
|
this.adData = adData
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -955,23 +955,23 @@
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {HTMLElement} opt_curWin
|
|
|
|
* @param {HTMLElement} opt_curWin
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
isValidContainer: function(el, opt_curWin) {
|
|
|
|
isValidContainer(el, opt_curWin) {
|
|
|
|
var cWidth = el.clientWidth
|
|
|
|
const cWidth = el.clientWidth
|
|
|
|
var cHeight = el.clientHeight
|
|
|
|
const cHeight = el.clientHeight
|
|
|
|
|
|
|
|
|
|
|
|
var adWidth = this.adData.width
|
|
|
|
const adWidth = this.adData.width
|
|
|
|
var adHeight = this.adData.height
|
|
|
|
const adHeight = this.adData.height
|
|
|
|
|
|
|
|
|
|
|
|
var winWidth = opt_curWin && opt_curWin.innerWidth
|
|
|
|
const winWidth = opt_curWin && opt_curWin.innerWidth
|
|
|
|
var winHeight = opt_curWin && opt_curWin.innerHeight
|
|
|
|
const winHeight = opt_curWin && opt_curWin.innerHeight
|
|
|
|
var similarWin =
|
|
|
|
const similarWin =
|
|
|
|
opt_curWin &&
|
|
|
|
opt_curWin &&
|
|
|
|
this.withinTol(adWidth, winWidth) &&
|
|
|
|
this.withinTol(adWidth, winWidth) &&
|
|
|
|
this.withinTol(adHeight, winHeight)
|
|
|
|
this.withinTol(adHeight, winHeight)
|
|
|
|
|
|
|
|
|
|
|
|
var similarSizeX = this.withinTol(adWidth, cWidth)
|
|
|
|
const similarSizeX = this.withinTol(adWidth, cWidth)
|
|
|
|
var similarSizeY = this.withinTol(adHeight, cHeight)
|
|
|
|
const similarSizeY = this.withinTol(adHeight, cHeight)
|
|
|
|
var adAspect = adWidth / adHeight
|
|
|
|
const adAspect = adWidth / adHeight
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
similarWin ||
|
|
|
|
similarWin ||
|
|
|
@ -986,8 +986,8 @@
|
|
|
|
* @param {Int} adlen
|
|
|
|
* @param {Int} adlen
|
|
|
|
* @param {Int} conlen
|
|
|
|
* @param {Int} conlen
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
withinTol: function(adlen, conlen) {
|
|
|
|
withinTol(adlen, conlen) {
|
|
|
|
var pct = (conlen - adlen) / adlen
|
|
|
|
const pct = (conlen - adlen) / adlen
|
|
|
|
|
|
|
|
|
|
|
|
return pct <= this.CONTAINER_SIZE_TOL
|
|
|
|
return pct <= this.CONTAINER_SIZE_TOL
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -997,43 +997,42 @@
|
|
|
|
* @param {*} el
|
|
|
|
* @param {*} el
|
|
|
|
* @todo define parameter type.
|
|
|
|
* @todo define parameter type.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
serializeElements: function(el) {
|
|
|
|
serializeElements(el) {
|
|
|
|
if (!el) {
|
|
|
|
if (!el) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var i
|
|
|
|
let i
|
|
|
|
var ifrWin
|
|
|
|
let ifrWin
|
|
|
|
var adId = this.adData.adId
|
|
|
|
const adId = this.adData.adId
|
|
|
|
var elIsAd = false
|
|
|
|
let elIsAd = false
|
|
|
|
|
|
|
|
|
|
|
|
if (adId && el[adId] && el[adId].isAd === true) {
|
|
|
|
if (adId && el[adId] && el[adId].isAd === true) {
|
|
|
|
elIsAd = true
|
|
|
|
elIsAd = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var json = exports.parser.elementToJSON(el, elIsAd)
|
|
|
|
const json = exports.parser.elementToJSON(el, elIsAd)
|
|
|
|
var childJSON
|
|
|
|
let childJSON
|
|
|
|
|
|
|
|
|
|
|
|
if (elIsAd) {
|
|
|
|
if (elIsAd) {
|
|
|
|
json.adId = adId
|
|
|
|
json.adId = adId
|
|
|
|
this.adData.element = {}
|
|
|
|
this.adData.element = {}
|
|
|
|
|
|
|
|
|
|
|
|
var keys = Object.keys(json)
|
|
|
|
const keys = Object.keys(json)
|
|
|
|
for (i = 0; i < keys.length; i++) {
|
|
|
|
for (i = 0; i < keys.length; i++) {
|
|
|
|
var key = keys[i]
|
|
|
|
const key = keys[i]
|
|
|
|
if (key !== 'children' && key !== 'contents') {
|
|
|
|
if (key !== 'children' && key !== 'contents') {
|
|
|
|
this.adData.element[key] = json[key]
|
|
|
|
this.adData.element[key] = json[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var children = exports.utils
|
|
|
|
const children = exports.utils
|
|
|
|
.realArray(el.children)
|
|
|
|
.realArray(el.children)
|
|
|
|
.filter(function (el) {
|
|
|
|
.filter(function (el) {
|
|
|
|
var param = el.tagName === 'PARAM'
|
|
|
|
const param = el.tagName === 'PARAM'
|
|
|
|
var inlineScript =
|
|
|
|
const inlineScript =
|
|
|
|
el.tagName === 'SCRIPT' &&
|
|
|
|
el.tagName === 'SCRIPT' && !(el.src && el.src.includes('http'))
|
|
|
|
!(el.src && el.src.indexOf('http') >= 0)
|
|
|
|
const noScript = el.tagName === 'NOSCRIPT'
|
|
|
|
var noScript = el.tagName === 'NOSCRIPT'
|
|
|
|
|
|
|
|
return !(param || inlineScript || noScript)
|
|
|
|
return !(param || inlineScript || noScript)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
@ -1075,7 +1074,7 @@
|
|
|
|
* Get element containers.
|
|
|
|
* Get element containers.
|
|
|
|
* @param {*} containerEl
|
|
|
|
* @param {*} containerEl
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
captureHTML: function(containerEl) {
|
|
|
|
captureHTML(containerEl) {
|
|
|
|
this.adData.context = this.serializeElements(containerEl)
|
|
|
|
this.adData.context = this.serializeElements(containerEl)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -1083,7 +1082,7 @@
|
|
|
|
* Get number of Nodes.
|
|
|
|
* Get number of Nodes.
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
* @param {HTMLElement} el
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
nodeCount: function(el) {
|
|
|
|
nodeCount(el) {
|
|
|
|
return el.getElementsByTagName('*').length + 1
|
|
|
|
return el.getElementsByTagName('*').length + 1
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -1094,10 +1093,10 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
highestContainer: function(curWin, referenceElement) {
|
|
|
|
highestContainer(curWin, referenceElement) {
|
|
|
|
var curContainer = referenceElement
|
|
|
|
let curContainer = referenceElement
|
|
|
|
var docEl = curWin.document.documentElement
|
|
|
|
const docEl = curWin.document.documentElement
|
|
|
|
var parentContainer
|
|
|
|
let parentContainer
|
|
|
|
|
|
|
|
|
|
|
|
if (curWin !== curWin.top && this.isValidContainer(docEl, curWin)) {
|
|
|
|
if (curWin !== curWin.top && this.isValidContainer(docEl, curWin)) {
|
|
|
|
return docEl
|
|
|
|
return docEl
|
|
|
@ -1111,10 +1110,10 @@
|
|
|
|
return curContainer
|
|
|
|
return curContainer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var tagfinder = {
|
|
|
|
const tagfinder = {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {*} adData
|
|
|
|
* @param {*} adData
|
|
|
@ -1123,10 +1122,10 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
setPositions: function(adData, opt_el, opt_winPos) {
|
|
|
|
setPositions(adData, opt_el, opt_winPos) {
|
|
|
|
var el = opt_el || adData.context
|
|
|
|
const el = opt_el || adData.context
|
|
|
|
var winPos = opt_winPos || { left: 0, top: 0 }
|
|
|
|
const winPos = opt_winPos || { left: 0, top: 0 }
|
|
|
|
var ifrPos
|
|
|
|
let ifrPos
|
|
|
|
|
|
|
|
|
|
|
|
el.left += winPos.left
|
|
|
|
el.left += winPos.left
|
|
|
|
el.top += winPos.top
|
|
|
|
el.top += winPos.top
|
|
|
@ -1156,9 +1155,9 @@
|
|
|
|
* @todo add description
|
|
|
|
* @todo add description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
appendTags: (adData, referenceElement) => {
|
|
|
|
appendTags: (adData, referenceElement) => {
|
|
|
|
var mgr = new ContextManager(adData)
|
|
|
|
const mgr = new ContextManager(adData)
|
|
|
|
var curWin = exports.utils.elementWindow(referenceElement)
|
|
|
|
let curWin = exports.utils.elementWindow(referenceElement)
|
|
|
|
var highestContainer
|
|
|
|
let highestContainer
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
while (true) {
|
|
|
|
highestContainer = mgr.highestContainer(curWin, referenceElement)
|
|
|
|
highestContainer = mgr.highestContainer(curWin, referenceElement)
|
|
|
@ -1180,30 +1179,30 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
referenceElement: referenceElement,
|
|
|
|
referenceElement,
|
|
|
|
highestContainer: highestContainer
|
|
|
|
highestContainer,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.tagfinder = tagfinder
|
|
|
|
exports.tagfinder = tagfinder
|
|
|
|
})(exports)
|
|
|
|
})(exports)
|
|
|
|
;(function (exports) {
|
|
|
|
;(function (exports) {
|
|
|
|
var _onAdFound
|
|
|
|
let _onAdFound
|
|
|
|
var _logGen = new exports.utils.LogGenerator()
|
|
|
|
const _logGen = new exports.utils.LogGenerator()
|
|
|
|
var _pageTags
|
|
|
|
let _pageTags
|
|
|
|
var INIT_MS_BW_SEARCHES = 2000
|
|
|
|
const INIT_MS_BW_SEARCHES = 2000
|
|
|
|
var PAGE_TAG_RE = new RegExp('gpt|oascentral')
|
|
|
|
const PAGE_TAG_RE = new RegExp('gpt|oascentral')
|
|
|
|
var POST_MSG_ID = '1554456894-8541-12665-19466-15909'
|
|
|
|
const POST_MSG_ID = '1554456894-8541-12665-19466-15909'
|
|
|
|
var AD_SERVER_RE = new RegExp('^(google_ads_iframe|oas_frame|atwAdFrame)')
|
|
|
|
const AD_SERVER_RE = new RegExp('^(google_ads_iframe|oas_frame|atwAdFrame)')
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get script tags from document.
|
|
|
|
* Get script tags from document.
|
|
|
|
* @param {Object} doc
|
|
|
|
* @param {Object} doc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getPageTags(doc) {
|
|
|
|
function getPageTags(doc) {
|
|
|
|
var scripts = doc.getElementsByTagName('script')
|
|
|
|
let scripts = doc.getElementsByTagName('script')
|
|
|
|
var pageTags = []
|
|
|
|
const pageTags = []
|
|
|
|
scripts = exports.utils.realArray(scripts)
|
|
|
|
scripts = exports.utils.realArray(scripts)
|
|
|
|
scripts.forEach(function (script) {
|
|
|
|
scripts.forEach(function (script) {
|
|
|
|
if (PAGE_TAG_RE.exec(script.src)) {
|
|
|
|
if (PAGE_TAG_RE.exec(script.src)) {
|
|
|
@ -1222,7 +1221,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
adData = JSON.stringify(adData)
|
|
|
|
adData = JSON.stringify(adData)
|
|
|
|
|
|
|
|
|
|
|
|
var win = window
|
|
|
|
let win = window
|
|
|
|
while (win !== win.top) {
|
|
|
|
while (win !== win.top) {
|
|
|
|
win = win.parent
|
|
|
|
win = win.parent
|
|
|
|
win.postMessage(adData, '*')
|
|
|
|
win.postMessage(adData, '*')
|
|
|
@ -1237,7 +1236,7 @@
|
|
|
|
* @todo update description
|
|
|
|
* @todo update description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function appendTagsAndSendToParent(adData, referenceElement) {
|
|
|
|
function appendTagsAndSendToParent(adData, referenceElement) {
|
|
|
|
var results = exports.tagfinder.appendTags(adData, referenceElement)
|
|
|
|
const results = exports.tagfinder.appendTags(adData, referenceElement)
|
|
|
|
if (exports.utils.SCRIPT_IN_HOSTILE_IFRAME) {
|
|
|
|
if (exports.utils.SCRIPT_IN_HOSTILE_IFRAME) {
|
|
|
|
messageAllParentFrames(adData)
|
|
|
|
messageAllParentFrames(adData)
|
|
|
|
} else if (exports.utils.SCRIPT_IN_WINDOW_TOP) {
|
|
|
|
} else if (exports.utils.SCRIPT_IN_WINDOW_TOP) {
|
|
|
@ -1259,7 +1258,7 @@
|
|
|
|
delete adData.height
|
|
|
|
delete adData.height
|
|
|
|
adData.curPageUrl = exports.utils.getPageUrl()
|
|
|
|
adData.curPageUrl = exports.utils.getPageUrl()
|
|
|
|
_pageTags = _pageTags || getPageTags(document)
|
|
|
|
_pageTags = _pageTags || getPageTags(document)
|
|
|
|
var log = _logGen.log('ad', [adData], _pageTags)
|
|
|
|
const log = _logGen.log('ad', [adData], _pageTags)
|
|
|
|
|
|
|
|
|
|
|
|
if (_onAdFound) {
|
|
|
|
if (_onAdFound) {
|
|
|
|
_onAdFound(log, results.referenceElement)
|
|
|
|
_onAdFound(log, results.referenceElement)
|
|
|
@ -1286,17 +1285,17 @@
|
|
|
|
* Main function for extracting ads after loaded.
|
|
|
|
* Main function for extracting ads after loaded.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function extractAds() {
|
|
|
|
function extractAds() {
|
|
|
|
var ads = exports.adfinder.findAds(window)
|
|
|
|
const ads = exports.adfinder.findAds(window)
|
|
|
|
ads.forEach(function (ad) {
|
|
|
|
ads.forEach(function (ad) {
|
|
|
|
var startTime = new Date().getTime()
|
|
|
|
const startTime = new Date().getTime()
|
|
|
|
var adId = startTime + '-' + Math.floor(Math.random() * 10e12)
|
|
|
|
const adId = startTime + '-' + Math.floor(Math.random() * 10e12)
|
|
|
|
|
|
|
|
|
|
|
|
var adData = {
|
|
|
|
const adData = {
|
|
|
|
width: Math.round(ad.offsetWidth),
|
|
|
|
width: Math.round(ad.offsetWidth),
|
|
|
|
height: Math.round(ad.offsetHeight),
|
|
|
|
height: Math.round(ad.offsetHeight),
|
|
|
|
startTime: startTime,
|
|
|
|
startTime,
|
|
|
|
adId: adId,
|
|
|
|
adId,
|
|
|
|
html5: ad.html5 || false
|
|
|
|
html5: ad.html5 || false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ad.html5) {
|
|
|
|
if (ad.html5) {
|
|
|
@ -1316,7 +1315,7 @@
|
|
|
|
* @param {Object} otherWin
|
|
|
|
* @param {Object} otherWin
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function isChildWin(myWin, otherWin) {
|
|
|
|
function isChildWin(myWin, otherWin) {
|
|
|
|
var parentWin = otherWin.parent
|
|
|
|
let parentWin = otherWin.parent
|
|
|
|
while (parentWin !== otherWin) {
|
|
|
|
while (parentWin !== otherWin) {
|
|
|
|
if (parentWin === myWin) {
|
|
|
|
if (parentWin === myWin) {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
@ -1335,10 +1334,10 @@
|
|
|
|
* @todo update description
|
|
|
|
* @todo update description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function iframeFromWindow(win, winToMatch) {
|
|
|
|
function iframeFromWindow(win, winToMatch) {
|
|
|
|
var i,
|
|
|
|
let i
|
|
|
|
ifr,
|
|
|
|
let ifr
|
|
|
|
ifrWin,
|
|
|
|
let ifrWin
|
|
|
|
iframes = win.document.querySelectorAll('iframe')
|
|
|
|
const iframes = win.document.querySelectorAll('iframe')
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < iframes.length; i++) {
|
|
|
|
for (i = 0; i < iframes.length; i++) {
|
|
|
|
ifr = iframes[i]
|
|
|
|
ifr = iframes[i]
|
|
|
@ -1365,15 +1364,12 @@
|
|
|
|
* @todo update description
|
|
|
|
* @todo update description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function onPostMessage(event) {
|
|
|
|
function onPostMessage(event) {
|
|
|
|
var adData,
|
|
|
|
let adData
|
|
|
|
ifrWin = event.source,
|
|
|
|
const ifrWin = event.source
|
|
|
|
myWin = window.document.defaultView,
|
|
|
|
const myWin = window.document.defaultView
|
|
|
|
ifrTag
|
|
|
|
let ifrTag
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (typeof event.data === 'string' && event.data.includes(POST_MSG_ID)) {
|
|
|
|
typeof event.data === 'string' &&
|
|
|
|
|
|
|
|
event.data.indexOf(POST_MSG_ID) != -1
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
adData = JSON.parse(event.data)
|
|
|
|
adData = JSON.parse(event.data)
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
@ -1410,7 +1406,7 @@
|
|
|
|
* @todo update description
|
|
|
|
* @todo update description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function onVideoMessage(msg, sender, callback) {
|
|
|
|
function onVideoMessage(msg, sender, callback) {
|
|
|
|
var log
|
|
|
|
let log
|
|
|
|
if (msg.event === 'new-video-ad') {
|
|
|
|
if (msg.event === 'new-video-ad') {
|
|
|
|
msg.assets.forEach(function (asset) {})
|
|
|
|
msg.assets.forEach(function (asset) {})
|
|
|
|
log = _logGen.log('video', msg.assets)
|
|
|
|
log = _logGen.log('video', msg.assets)
|
|
|
@ -1448,7 +1444,7 @@
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @todo update description
|
|
|
|
* @todo update description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
addPostMessageListener: function() {
|
|
|
|
addPostMessageListener() {
|
|
|
|
if (!exports.utils.SCRIPT_IN_FRIENDLY_IFRAME) {
|
|
|
|
if (!exports.utils.SCRIPT_IN_FRIENDLY_IFRAME) {
|
|
|
|
window.addEventListener('message', onPostMessage, false)
|
|
|
|
window.addEventListener('message', onPostMessage, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1461,10 +1457,10 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo update description
|
|
|
|
* @todo update description
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
blockedRobotsMsgGen: function(sendFcn, origUrl) {
|
|
|
|
blockedRobotsMsgGen(sendFcn, origUrl) {
|
|
|
|
if (origUrl.indexOf('google.com/_/chrome/newtab') === -1) {
|
|
|
|
if (!origUrl.includes('google.com/_/chrome/newtab')) {
|
|
|
|
var onBlockedRobotsMessage = function() {
|
|
|
|
const onBlockedRobotsMessage = function () {
|
|
|
|
var log
|
|
|
|
let log
|
|
|
|
log = _logGen.log('invalid-robotstxt', [])
|
|
|
|
log = _logGen.log('invalid-robotstxt', [])
|
|
|
|
log.doc.finalPageUrl = log.doc.url
|
|
|
|
log.doc.finalPageUrl = log.doc.url
|
|
|
|
log.doc.url = exports.utils.normalizeUrl(origUrl)
|
|
|
|
log.doc.url = exports.utils.normalizeUrl(origUrl)
|
|
|
@ -1481,18 +1477,18 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {*} onAdFound
|
|
|
|
* @param {*} onAdFound
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
init: function(onAdFound) {
|
|
|
|
init(onAdFound) {
|
|
|
|
if (exports.utils.SCRIPT_IN_FRIENDLY_IFRAME) {
|
|
|
|
if (exports.utils.SCRIPT_IN_FRIENDLY_IFRAME) {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_onAdFound = onAdFound
|
|
|
|
_onAdFound = onAdFound
|
|
|
|
if (exports.utils.SCRIPT_IN_WINDOW_TOP) {
|
|
|
|
if (exports.utils.SCRIPT_IN_WINDOW_TOP) {
|
|
|
|
var log = _logGen.log('page')
|
|
|
|
const log = _logGen.log('page')
|
|
|
|
onAdFound(log)
|
|
|
|
onAdFound(log)
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('beforeunload', function (event) {
|
|
|
|
window.addEventListener('beforeunload', function (event) {
|
|
|
|
var log = _logGen.log('unload')
|
|
|
|
const log = _logGen.log('unload')
|
|
|
|
log.timing = window.performance.timing
|
|
|
|
log.timing = window.performance.timing
|
|
|
|
onAdFound(log)
|
|
|
|
onAdFound(log)
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -1502,7 +1498,7 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.utils.onDocLoaded(document, extractAdsWrapper)
|
|
|
|
exports.utils.onDocLoaded(document, extractAdsWrapper)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})(exports)
|
|
|
|
})(exports)
|
|
|
|
|
|
|
|
|
|
|
@ -1513,7 +1509,7 @@
|
|
|
|
askIfTrackingEnabled: exports.utils.askIfTrackingEnabled,
|
|
|
|
askIfTrackingEnabled: exports.utils.askIfTrackingEnabled,
|
|
|
|
blockedRobotsMsgGen: exports.coordinator.blockedRobotsMsgGen,
|
|
|
|
blockedRobotsMsgGen: exports.coordinator.blockedRobotsMsgGen,
|
|
|
|
inWindowTop: exports.utils.SCRIPT_IN_WINDOW_TOP,
|
|
|
|
inWindowTop: exports.utils.SCRIPT_IN_WINDOW_TOP,
|
|
|
|
sendToBackground: exports.utils.sendToBackground
|
|
|
|
sendToBackground: exports.utils.sendToBackground,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
exports.coordinator.addPostMessageListener()
|
|
|
|
exports.coordinator.addPostMessageListener()
|
|
|
|