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

Delta Between Two Patch Sets: background.js

Issue 4864767881641984: Issue 1528 - Implemented backend for general tab of new options page (Closed)
Left Patch Set: Created Jan. 21, 2015, 6:04 p.m.
Right Patch Set: Created June 8, 2015, 4:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « README.md ('k') | ext/background.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 13 matching lines...) Expand all
24 var params = window.location.search.substr(1).split("&"); 24 var params = window.location.search.substr(1).split("&");
25 for (var i = 0; i < params.length; i++) 25 for (var i = 0; i < params.length; i++)
26 { 26 {
27 var parts = params[i].split("=", 2); 27 var parts = params[i].split("=", 2);
28 if (parts.length == 2 && parts[0] in data) 28 if (parts.length == 2 && parts[0] in data)
29 data[parts[0]] = decodeURIComponent(parts[1]); 29 data[parts[0]] = decodeURIComponent(parts[1]);
30 } 30 }
31 } 31 }
32 } 32 }
33 33
34 var subscriptions =[
35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
38 "~user~786254"
39 ];
40 var filters = [
41 {text: "@@||alternate.de^$document"},
42 {text: "@@||der.postillion.com^$document"},
43 {text: "@@||taz.de^$document"},
44 {text: "@@||amazon.de^$document"}
45 ];
46
47 var modules = {}; 34 var modules = {};
48 global.require = function(module) 35 global.require = function(module)
49 { 36 {
50 return modules[module]; 37 return modules[module];
51 }; 38 };
52 39
53 modules.utils = { 40 modules.utils = {
54 Utils: { 41 Utils: {
55 getDocLink: function(link) 42 getDocLink: function(link)
56 { 43 {
(...skipping 10 matching lines...) Expand all
67 54
68 modules.subscriptionClasses = { 55 modules.subscriptionClasses = {
69 Subscription: function(url) 56 Subscription: function(url)
70 { 57 {
71 this.url = url; 58 this.url = url;
72 this.title = "Subscription " + url; 59 this.title = "Subscription " + url;
73 this.disabled = false; 60 this.disabled = false;
74 this.lastDownload = 1234; 61 this.lastDownload = 1234;
75 }, 62 },
76 63
77 SpecialSubscription: function(url) { 64 SpecialSubscription: function(url)
65 {
78 this.url = url; 66 this.url = url;
79 this.disabled = false; 67 this.disabled = false;
80 this.filters = filters.slice(); 68 this.filters = knownFilters.slice();
81 } 69 }
82 }; 70 };
83 modules.subscriptionClasses.Subscription.fromURL = function(url) 71 modules.subscriptionClasses.Subscription.fromURL = function(url)
84 { 72 {
85 if (/^https?:\/\//.test(url)) 73 if (/^https?:\/\//.test(url))
86 return new modules.subscriptionClasses.Subscription(url); 74 return new modules.subscriptionClasses.Subscription(url);
87 else 75 else
88 return new modules.subscriptionClasses.SpecialSubscription(url); 76 return new modules.subscriptionClasses.SpecialSubscription(url);
89 }; 77 };
90 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription; 78 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription;
91 79
92 modules.filterStorage = { 80 modules.filterStorage = {
93 FilterStorage: { 81 FilterStorage: {
94 get subscriptions() 82 get subscriptions()
95 { 83 {
96 return subscriptions.map(modules.subscriptionClasses.Subscription.fromUR L); 84 var subscriptions = [];
85 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions)
86 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]);
87 return subscriptions;
97 }, 88 },
98 89
99 get knownSubscriptions() 90 get knownSubscriptions()
100 { 91 {
101 var result = {}; 92 return knownSubscriptions;
102 for (var i = 0; i < subscriptions.length; i++)
103 result[subscriptions[i]] = modules.subscriptionClasses.Subscription.fr omURL(subscriptions[i]);
104 return result;
105 }, 93 },
106 94
107 addSubscription: function(subscription) 95 addSubscription: function(subscription)
108 { 96 {
109 var index = subscriptions.indexOf(subscription.url); 97 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc riptions))
110 if (index < 0) 98 {
111 { 99 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub scription.fromURL(subscription.url);
112 subscriptions.push(subscription.url);
113 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a dded", subscription); 100 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a dded", subscription);
114 } 101 }
115 }, 102 },
116 103
117 removeSubscription: function(subscription) 104 removeSubscription: function(subscription)
118 { 105 {
119 var index = subscriptions.indexOf(subscription.url); 106 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri ptions)
120 if (index >= 0) 107 {
121 { 108 delete knownSubscriptions[subscription.url];
122 subscriptions.splice(index, 1);
123 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r emoved", subscription); 109 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r emoved", subscription);
124 } 110 }
125 }, 111 },
126 112
127 addFilter: function(filter) 113 addFilter: function(filter)
128 { 114 {
129 var subscription = Subscription.fromURL("~user~786254"); 115 for (var i = 0; i < customSubscription.filters.length; i++)
saroyanm 2015/01/26 19:44:06 Subscription is not defined here, this needs to be
Thomas Greiner 2015/01/27 13:01:07 Done.
130 var index = subscription.filters.indexOf(filter); 116 {
131 if (index < 0) 117 if (customSubscription.filters[i].text == filter.text)
132 { 118 return;
133 subscription.filters.push(filter); 119 }
134 modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", filter); 120 customSubscription.filters.push(filter);
135 } 121 modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", f ilter);
136 }, 122 },
137 123
138 removeFilter: function(filter) 124 removeFilter: function(filter)
139 { 125 {
140 var subscription = Subscription.fromURL("~user~786254"); 126 for (var i = 0; i < customSubscription.filters.length; i++)
saroyanm 2015/01/26 19:44:06 Subscription is not defined here, this needs to be
Thomas Greiner 2015/01/27 13:01:07 Done.
141 var index = subscription.filters.indexOf(filter); 127 {
142 if (index >= 0) 128 if (customSubscription.filters[i].text == filter.text)
143 { 129 {
144 subscription.filters.splice(index, 1); 130 customSubscription.filters.splice(i, 1);
145 modules.filterNotifier.FilterNotifier.triggerListeners("filter.removed ", filter); 131 modules.filterNotifier.FilterNotifier.triggerListeners("filter.remov ed", filter);
132 return;
133 }
146 } 134 }
147 } 135 }
148 } 136 }
149 }; 137 };
150 138
151 modules.filterClasses = { 139 modules.filterClasses = {
152 BlockingFilter: function() {}, 140 BlockingFilter: function() {},
153 Filter: function(text) 141 Filter: function(text)
154 { 142 {
155 this.text = text; 143 this.text = text;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 for (var i = 0; i < listeners.length; i++) 191 for (var i = 0; i < listeners.length; i++)
204 listeners[i].apply(null, args); 192 listeners[i].apply(null, args);
205 } 193 }
206 } 194 }
207 }; 195 };
208 196
209 modules.info = { 197 modules.info = {
210 platform: "gecko", 198 platform: "gecko",
211 platformVersion: "34.0", 199 platformVersion: "34.0",
212 application: "firefox", 200 application: "firefox",
213 applicationVersion: "34.0" 201 applicationVersion: "34.0",
202 addonName: "adblockplus",
203 addonVersion: "2.6.7"
214 }; 204 };
215 updateFromURL(modules.info); 205 updateFromURL(modules.info);
216 206
217 global.Services = { 207 global.Services = {
218 vc: { 208 vc: {
219 compare: function(v1, v2) 209 compare: function(v1, v2)
220 { 210 {
221 return parseFloat(v1) - parseFloat(v2); 211 return parseFloat(v1) - parseFloat(v2);
222 } 212 }
223 } 213 }
224 }; 214 };
215
216 var filters = [
217 "@@||alternate.de^$document",
218 "@@||der.postillion.com^$document",
219 "@@||taz.de^$document",
220 "@@||amazon.de^$document"
221 ];
222 var knownFilters = filters.map(modules.filterClasses.Filter.fromText);
223
224 var subscriptions = [
225 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
226 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
227 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
228 "~user~786254"
229 ];
230 var knownSubscriptions = Object.create(null);
231 for (var subscriptionUrl of subscriptions)
232 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl);
Thomas Greiner 2015/06/08 16:12:43 FYI: This is basically the same what I did with `A
233 var customSubscription = knownSubscriptions["~user~786254"];
225 234
226 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; 235 var issues = {seenDataCorruption: false, filterlistsReinitialized: false};
227 updateFromURL(issues); 236 updateFromURL(issues);
228 global.seenDataCorruption = issues.seenDataCorruption; 237 global.seenDataCorruption = issues.seenDataCorruption;
229 global.filterlistsReinitialized = issues.filterlistsReinitialized; 238 global.filterlistsReinitialized = issues.filterlistsReinitialized;
239
240 var events = {addSubscription: false};
241 updateFromURL(events);
242 if (events.addSubscription)
243 {
244 // We don't know how long it will take for the page to fully load
245 // so we'll post the message after one second
246 setTimeout(function()
247 {
248 window.postMessage({
249 type: "message",
250 payload: {
251 title: "Custom subscription",
252 url: "http://example.com/custom.txt",
253 type: "add-subscription"
254 }
255 }, "*");
256 }, 1000);
257 }
230 })(this); 258 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld