dAElement.href).hostname;
} catch (e) {}
try {
topUrl = window.location != window.parent.location ? document.referrer : document.location.href;
} catch (e) {}
try {
topDomain = new URL(topUrl).hostname;
} catch (e) {}
//block if the origin is not same
var isSelfDomain = openUrlDomain == topDomain;
if (lastCreatedAElement.href.trim() && !isInWhitelist(lastCreatedAElement.href) && !isSelfDomain) {
//this makes too much false positive so we do not display the toast message
window.pbreason = 'Blocked because \'a\' element was recently created and ' + arguments[0] + ' event was created shortly after';
arguments[0] = lastCreatedAElement.href;
blockedWndNotification({ "0": lastCreatedAElement.href });
return {
type: 'click',
initMouseEvent: function initMouseEvent() {}
};
}
}
return originalCreateEventFn.apply(document, arguments);
} catch (err) {}
};
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Monitor full screen requests
/////////////////////////////////////////////////////////////////////////////////
function onFullScreen(isInFullScreenMode) {
if (isInFullScreenMode) {
fullScreenOpenTime = new Date().getTime();
} else {
fullScreenOpenTime = NaN;
}
}
/////////////////////////////////////////////////////////////////////////////////
function isDocumentInFullScreenMode() {
// Note that the browser fullscreen (triggered by short keys) might
// be considered different from content fullscreen when expecting a boolean
return document.fullScreenElement && document.fullScreenElement !== null || // alternative standard methods
document.mozFullscreenElement != null || document.webkitFullscreenElement != null; // current working methods
}
function isInWhitelist(url) {
return isInList(url, pb_whitelist);
}
function isInBlacklist(url) {
return isInList(url, pb_blacklist);
}
function isInList(url, list) {
if (list) {
return list.some(function (li) {
return new RegExp("https?://(www\.|.*\.)?" + li + "+").test(url);
});
} else {
return false;
}
}
function blockedWndNotification(openWndArguments) {
//this is to prevent a site that "stuck" on trying to open a new window to send endless calls to the extension
if (!lastBlockTime || lastBlockTime < Date.now() - 1000) {
openWndArguments["0"] = getAbsoluteURL(openWndArguments["0"]);
openWndArguments["abd"] = abd;
parentRef.postMessage({ type: "blockedWindow", args: JSON.stringify(openWndArguments) }, parentOrigin);
}
lastBlockTime = Date.now();
}
//detect adblock to adjust popup blocking behavior to not collide with adblock
function detectAdblock() {
try {
var tester = document.createElement('div');
tester.innerHTML = ' ';
tester.className = 'adsbox';
tester.style.cssText = "position:absolute;top-1000px;left:-1000px;";
document.body.appendChild(tester);
window.setTimeout(function () {
if (tester.offsetHeight === 0) {
abd = true;
}
tester.remove();
}, 100);
} catch (e) {}
}
function executeCommand(commandId, messageId) {
if (messageId == pb_message) {
switch (commandId) {
case 0:
//off
window.open = originalWindowOpenFn;
document.createElement = originalCreateElementFn;
document.createEvent = originalCreateEventFn;
HTMLElement.prototype.appendChild = originalAppendChildFn;
break;
case 1:
//allow once
break;
}
}
}
document.addEventListener("fullscreenchange", function () {
onFullScreen(document.fullscreen);
}, false);
document.addEventListener("mozfullscreenchange", function () {
onFullScreen(document.mozFullScreen);
}, false);
document.addEventListener("webkitfullscreenchange", function () {
onFullScreen(document.webkitIsFullScreen);
}, false);
//document.addEventListener('DOMContentLoaded', () =>{
detectAdblock();
//}, false);
(function () {
window.pbExternalCommand = function (commandId, messageId) {
executeCommand(commandId, messageId);
};
})();
};
inject();
})();