Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

Commit 9d7b3f6

Browse files
committed
this fixes #218 and more
1 parent d60e42a commit 9d7b3f6

File tree

5 files changed

+70
-64
lines changed

5 files changed

+70
-64
lines changed

js/background.js

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
Home: https://github.com/gorhill/httpswitchboard
2020
*/
2121

22+
/* global chrome */
23+
2224
/******************************************************************************/
2325

2426
var HTTPSB = {
@@ -67,47 +69,9 @@ var HTTPSB = {
6769
'assets/user/ubiquitous-blacklisted-hosts.txt': {},
6870

6971
// HTTPSB
70-
'assets/httpsb/blacklist.txt': {},
71-
72-
// Third parties
73-
74-
// Various
75-
'assets/thirdparties/mirror1.malwaredomains.com/files/immortal_domains.txt': {},
76-
'assets/thirdparties/mirror1.malwaredomains.com/files/justdomains': {},
77-
'assets/thirdparties/pgl.yoyo.org/as/serverlist': {},
78-
'assets/thirdparties/www.malwaredomainlist.com/hostslist/hosts.txt': {},
79-
'assets/thirdparties/hosts-file.net/ad-servers': {},
80-
'assets/thirdparties/someonewhocares.org/hosts/hosts': {},
81-
82-
// Various
83-
'assets/thirdparties/winhelp2002.mvps.org/hosts.txt': {},
84-
85-
// From here on, any new list is 'off' by default
86-
// Adblock Plus
87-
'assets/thirdparties/easylist-downloads.adblockplus.org/easylist.txt': {},
88-
'assets/thirdparties/easylist-downloads.adblockplus.org/easyprivacy.txt': {},
89-
'assets/thirdparties/easylist-downloads.adblockplus.org/fanboy-annoyance.txt': { off: true },
90-
91-
// Fanboy
92-
'assets/thirdparties/www.fanboy.co.nz/enhancedstats.txt': { off: true },
93-
94-
'assets/thirdparties/easylist-downloads.adblockplus.org/easylistgermany.txt': { off: true },
95-
'assets/thirdparties/easylist-downloads.adblockplus.org/easylistitaly.txt': { off: true },
96-
'assets/thirdparties/easylist-downloads.adblockplus.org/easylistdutch.txt': { off: true },
97-
'assets/thirdparties/easylist-downloads.adblockplus.org/liste_fr.txt': { off: true },
98-
'assets/thirdparties/easylist-downloads.adblockplus.org/advblock.txt': { off: true },
99-
'assets/thirdparties/easylist-downloads.adblockplus.org/easylistchina.txt': { off: true },
100-
'assets/thirdparties/adblock-chinalist.googlecode.com/svn/trunk/adblock.txt': { off: true },
101-
'assets/thirdparties/adblock-plus-japanese-filter.googlecode.com/hg/abp_jp.txt': { off: true },
102-
'assets/thirdparties/stanev.org/abp/adblock_bg.txt': { off: true },
103-
'assets/thirdparties/indonesianadblockrules.googlecode.com/hg/subscriptions/abpindo.txt': { off: true },
104-
'assets/thirdparties/liste-ar-adblock.googlecode.com/hg/Liste_AR.txt': { off: true },
105-
'assets/thirdparties/adblock-czechoslovaklist.googlecode.com/svn/filters.txt': { off: true },
106-
// 'assets/thirdparties/gitorious.org/adblock-latvian/adblock-latvian/raw/5f5fc83eb1a2d0e97df9a5c382febaa651511757%3Alists/latvian-list.txt': { off: true },
107-
'assets/thirdparties/raw.github.com/AdBlockPlusIsrael/EasyListHebrew/master/EasyListHebrew.txt': { off: true },
108-
'assets/thirdparties/download.wiltteri.net/wiltteri.txt': { off: true },
109-
110-
'assets/thirdparties/hosts-file.net/hosts.txt': { off: true }
72+
'assets/httpsb/blacklist.txt': { title: 'HTTP Switchboard' },
73+
74+
// 3rd-party lists now fetched dynamically
11175
},
11276

11377
// urls stats are kept on the back burner while waiting to be reactivated

js/storage.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,14 @@ HTTPSB.loadUbiquitousBlacklists = function() {
212212
}
213213
if ( details.what === 'mergeUbiquitousBlacklist' ) {
214214
mergeBlacklist(details);
215+
return;
216+
}
217+
if ( details.what === 'listOfBlockListsLoaded' ) {
218+
onListOfBlockListsLoaded(details);
219+
return;
215220
}
216221
};
222+
chrome.runtime.onMessage.addListener(onMessageHandler);
217223

