From fb1221a8a1a3a2b7ad11947acfe8d25b7773980b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 26 Nov 2014 15:45:36 -0200 Subject: [PATCH] remove overhead of PSL for "3rd-party filters" tab --- src/3p-filters.html | 2 -- src/js/3p-filters.js | 22 ++++++---------------- src/js/messaging.js | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/3p-filters.html b/src/3p-filters.html index 3ee5213a1..fc89a4851 100644 --- a/src/3p-filters.html +++ b/src/3p-filters.html @@ -31,12 +31,10 @@
- - diff --git a/src/js/3p-filters.js b/src/js/3p-filters.js index 00b731875..b6bb1ea3a 100644 --- a/src/js/3p-filters.js +++ b/src/js/3p-filters.js @@ -36,8 +36,7 @@ var cacheWasPurged = false; var needUpdate = false; var hasCachedContent = false; -var re3rdPartyExternalAsset = /^https?:\/\/[a-z0-9]+/; -var re3rdPartyRepoAsset = /^assets\/thirdparties\/([^\/]+)/; +var re3rdPartyExternalAsset = /^https?:\/\/([a-z0-9.-]+)/; /******************************************************************************/ @@ -81,24 +80,15 @@ var renderBlacklists = function() { }; // Assemble a pretty blacklist name if possible - var htmlFromHomeURL = function(blacklistHref) { - if ( blacklistHref.indexOf('assets/thirdparties/') !== 0 ) { - return ''; - } - var matches = re3rdPartyRepoAsset.exec(blacklistHref); - if ( matches === null || matches.length !== 2 ) { - return ''; - } - var hostname = matches[1]; - var domain = µBlock.URI.domainFromHostname(hostname); - if ( domain === '' ) { + var htmlFromHomeURL = function(entry) { + if ( !entry.homeDomain ) { return ''; } var html = [ ' (', - domain, + entry.homeDomain, ')' ]; return html.join(''); @@ -128,7 +118,7 @@ var renderBlacklists = function() { .replace('{{checked}}', list.off ? '' : 'checked') .replace('{{URL}}', encodeURI(listKey)) .replace('{{name}}', listNameFromListKey(listKey)) - .replace('{{homeURL}}', htmlFromHomeURL(listKey)) + .replace('{{homeURL}}', htmlFromHomeURL(list)) .replace('{{used}}', !list.off && !isNaN(+list.entryUsedCount) ? renderNumber(list.entryUsedCount) : '0') .replace('{{total}}', !isNaN(+list.entryCount) ? renderNumber(list.entryCount) : '?'); html.push(li); diff --git a/src/js/messaging.js b/src/js/messaging.js index db6c41396..d46a0a554 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -449,6 +449,23 @@ var µb = µBlock; /******************************************************************************/ +var prepEntries = function(entries) { + var µburi = µb.URI; + var entry; + for ( var k in entries ) { + if ( entries.hasOwnProperty(k) === false ) { + continue; + } + entry = entries[k]; + if ( typeof entry.homeURL === 'string' ) { + entry.homeHostname = µburi.hostnameFromURI(entry.homeURL); + entry.homeDomain = µburi.domainFromHostname(entry.homeHostname); + } + } +}; + +/******************************************************************************/ + var getLists = function(callback) { var r = { available: null, @@ -462,10 +479,12 @@ var getLists = function(callback) { }; var onMetadataReady = function(entries) { r.cache = entries; + prepEntries(r.cache); callback(r); }; var onLists = function(lists) { r.available = lists; + prepEntries(r.available); µb.assets.metadata(onMetadataReady); }; µb.getAvailableLists(onLists);