1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-06 19:02:30 +01:00

try to extract a user-friendly list name from the list content

This commit is contained in:
gorhill 2014-09-25 20:21:21 -04:00
parent dde27629a2
commit 147fbf7f8e
2 changed files with 25 additions and 8 deletions

View File

@ -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) : '?');

View File

@ -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();
}
}
};
/******************************************************************************/