/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
Copyright (C) 2014 Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/
/* global chrome, messaging, uDom */
/******************************************************************************/
(function() {
/******************************************************************************/
var userListName = chrome.i18n.getMessage('1pPageName');
var listDetails = {};
var parseCosmeticFilters = true;
var externalLists = '';
/******************************************************************************/
messaging.start('3p-filters.js');
var onMessage = function(msg) {
switch ( msg.what ) {
case 'loadUbiquitousBlacklistCompleted':
renderBlacklists();
selectedBlacklistsChanged();
break;
default:
break;
}
};
messaging.listen(onMessage);
/******************************************************************************/
var getµb = function() {
return chrome.extension.getBackgroundPage().µBlock;
};
/******************************************************************************/
var renderNumber = function(value) {
return value.toLocaleString();
};
/******************************************************************************/
// TODO: get rid of background page dependencies
var renderBlacklists = function() {
// empty list first
var µb = getµb();
uDom('#listsOfBlockedHostsPrompt').text(
chrome.i18n.getMessage('3pListsOfBlockedHostsPrompt')
.replace('{{netFilterCount}}', renderNumber(µb.abpFilters.getFilterCount()))
.replace('{{cosmeticFilterCount}}', renderNumber(µb.abpHideFilters.getFilterCount()))
);
// Assemble a pretty blacklist name if possible
var htmlFromListName = function(blacklistTitle, blacklistHref) {
if ( blacklistHref === µb.userFiltersPath ) {
return userListName;
}
if ( !blacklistTitle ) {
return blacklistHref;
}
if ( blacklistHref.indexOf('assets/thirdparties/') !== 0 ) {
return blacklistTitle;
}
var matches = blacklistHref.match(/^assets\/thirdparties\/([^\/]+)/);
if ( matches === null || matches.length !== 2 ) {
return blacklistTitle;
}
var hostname = matches[1];
var domain = µb.URI.domainFromHostname(hostname);
if ( domain === '' ) {
return blacklistTitle;
}
var html = [
blacklistTitle,
' (',
domain,
')'
];
return html.join('');
};
var listStatsTemplate = chrome.i18n.getMessage('3pListsOfBlockedHostsPerListStats');
var htmlFromBranch = function(groupKey, listKeys, lists) {
var html = [
'