Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
#18
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Oct 20, 2013
1 parent 89541f3 commit ec44f7d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
33 changes: 25 additions & 8 deletions js/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/******************************************************************************/

// Whitelist something
function allow(type, domain) {
function whitelistTemporarily(type, domain) {
var httpsb = HTTPSB;
var key = type + '/' + domain;
var whitelisted = !httpsb.whitelist[key];
Expand All @@ -36,7 +36,7 @@ function allow(type, domain) {
}
}

function allowPermanently(type, domain) {
function whitelistPermanently(type, domain) {
var httpsb = HTTPSB;
var key = type + '/' + domain;
var whitelisted = !httpsb.whitelistUser[key];
Expand All @@ -56,7 +56,7 @@ function allowPermanently(type, domain) {
/******************************************************************************/

// Blacklist something
function disallow(type, domain) {
function blacklistTemporarily(type, domain) {
var httpsb = HTTPSB;
var key = type + '/' + domain;
var unwhitelisted = httpsb.whitelist[key];
Expand All @@ -70,7 +70,7 @@ function disallow(type, domain) {
}
}

function disallowPermanently(type, domain) {
function blacklistPermanently(type, domain) {
var httpsb = HTTPSB;
var key = type + '/' + domain;
var unwhitelisted = httpsb.whitelistUser[key];
Expand Down Expand Up @@ -133,13 +133,30 @@ function graylistPermanently(type, domain) {

// Reset lists to their default state.

function resetLists() {
function restoreTemporaryLists() {
var httpsb = HTTPSB;
httpsb.whitelist = {};
httpsb.blacklist = {};
populateListFromList(httpsb.whitelist, httpsb.whitelistUser);
populateListFromList(httpsb.blacklist, httpsb.blacklistUser);
populateListFromString(httpsb.blacklist, httpsb.blacklistRemote);
populateListFromList(httpsb.blacklist, httpsb.blacklistUser);
// rhill 2013-10-19: https://github.com/gorhill/httpswitchboard/issues/18
// Be sure a domain doesn't end up in both the effective black and whitelist
restoreTemporaryWhitelist();
}


// rhill 2013-10-19: https://github.com/gorhill/httpswitchboard/issues/18
// I create a separate function so it can also be called at launch time.
function restoreTemporaryWhitelist() {
var httpsb = HTTPSB;
httpsb.whitelist = {};
var filters = Object.keys(httpsb.whitelistUser);
var i = filters.length;
var filter;
while ( i-- ) {
filter = filters[i];
delete httpsb.blacklist[filter];
httpsb.whitelist[filter] = true;
}
}

/******************************************************************************/
Expand Down
10 changes: 5 additions & 5 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ var handleFilter = function(button) {
var domain = button.prop('filterDomain');
var nextAction = getNextAction(domain, type);
if ( nextAction === 'blacklist' ) {
background.disallow(type, domain);
background.blacklistTemporarily(type, domain);
} else if ( nextAction === 'whitelist' ) {
background.allow(type, domain);
background.whitelistTemporarily(type, domain);
} else {
background.graylist(type, domain);
}
Expand All @@ -334,9 +334,9 @@ var handlePersistence = function(button) {
if ( !entry ) { return; }
if ( entry.temporaryColor.charAt(1) === 'd' && entry.temporaryColor !== entry.permanentColor ) {
if ( entry.temporaryColor === 'rdt' ) {
background.disallowPermanently(type, domain);
background.blacklistPermanently(type, domain);
} else if ( entry.temporaryColor === 'gdt' ) {
background.allowPermanently(type, domain);
background.whitelistPermanently(type, domain);
}
entry.permanentColor = background.getPermanentColor(type, domain);
var newClass = getCellClass(domain, type);
Expand Down Expand Up @@ -589,7 +589,7 @@ document.addEventListener('DOMContentLoaded', function () {
});

$('#button-revert').click(function() {
background.resetLists();
background.restoreTemporaryLists();
updateMatrixStats(matrixStats);
updateFilterButtons();
});
Expand Down
21 changes: 15 additions & 6 deletions js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ function loadUserLists() {
store.graylist = '';
}

populateListFromString(httpsb.whitelistUser, store.whitelist);
populateListFromList(httpsb.whitelist, httpsb.whitelistUser);

populateListFromString(httpsb.blacklistUser, store.blacklist);
populateListFromList(httpsb.blacklist, httpsb.blacklistUser);

populateListFromString(httpsb.graylistUser, store.graylist);
populateListFromList(httpsb.graylist, httpsb.graylistUser);

populateListFromString(httpsb.whitelistUser, store.whitelist);
populateListFromList(httpsb.whitelist, httpsb.whitelistUser);

// rhill 20130923: ok, there is no point in blacklisting
// 'main_frame/*', since there is only one such page per tab. It is
// reasonable to whitelist by default 'main_frame/*', and top page of
// blacklisted domain name will not be loaded anyways (because domain
// name has precedence over type). Now this way we save precious real
// estate pixels in popup menu.
allow('main_frame', '*');
whitelistTemporarily('main_frame', '*');

chrome.runtime.sendMessage({
'what': 'startWebRequestHandler',
Expand Down Expand Up @@ -291,7 +291,7 @@ function queryRemoteBlacklist(location) {
/******************************************************************************/

function parseRemoteBlacklist(list) {
console.log('HTTP Switchboard > parseRemoteBlacklist > "%s"', list.url);
// console.log('HTTP Switchboard > parseRemoteBlacklist > "%s"', list.url);
list.raw = normalizeRemoteContent('*/', list.raw, '');
// Save locally in order to load efficiently in the future.
chrome.runtime.sendMessage({
Expand Down Expand Up @@ -333,9 +333,18 @@ function localRemoveRemoteBlacklist(list) {
/******************************************************************************/

function mergeRemoteBlacklist(list) {
console.log('HTTP Switchboard > mergeRemoteBlacklist from "%s": "%s..."', list.url, list.raw.slice(0, 40));
// console.log('HTTP Switchboard > mergeRemoteBlacklist from "%s": "%s..."', list.url, list.raw.slice(0, 40));
var httpsb = HTTPSB;

populateListFromString(httpsb.blacklist, list.raw);

// rhill 2013-10-19: https://github.com/gorhill/httpswitchboard/issues/18
// Ensure that whatever is in the whitelist is not also found in the
// blacklist.
restoreTemporaryWhitelist();

// Make our internal collection of preset blacklist domains compatible with
// quickIndexOf().
httpsb.blacklistRemote += '\n' + list.raw;
httpsb.blacklistRemote = '\n' + httpsb.blacklistRemote
.trim()
Expand Down

0 comments on commit ec44f7d

Please sign in to comment.