1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-02 08:52:45 +01:00

remove overhead of PSL for "3rd-party filters" tab

This commit is contained in:
Raymond Hill 2014-11-26 15:45:36 -02:00
parent f149b2e340
commit fb1221a8a1
3 changed files with 25 additions and 18 deletions

View File

@ -31,12 +31,10 @@
<div id="busyOverlay"></div> <div id="busyOverlay"></div>
<script src="lib/publicsuffixlist.min.js"></script>
<script src="js/vapi-common.js"></script> <script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script> <script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script> <script src="js/udom.js"></script>
<script src="js/i18n.js"></script> <script src="js/i18n.js"></script>
<script src="js/uritools.js"></script>
<script src="js/dashboard-common.js"></script> <script src="js/dashboard-common.js"></script>
<script src="js/3p-filters.js"></script> <script src="js/3p-filters.js"></script>

View File

@ -36,8 +36,7 @@ var cacheWasPurged = false;
var needUpdate = false; var needUpdate = false;
var hasCachedContent = false; var hasCachedContent = false;
var re3rdPartyExternalAsset = /^https?:\/\/[a-z0-9]+/; var re3rdPartyExternalAsset = /^https?:\/\/([a-z0-9.-]+)/;
var re3rdPartyRepoAsset = /^assets\/thirdparties\/([^\/]+)/;
/******************************************************************************/ /******************************************************************************/
@ -81,24 +80,15 @@ var renderBlacklists = function() {
}; };
// Assemble a pretty blacklist name if possible // Assemble a pretty blacklist name if possible
var htmlFromHomeURL = function(blacklistHref) { var htmlFromHomeURL = function(entry) {
if ( blacklistHref.indexOf('assets/thirdparties/') !== 0 ) { if ( !entry.homeDomain ) {
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 === '' ) {
return ''; return '';
} }
var html = [ var html = [
' <a href="http://', ' <a href="http://',
hostname, entry.homeHostname,
'" target="_blank">(', '" target="_blank">(',
domain, entry.homeDomain,
')</a>' ')</a>'
]; ];
return html.join(''); return html.join('');
@ -128,7 +118,7 @@ var renderBlacklists = function() {
.replace('{{checked}}', list.off ? '' : 'checked') .replace('{{checked}}', list.off ? '' : 'checked')
.replace('{{URL}}', encodeURI(listKey)) .replace('{{URL}}', encodeURI(listKey))
.replace('{{name}}', listNameFromListKey(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('{{used}}', !list.off && !isNaN(+list.entryUsedCount) ? renderNumber(list.entryUsedCount) : '0')
.replace('{{total}}', !isNaN(+list.entryCount) ? renderNumber(list.entryCount) : '?'); .replace('{{total}}', !isNaN(+list.entryCount) ? renderNumber(list.entryCount) : '?');
html.push(li); html.push(li);

View File

@ -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 getLists = function(callback) {
var r = { var r = {
available: null, available: null,
@ -462,10 +479,12 @@ var getLists = function(callback) {
}; };
var onMetadataReady = function(entries) { var onMetadataReady = function(entries) {
r.cache = entries; r.cache = entries;
prepEntries(r.cache);
callback(r); callback(r);
}; };
var onLists = function(lists) { var onLists = function(lists) {
r.available = lists; r.available = lists;
prepEntries(r.available);
µb.assets.metadata(onMetadataReady); µb.assets.metadata(onMetadataReady);
}; };
µb.getAvailableLists(onLists); µb.getAvailableLists(onLists);