Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: background.js

Issue 8626106: Added import of custom filters from old versions (Closed)
Patch Set: Created Oct. 22, 2012, 2:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 with(require("filterClasses")) 1 with(require("filterClasses"))
2 { 2 {
3 this.Filter = Filter; 3 this.Filter = Filter;
4 this.WhitelistFilter = WhitelistFilter; 4 this.WhitelistFilter = WhitelistFilter;
5 } 5 }
6 with(require("subscriptionClasses")) 6 with(require("subscriptionClasses"))
7 { 7 {
8 this.Subscription = Subscription; 8 this.Subscription = Subscription;
9 this.DownloadableSubscription = DownloadableSubscription; 9 this.DownloadableSubscription = DownloadableSubscription;
10 } 10 }
(...skipping 17 matching lines...) Expand all
28 window.localStorage.currentVersion = require("info").addonVersion; 28 window.localStorage.currentVersion = require("info").addonVersion;
29 } 29 }
30 }); 30 });
31 31
32 var toolbarButton; 32 var toolbarButton;
33 var i18nMessages; 33 var i18nMessages;
34 34
35 function importOldData() 35 function importOldData()
36 { 36 {
37 // TODO: Remove this once most people have the update 37 // TODO: Remove this once most people have the update
38 if ("version" in widget.preferences) 38 if ("version" in widget.preferences || "last-version" in widget.preferences)
39 { 39 {
40 var oldLists = { 40 var oldLists = {
41 "fanboy": "https://secure.fanboy.co.nz/fanboy-adblock.txt", 41 "fanboy": "https://secure.fanboy.co.nz/fanboy-adblock.txt",
42 "fanboy-ru": "https://secure.fanboy.co.nz/fanboy-russian.txt", 42 "fanboy-ru": "https://secure.fanboy.co.nz/fanboy-russian.txt",
43 "fanboy-es": "https://secure.fanboy.co.nz/fanboy-espanol.txt", 43 "fanboy-es": "https://secure.fanboy.co.nz/fanboy-espanol.txt",
44 "fanboy-ja": "https://secure.fanboy.co.nz/fanboy-japanese.txt", 44 "fanboy-ja": "https://secure.fanboy.co.nz/fanboy-japanese.txt",
45 "fanboy-cz": "https://secure.fanboy.co.nz/fanboy-czech.txt", 45 "fanboy-cz": "https://secure.fanboy.co.nz/fanboy-czech.txt",
46 "fanboy-tr": "https://secure.fanboy.co.nz/fanboy-turkish.txt", 46 "fanboy-tr": "https://secure.fanboy.co.nz/fanboy-turkish.txt",
47 "fanboy-pl": "https://secure.fanboy.co.nz/fanboy-polish.txt", 47 "fanboy-pl": "https://secure.fanboy.co.nz/fanboy-polish.txt",
48 "fanboy-vi": "https://secure.fanboy.co.nz/fanboy-vietnam.txt", 48 "fanboy-vi": "https://secure.fanboy.co.nz/fanboy-vietnam.txt",
(...skipping 13 matching lines...) Expand all
62 "easy-nl": "https://dutchadblockfilters.googlecode.com/svn/trunk/AdBlock_D utch_hide.txt", 62 "easy-nl": "https://dutchadblockfilters.googlecode.com/svn/trunk/AdBlock_D utch_hide.txt",
63 "easy-ro": "http://www.zoso.ro/pages/rolist.txt", 63 "easy-ro": "http://www.zoso.ro/pages/rolist.txt",
64 "easy-fi": "http://www.wiltteri.net/wiltteri.txt", 64 "easy-fi": "http://www.wiltteri.net/wiltteri.txt",
65 "easy-es": "http://abp.mozilla-hispano.org/nauscopio/filtros.txt", 65 "easy-es": "http://abp.mozilla-hispano.org/nauscopio/filtros.txt",
66 "easy-hu": "http://ajnasz.hu/adblock/recent", 66 "easy-hu": "http://ajnasz.hu/adblock/recent",
67 "adblock-lv": "https://gitorious.org/adblock-latvian/adblock-latvian/blobs /raw/master/lists/latvian-list.txt", 67 "adblock-lv": "https://gitorious.org/adblock-latvian/adblock-latvian/blobs /raw/master/lists/latvian-list.txt",
68 "easy-priv": "https://easylist-downloads.adblockplus.org/easyprivacy.txt", 68 "easy-priv": "https://easylist-downloads.adblockplus.org/easyprivacy.txt",
69 "easy-ru-priv": "https://ruadlist.googlecode.com/svn/trunk/cntblock.txt" 69 "easy-ru-priv": "https://ruadlist.googlecode.com/svn/trunk/cntblock.txt"
70 }; 70 };
71 71
72 // Import filter subscriptions
72 for (var key in oldLists) 73 for (var key in oldLists)
73 { 74 {
74 if (key in widget.preferences) 75 if (key in widget.preferences)
75 { 76 {
76 // Only add subscriptions that were enabled in old version 77 // Only add subscriptions that were enabled in old version
77 if (widget.preferences[key] == "true") 78 if (widget.preferences[key] == "true")
78 { 79 {
79 var subscription = Subscription.fromURL(oldLists[key]); 80 var subscription = Subscription.fromURL(oldLists[key]);
80 if (subscription && !(subscription.url in FilterStorage.knownSubscript ions)) 81 if (subscription && !(subscription.url in FilterStorage.knownSubscript ions))
81 { 82 {
82 FilterStorage.addSubscription(subscription); 83 FilterStorage.addSubscription(subscription);
83 Synchronizer.execute(subscription); 84 Synchronizer.execute(subscription);
84 } 85 }
85 } 86 }
86
87 delete widget.preferences[key];
88 delete widget.preferences[key + "-content"];
89 delete widget.preferences[key + "-time"];
90 } 87 }
91 } 88 }
92 89
93 // TODO: Import custom filters? 90 // Import custom filters
91 if ("personal" in widget.preferences)
92 {
93 var customFilters = widget.preferences.personal.split("\n");
94 for (var i = 0; i < customFilters.length; i++)
95 {
96 var filter = customFilters[i];
97 if (filter === "")
98 continue;
94 99
95 delete widget.preferences.version; 100 if (filter.substr(0, 1) != "*")
101 filter = "|" + filter;
102 if (filter.substr(-1) != "*")
103 filter = filter + "|";
104 FilterStorage.addFilter(Filter.fromText(filter));
105 }
106 }
107
108 // Import custom CSS rules
109 if ("personal-css" in widget.preferences)
110 {
111 var customRules = widget.preferences["personal-css"].split("\n");
112 for (var i = 0; i < customRules.length; i++)
113 {
114 var rule = customRules[i];
115 if (rule === "")
116 continue;
117
118 rule = "##" + rule;
119 FilterStorage.addFilter(Filter.fromText(rule));
120 }
121 }
122
123 widget.preferences.clear();
96 } 124 }
97 } 125 }
98 126
99 function executeFirstRunActions() 127 function executeFirstRunActions()
100 { 128 {
101 // Don't do anything if the user has a subscription already 129 // Don't do anything if the user has a subscription already
102 var hasSubscriptions = FilterStorage.subscriptions.some(function(subscription) {return subscription instanceof DownloadableSubscription}); 130 var hasSubscriptions = FilterStorage.subscriptions.some(function(subscription) {return subscription instanceof DownloadableSubscription});
103 if (hasSubscriptions) 131 if (hasSubscriptions)
104 return; 132 return;
105 133
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 var selectors = ElemHide.getSelectorsForDomain(host, false); 267 var selectors = ElemHide.getSelectorsForDomain(host, false);
240 event.source.postMessage({reqtype: "get-settings-response", selectors: sel ectors}); 268 event.source.postMessage({reqtype: "get-settings-response", selectors: sel ectors});
241 break; 269 break;
242 } 270 }
243 }, false); 271 }, false);
244 272
245 setDefaultOptions(); 273 setDefaultOptions();
246 createToolbarButton(); 274 createToolbarButton();
247 refreshToolbarButton(); 275 refreshToolbarButton();
248 loadI18nMessages(); 276 loadI18nMessages();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld