From 147fbf7f8e6d75893edd41cd568af51e22c4f48d Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 25 Sep 2014 20:21:21 -0400 Subject: [PATCH] try to extract a user-friendly list name from the list content --- js/3p-filters.js | 14 ++++++++------ js/storage.js | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/js/3p-filters.js b/js/3p-filters.js index 4f56f8c57..3eb49c332 100644 --- a/js/3p-filters.js +++ b/js/3p-filters.js @@ -77,14 +77,16 @@ var renderBlacklists = function() { var µb = getµb(); // Assemble a pretty blacklist name if possible - var htmlFromListName = function(blacklistTitle, blacklistHref) { - if ( blacklistHref === listDetails.userFiltersPath ) { + var listNameFromListKey = function(listKey) { + if ( listKey === listDetails.userFiltersPath ) { return userListName; } - if ( !blacklistTitle ) { - return blacklistHref; + var list = listDetails.current[listKey] || listDetails.available[listKey]; + var listTitle = list ? list.title : ''; + if ( listTitle === '' ) { + return listKey; } - return blacklistTitle; + return listTitle; }; // Assemble a pretty blacklist name if possible @@ -134,7 +136,7 @@ var renderBlacklists = function() { var li = liTemplate .replace('{{checked}}', list.off ? '' : 'checked') .replace('{{URL}}', encodeURI(listKey)) - .replace('{{name}}', htmlFromListName(list.title, listKey)) + .replace('{{name}}', listNameFromListKey(listKey)) .replace('{{homeURL}}', htmlFromHomeURL(listKey)) .replace('{{used}}', !list.off && !isNaN(+list.entryUsedCount) ? renderNumber(list.entryUsedCount) : '0') .replace('{{total}}', !isNaN(+list.entryCount) ? renderNumber(list.entryCount) : '?'); diff --git a/js/storage.js b/js/storage.js index e1f80a40c..b5d6560be 100644 --- a/js/storage.js +++ b/js/storage.js @@ -196,6 +196,10 @@ if ( storedEntry.entryUsedCount !== undefined ) { availableEntry.entryUsedCount = storedEntry.entryUsedCount; } + // This may happen if the list name was pulled from the list content + if ( availableEntry.title === '' && storedEntry.title !== '' ) { + availableEntry.title = storedEntry.title; + } } callback(availableLists); }; @@ -335,8 +339,19 @@ duplicateCount = netFilteringEngine.duplicateCount + cosmeticFilteringEngine.duplicateCount - duplicateCount; acceptedCount = netFilteringEngine.acceptedCount + cosmeticFilteringEngine.acceptedCount - acceptedCount; - this.remoteBlacklists[details.path].entryCount = acceptedCount; - this.remoteBlacklists[details.path].entryUsedCount = acceptedCount - duplicateCount; + var filterListMeta = this.remoteBlacklists[details.path]; + + filterListMeta.entryCount = acceptedCount; + filterListMeta.entryUsedCount = acceptedCount - duplicateCount; + + // Try to extract a human-friendly name (works only for + // ABP-compatible filter lists) + if ( filterListMeta.title === '' ) { + var matches = details.content.slice(0, 1024).match(/(?:^|\n)!\s*Title:([^\n]+)/i); + if ( matches !== null ) { + filterListMeta.title = matches[1].trim(); + } + } }; /******************************************************************************/