218224
var removeObsoleteBlacklistsHandler = function(store) {
219225
if ( !store.remoteBlacklists ) {
@@ -271,22 +277,18 @@ HTTPSB.loadUbiquitousBlacklists = function() {
271277
// Load each preset blacklist which is not disabled.
272278
var location;
273279
while ( location = blacklistLocations.pop() ) {
274-
// rhill 2014-01-24: HTTPSB-maintained lists sit now in their
275-
// own directory, "asset/httpsb/". Ensure smooth transition.
276-
// TODO: Remove this code when everybody upgraded beyond 0.7.7.1
277-
if ( location === 'assets/httpsb-blacklist.txt' && store.remoteBlacklists[location].off === true ) {
278-
// In case it was already processed
279-
httpsb.remoteBlacklists['assets/httpsb/blacklist.txt'].off = true;
280-
// In case it was not yet processed
281-
store.remoteBlacklists['assets/httpsb/blacklist.txt'].off = true;
282-
}
283280
// If loaded list location is not part of default list locations,
284281
// remove its entry from local storage.
285282
if ( !httpsb.remoteBlacklists[location] ) {
286283
obsoleteBlacklists.push(location);
287284
blacklistLoadCount -= 1;
288285
continue;
289286
}
287+
// https://github.com/gorhill/httpswitchboard/issues/218
288+
// Transfer potentially existing list title into restored list data.
289+
if ( store.remoteBlacklists[location].title !== httpsb.remoteBlacklists[location].title ) {
290+
store.remoteBlacklists[location].title = httpsb.remoteBlacklists[location].title;
291+
}
290292
// Store details of this preset blacklist
291293
httpsb.remoteBlacklists[location] = store.remoteBlacklists[location];
292294
// rhill 2013-12-09:
@@ -300,13 +302,32 @@ HTTPSB.loadUbiquitousBlacklists = function() {
300302
}
301303
};
302304

303-
chrome.runtime.onMessage.addListener(onMessageHandler);
305+
var onListOfBlockListsLoaded = function(details) {
306+
var httpsb = HTTPSB;
307+
// Initialize built-in list of 3rd-party block lists.
308+
var lists = JSON.parse(details.content);
309+
for ( var location in lists ) {
310+
if ( lists.hasOwnProperty(location) === false ) {
311+
continue;
312+
}
313+
httpsb.remoteBlacklists['assets/thirdparties/' + location] = lists[location];
314+
}
315+
// Now get user's selection of list of block lists.
316+
chrome.storage.local.get(
317+
{ 'remoteBlacklists': httpsb.remoteBlacklists },
318+
loadBlacklistsStart
319+
);
320+
};
304321

305-
// Get remote blacklist data (which may be saved locally).
306-
chrome.storage.local.get(
307-
{ 'remoteBlacklists': this.remoteBlacklists },
308-
loadBlacklistsStart
309-
);
322+
// Reset list of 3rd-party block lists.
323+
for ( var location in this.remoteBlacklists ) {
324+
if ( location.indexOf('assets/thirdparties/') === 0 ) {
325+
delete this.remoteBlacklists[location];
326+
}
327+
}
328+
329+
// Get new list of 3rd-party block lists.
330+
this.assets.get('assets/httpsb/ubiquitous-block-lists.json', 'listOfBlockListsLoaded');
310331
};
311332

312333
/******************************************************************************/

js/ubiquitous-rules.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
Home: https://github.com/gorhill/httpswitchboard
2020
*/
2121

22+
/* global chrome, $ */
23+
2224
/******************************************************************************/
2325

2426
(function() {
@@ -74,27 +76,46 @@ function renderBlacklists() {
7476
.replace('{{ubiquitousBlacklistCount}}', renderNumber(httpsb.ubiquitousBlacklist.count))
7577
);
7678

79+
// Assemble a pretty blacklist name if possible
80+
var prettifyListName = function(blacklistTitle, blacklistHref) {
81+
if ( !blacklistTitle ) {
82+
return blacklistHref;
83+
}
84+
if ( blacklistHref.indexOf('assets/thirdparties/') !== 0 ) {
85+
return blacklistTitle;
86+
}
87+
var matches = blacklistHref.match(/^assets\/thirdparties\/([^\/]+)/);
88+
if ( matches === null || matches.length !== 2 ) {
89+
return blacklistTitle;
90+
}
91+
var domain = httpsb.URI.domainFromHostname(matches[1]);
92+
if ( domain === '' ) {
93+
return blacklistTitle;
94+
}
95+
return blacklistTitle + ' <i>(' + domain + ')</i>';
96+
};
97+
7798
var blacklists = httpsb.remoteBlacklists;
7899
var ul = $('#blacklists');
79100
var keys = Object.keys(blacklists);
80101
var i = keys.length;
81-
var blacklist, blacklistName;
102+
var blacklist, blacklistHref;
82103
var liTemplate = $('#blacklistTemplate .blacklistDetails').first();
83104
var li, child, text;
84105
while ( i-- ) {
85-
blacklistName = keys[i];
86-
blacklist = blacklists[blacklistName];
106+
blacklistHref = keys[i];
107+
blacklist = blacklists[blacklistHref];
87108
li = liTemplate.clone();
88109
child = $('input', li);
89110
child.prop('checked', !blacklist.off);
90111
child = $('a', li);
91112
// Special rendering: user list
92-
if ( blacklistName === httpsb.userBlacklistPath ) {
113+
if ( blacklistHref === httpsb.userBlacklistPath ) {
93114
child.attr('href', userListHref);
94115
child.text($(userListHref).text());
95116
} else {
96-
child.attr('href', encodeURI(blacklistName));
97-
child.text(blacklistName);
117+
child.attr('href', encodeURI(blacklistHref));
118+
child.html(prettifyListName(blacklist.title, blacklistHref));
98119
}
99120
child = $('span', li);
100121
text = child.text()

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "__MSG_extName__",
44
"short_name": "HTTPSB",
5-
"version": "0.9.5.5",
5+
"version": "0.9.5.6",
66
"description": "__MSG_extShortDesc__",
77
"icons": {
88
"16": "icon_16.png",

ubiquitous-rules.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
margin: 0 0 0 1em;
2121
}
2222
.dim {
23-
color: #888;
23+
color: #444;
2424
}
2525
.userUbiquitousHosts {
2626
font-size: smaller;

0 commit comments

Comments
 (0)