This commit is contained in:
gorhill 2014-07-26 16:10:20 -04:00
parent 0f601e55ad
commit 8eff9ddcee
7 changed files with 85 additions and 13 deletions

View File

@ -36,11 +36,17 @@ ul > li > ul > li {
.dim { .dim {
color: #888; color: #888;
} }
.userUbiquitousHosts { button.purge {
font-size: smaller; margin: 0;
width: 36em; border: 1px solid #ccc;
height: 16em; padding: 1px 2px;
white-space: nowrap; color: #444;
background-color: #eee;
font-size: 11px;
opacity: 0.6;
}
button.purge:hover {
opacity: 1;
} }
#externalLists { #externalLists {
font-size: smaller; font-size: smaller;

View File

@ -143,6 +143,10 @@
"message":"Anwenden", "message":"Anwenden",
"description":"English: Apply" "description":"English: Apply"
}, },
"3pExternalListPurge":{
"message":"purge cache",
"description":"English: purge cache"
},
"1pFormatHint":{ "1pFormatHint":{
"message":"Eine Regel pro Zeile. Eine Regel kann ein einfacher Host-Name sein oder ein Adblock Plus-kompatibler Filter. Zeilen mit vorangestelltem ‘!’ werden ignoriert.", "message":"Eine Regel pro Zeile. Eine Regel kann ein einfacher Host-Name sein oder ein Adblock Plus-kompatibler Filter. Zeilen mit vorangestelltem ‘!’ werden ignoriert.",
"description":"English: One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with ‘!’ will be ignored." "description":"English: One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with ‘!’ will be ignored."

View File

@ -143,6 +143,10 @@
"message":"Apply", "message":"Apply",
"description":"English: Apply" "description":"English: Apply"
}, },
"3pExternalListPurge":{
"message":"purge cache",
"description":"English: purge cache"
},
"1pFormatHint":{ "1pFormatHint":{
"message":"One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with ‘!’ will be ignored.", "message":"One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with ‘!’ will be ignored.",
"description":"English: One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with ‘!’ will be ignored." "description":"English: One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with ‘!’ will be ignored."

View File

@ -143,6 +143,10 @@
"message":"Appliquer", "message":"Appliquer",
"description":"English: Apply" "description":"English: Apply"
}, },
"3pExternalListPurge":{
"message":"purge cache",
"description":"English: purge cache"
},
"1pFormatHint":{ "1pFormatHint":{
"message":"Une règle par ligne. Une règle peut être un simple nom d'hôte, ou encore un filtre respectant la syntaxe des filtres Adblock Plus. Les lignes débutant par ‘!’ seront ignorées.", "message":"Une règle par ligne. Une règle peut être un simple nom d'hôte, ou encore un filtre respectant la syntaxe des filtres Adblock Plus. Les lignes débutant par ‘!’ seront ignorées.",
"description":"English: One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with ‘!’ will be ignored." "description":"English: One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with ‘!’ will be ignored."

View File

@ -30,6 +30,7 @@
var userListName = chrome.i18n.getMessage('1pPageName'); var userListName = chrome.i18n.getMessage('1pPageName');
var listDetails = {}; var listDetails = {};
var externalLists = ''; var externalLists = '';
var cacheWasPurged = false;
/******************************************************************************/ /******************************************************************************/
@ -107,6 +108,7 @@ var renderBlacklists = function() {
}; };
var listStatsTemplate = chrome.i18n.getMessage('3pListsOfBlockedHostsPerListStats'); var listStatsTemplate = chrome.i18n.getMessage('3pListsOfBlockedHostsPerListStats');
var purgeButtontext = chrome.i18n.getMessage('3pExternalListPurge');
var htmlFromBranch = function(groupKey, listKeys, lists) { var htmlFromBranch = function(groupKey, listKeys, lists) {
var html = [ var html = [
@ -143,6 +145,15 @@ var renderBlacklists = function() {
.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(listEntry); html.push(listEntry);
// https://github.com/gorhill/uBlock/issues/104
if ( /^https?:\/\/.+/.test(listKey) && listDetails.cache[listKey] ) {
html.push(
' ',
'<button type="button" class="purge">',
purgeButtontext,
'</button>'
);
}
} }
html.push('</ul>'); html.push('</ul>');
return html.join(''); return html.join('');
@ -217,6 +228,9 @@ var needToReload = function() {
if ( listDetails.cosmetic !== getµb().userSettings.parseAllABPHideFilters ) { if ( listDetails.cosmetic !== getµb().userSettings.parseAllABPHideFilters ) {
return true; return true;
} }
if ( cacheWasPurged ) {
return true;
}
var availableLists = listDetails.available; var availableLists = listDetails.available;
var currentLists = listDetails.current; var currentLists = listDetails.current;
var location, availableOff, currentOff; var location, availableOff, currentOff;
@ -279,6 +293,20 @@ var onListLinkClicked = function(ev) {
/******************************************************************************/ /******************************************************************************/
var onPurgeClicked = function(ev) {
var button = uDom(this);
var href = button.parent().find('a').first().attr('href');
if ( !href ) {
return;
}
messaging.tell({ what: 'purgeCache', path: href });
button.remove();
cacheWasPurged = true;
selectedBlacklistsChanged();
};
/******************************************************************************/
var blacklistsApplyHandler = function() { var blacklistsApplyHandler = function() {
if ( !needToReload() ) { if ( !needToReload() ) {
return; return;
@ -308,6 +336,7 @@ var blacklistsApplyHandler = function() {
what: 'reloadAllFilters', what: 'reloadAllFilters',
switches: switches switches: switches
}); });
cacheWasPurged = false;
uDom('#blacklistsApply').prop('disabled', true); uDom('#blacklistsApply').prop('disabled', true);
}; };
@ -358,6 +387,7 @@ uDom.onLoad(function() {
uDom('#blacklistsApply').on('click', blacklistsApplyHandler); uDom('#blacklistsApply').on('click', blacklistsApplyHandler);
uDom('#lists').on('change', '.listDetails > input', onListCheckboxChanged); uDom('#lists').on('change', '.listDetails > input', onListCheckboxChanged);
uDom('#lists').on('click', '.listDetails > a:nth-of-type(1)', onListLinkClicked); uDom('#lists').on('click', '.listDetails > a:nth-of-type(1)', onListLinkClicked);
uDom('#lists').on('click', 'button.purge', onPurgeClicked);
uDom('#externalLists').on('input', externalListsChangeHandler); uDom('#externalLists').on('input', externalListsChangeHandler);
uDom('#externalListsApply').on('click', externalListsApplyHandler); uDom('#externalListsApply').on('click', externalListsApplyHandler);

View File

@ -95,6 +95,7 @@ var cachedAssetsManager = (function() {
}; };
chrome.storage.local.get('cached_asset_entries', onLoaded); chrome.storage.local.get('cached_asset_entries', onLoaded);
}; };
exports.entries = getEntries;
exports.load = function(path, cbSuccess, cbError) { exports.load = function(path, cbSuccess, cbError) {
cbSuccess = cbSuccess || nullFunc; cbSuccess = cbSuccess || nullFunc;
@ -625,6 +626,12 @@ var updateFromRemote = function(details, callback) {
/******************************************************************************/ /******************************************************************************/
var cacheEntries = function(callback) {
return cachedAssetsManager.entries(callback);
};
/******************************************************************************/
// Flush cached assets if cache content is from an older version: the extension // Flush cached assets if cache content is from an older version: the extension
// always ships with the most up-to-date assets. // always ships with the most up-to-date assets.
@ -640,7 +647,8 @@ return {
'getRepo': readRepoFile, 'getRepo': readRepoFile,
'purge': purgeCache, 'purge': purgeCache,
'put': writeLocalFile, 'put': writeLocalFile,
'update': updateFromRemote 'update': updateFromRemote,
'entries': cacheEntries
}; };
/******************************************************************************/ /******************************************************************************/

View File

@ -235,14 +235,26 @@ var onMessage = function(request, sender, callback) {
var getLists = function(callback) { var getLists = function(callback) {
var µb = µBlock; var µb = µBlock;
var onReceived = function(lists) { var r = {
callback({ available: null,
available: lists,
current: µb.remoteBlacklists, current: µb.remoteBlacklists,
cosmetic: µb.userSettings.parseAllABPHideFilters cosmetic: µb.userSettings.parseAllABPHideFilters,
}); cache: null
}; };
µb.getAvailableLists(onReceived); var onEntries = function(entries) {
r.cache = entries;
if ( r.available ) {
callback(r);
}
};
var onLists = function(lists) {
r.available = lists;
if ( r.cache ) {
callback(r);
}
};
µb.getAvailableLists(onLists);
µb.assets.entries(onEntries);
}; };
/******************************************************************************/ /******************************************************************************/
@ -269,6 +281,10 @@ var onMessage = function(request, sender, callback) {
var response; var response;
switch ( request.what ) { switch ( request.what ) {
case 'purgeCache':
µb.assets.purge(request.path);
break;
default: default:
return µb.messaging.defaultHandler(request, sender, callback); return µb.messaging.defaultHandler(request, sender, callback);
} }