daelement.href).hostname;
} catch (e) {}
try {
topurl = window.location != window.parent.location ? document.referrer : document.location.href;
} catch (e) {}
try {
topdomain = new .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"] = getabsolute;
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();
})();