LEFT | RIGHT |
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 Loading... |
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 "@@||alternate.de^$document", | |
42 "@@||der.postillion.com^$document", | |
43 "@@||taz.de^$document", | |
44 "@@||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 Loading... |
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.map(modules.filterClasses.Filter.fromText); | 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 var subscriptions = []; | 84 var subscriptions = []; |
97 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions) | 85 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions) |
98 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti
ons[url]); | 86 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti
ons[url]); |
99 return subscriptions; | 87 return subscriptions; |
100 }, | 88 }, |
101 | 89 |
102 get knownSubscriptions() | 90 get knownSubscriptions() |
103 { | 91 { |
104 subscriptions = subscriptions.reduce(function(obj, subscription) | 92 return knownSubscriptions; |
105 { | 93 }, |
106 obj[subscription] = modules.subscriptionClasses.Subscription.fromURL(s
ubscription); | 94 |
107 return obj; | 95 addSubscription: function(subscription) |
108 }, Object.create(null)); | 96 { |
109 | 97 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc
riptions)) |
110 Object.defineProperty(modules.filterStorage.FilterStorage, "knownSubscri
ptions", { | 98 { |
111 get: function() | 99 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub
scription.fromURL(subscription.url); |
| 100 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a
dded", subscription); |
| 101 } |
| 102 }, |
| 103 |
| 104 removeSubscription: function(subscription) |
| 105 { |
| 106 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri
ptions) |
| 107 { |
| 108 delete knownSubscriptions[subscription.url]; |
| 109 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r
emoved", subscription); |
| 110 } |
| 111 }, |
| 112 |
| 113 addFilter: function(filter) |
| 114 { |
| 115 for (var i = 0; i < customSubscription.filters.length; i++) |
| 116 { |
| 117 if (customSubscription.filters[i].text == filter.text) |
| 118 return; |
| 119 } |
| 120 customSubscription.filters.push(filter); |
| 121 modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", f
ilter); |
| 122 }, |
| 123 |
| 124 removeFilter: function(filter) |
| 125 { |
| 126 for (var i = 0; i < customSubscription.filters.length; i++) |
| 127 { |
| 128 if (customSubscription.filters[i].text == filter.text) |
112 { | 129 { |
113 return subscriptions; | 130 customSubscription.filters.splice(i, 1); |
114 } | |
115 }); | |
116 | |
117 return modules.filterStorage.FilterStorage.knownSubscriptions; | |
118 }, | |
119 | |
120 addSubscription: function(subscription) | |
121 { | |
122 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc
riptions)) | |
123 { | |
124 subscriptions[subscription.url] = modules.subscriptionClasses.Subscrip
tion.fromURL(subscription.url); | |
125 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a
dded", subscription); | |
126 } | |
127 }, | |
128 | |
129 removeSubscription: function(subscription) | |
130 { | |
131 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri
ptions) | |
132 { | |
133 delete subscriptions[subscription.url]; | |
134 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r
emoved", subscription); | |
135 } | |
136 }, | |
137 | |
138 addFilter: function(filter) | |
139 { | |
140 var subscription = modules.filterStorage.FilterStorage.knownSubscription
s["~user~786254"]; | |
141 for (var i = 0; i < subscription.filters.length; i++) | |
142 { | |
143 if (subscription.filters[i].text == filter.text) | |
144 return; | |
145 } | |
146 subscription.filters.push(filter); | |
147 modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", f
ilter); | |
148 }, | |
149 | |
150 removeFilter: function(filter) | |
151 { | |
152 var subscription = modules.filterStorage.FilterStorage.knownSubscription
s["~user~786254"]; | |
153 for (var i = 0; i < subscription.filters.length; i++) | |
154 { | |
155 if (subscription.filters[i].text == filter.text) | |
156 { | |
157 subscription.filters.splice(i, 1); | |
158 modules.filterNotifier.FilterNotifier.triggerListeners("filter.remov
ed", filter); | 131 modules.filterNotifier.FilterNotifier.triggerListeners("filter.remov
ed", filter); |
159 return; | 132 return; |
160 } | 133 } |
161 } | 134 } |
162 } | 135 } |
163 } | 136 } |
164 }; | 137 }; |
165 | 138 |
166 modules.filterClasses = { | 139 modules.filterClasses = { |
167 BlockingFilter: function() {}, | 140 BlockingFilter: function() {}, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 listeners[i].apply(null, args); | 192 listeners[i].apply(null, args); |
220 } | 193 } |
221 } | 194 } |
222 }; | 195 }; |
223 | 196 |
224 modules.info = { | 197 modules.info = { |
225 platform: "gecko", | 198 platform: "gecko", |
226 platformVersion: "34.0", | 199 platformVersion: "34.0", |
227 application: "firefox", | 200 application: "firefox", |
228 applicationVersion: "34.0", | 201 applicationVersion: "34.0", |
229 addon: "adblockplus", | 202 addonName: "adblockplus", |
230 addonVersion: "2.6.7" | 203 addonVersion: "2.6.7" |
231 }; | 204 }; |
232 updateFromURL(modules.info); | 205 updateFromURL(modules.info); |
233 | 206 |
234 global.Services = { | 207 global.Services = { |
235 vc: { | 208 vc: { |
236 compare: function(v1, v2) | 209 compare: function(v1, v2) |
237 { | 210 { |
238 return parseFloat(v1) - parseFloat(v2); | 211 return parseFloat(v1) - parseFloat(v2); |
239 } | 212 } |
240 } | 213 } |
241 }; | 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); |
| 233 var customSubscription = knownSubscriptions["~user~786254"]; |
242 | 234 |
243 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; | 235 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; |
244 updateFromURL(issues); | 236 updateFromURL(issues); |
245 global.seenDataCorruption = issues.seenDataCorruption; | 237 global.seenDataCorruption = issues.seenDataCorruption; |
246 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 } |
247 })(this); | 258 })(this); |
LEFT | RIGHT |