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-2016 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
(...skipping 10 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 =[ | 34 var params = { |
35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", | 35 blockedURLs: "", |
36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", | 36 seenDataCorruption: false, |
37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" | 37 filterlistsReinitialized: false, |
38 ]; | 38 addSubscription: false, |
| 39 filterError: false |
| 40 }; |
| 41 updateFromURL(params); |
39 | 42 |
40 var modules = {}; | 43 var modules = {}; |
41 global.require = function(module) | 44 global.require = function(module) |
42 { | 45 { |
43 return modules[module]; | 46 return modules[module]; |
44 }; | 47 }; |
45 | 48 |
46 modules.utils = { | 49 modules.utils = { |
47 Utils: { | 50 Utils: { |
48 getDocLink: function(link) | 51 getDocLink: function(link) |
49 { | 52 { |
50 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin
k); | 53 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin
k); |
51 } | 54 }, |
| 55 get appLocale() |
| 56 { |
| 57 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); |
| 58 } |
| 59 } |
| 60 }; |
| 61 |
| 62 modules.prefs = { |
| 63 Prefs: { |
| 64 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org
/exceptionrules.txt" |
52 } | 65 } |
53 }; | 66 }; |
54 | 67 |
55 modules.subscriptionClasses = { | 68 modules.subscriptionClasses = { |
56 Subscription: function(url) | 69 Subscription: function(url) |
57 { | 70 { |
58 this.url = url; | 71 this.url = url; |
59 this.title = "Subscription " + url; | 72 this.title = "Subscription " + url; |
60 this.disabled = false; | 73 this.disabled = false; |
61 this.lastDownload = 1234; | 74 this.lastDownload = 1234; |
62 }, | 75 }, |
63 | 76 |
64 SpecialSubscription: function() {} | 77 SpecialSubscription: function(url) |
| 78 { |
| 79 this.url = url; |
| 80 this.disabled = false; |
| 81 this.filters = knownFilters.slice(); |
| 82 } |
65 }; | 83 }; |
66 modules.subscriptionClasses.Subscription.fromURL = function(url) | 84 modules.subscriptionClasses.Subscription.fromURL = function(url) |
67 { | 85 { |
68 return new modules.subscriptionClasses.Subscription(url); | 86 if (/^https?:\/\//.test(url)) |
| 87 return new modules.subscriptionClasses.Subscription(url); |
| 88 else |
| 89 return new modules.subscriptionClasses.SpecialSubscription(url); |
69 }; | 90 }; |
70 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla
sses.Subscription; | 91 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla
sses.Subscription; |
71 | 92 |
72 modules.filterStorage = { | 93 modules.filterStorage = { |
73 FilterStorage: { | 94 FilterStorage: { |
74 get subscriptions() | 95 get subscriptions() |
75 { | 96 { |
76 return subscriptions.map(modules.subscriptionClasses.Subscription.fromUR
L); | 97 var subscriptions = []; |
| 98 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions) |
| 99 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti
ons[url]); |
| 100 return subscriptions; |
77 }, | 101 }, |
78 | 102 |
79 get knownSubscriptions() | 103 get knownSubscriptions() |
80 { | 104 { |
81 var result = {}; | 105 return knownSubscriptions; |
82 for (var i = 0; i < subscriptions.length; i++) | |
83 result[subscriptions[i]] = modules.subscriptionClasses.Subscription.fr
omURL(subscriptions[i]); | |
84 return result; | |
85 }, | 106 }, |
86 | 107 |
87 addSubscription: function(subscription) | 108 addSubscription: function(subscription) |
88 { | 109 { |
89 var index = subscriptions.indexOf(subscription.url); | 110 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc
riptions)) |
90 if (index < 0) | |
91 { | 111 { |
92 subscriptions.push(subscription.url); | 112 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub
scription.fromURL(subscription.url); |
93 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a
dded", subscription); | 113 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a
dded", subscription); |
94 } | 114 } |
95 }, | 115 }, |
96 | 116 |
97 removeSubscription: function(subscription) | 117 removeSubscription: function(subscription) |
98 { | 118 { |
99 var index = subscriptions.indexOf(subscription.url); | 119 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri
ptions) |
100 if (index >= 0) | |
101 { | 120 { |
102 subscriptions.splice(index, 1); | 121 delete knownSubscriptions[subscription.url]; |
103 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r
emoved", subscription); | 122 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r
emoved", subscription); |
104 } | 123 } |
105 }, | 124 }, |
106 | 125 |
107 addFilter: function() {}, | 126 addFilter: function(filter) |
108 removeFilter: function() {} | 127 { |
| 128 for (var i = 0; i < customSubscription.filters.length; i++) |
| 129 { |
| 130 if (customSubscription.filters[i].text == filter.text) |
| 131 return; |
| 132 } |
| 133 customSubscription.filters.push(filter); |
| 134 modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", f
ilter); |
| 135 }, |
| 136 |
| 137 removeFilter: function(filter) |
| 138 { |
| 139 for (var i = 0; i < customSubscription.filters.length; i++) |
| 140 { |
| 141 if (customSubscription.filters[i].text == filter.text) |
| 142 { |
| 143 customSubscription.filters.splice(i, 1); |
| 144 modules.filterNotifier.FilterNotifier.triggerListeners("filter.remov
ed", filter); |
| 145 return; |
| 146 } |
| 147 } |
| 148 } |
109 } | 149 } |
110 }; | 150 }; |
111 | 151 |
112 modules.filterClasses = { | 152 modules.filterClasses = { |
| 153 BlockingFilter: function() {}, |
113 Filter: function(text) | 154 Filter: function(text) |
114 { | 155 { |
115 this.text = text; | 156 this.text = text; |
| 157 this.disabled = false; |
| 158 } |
| 159 }; |
| 160 modules.filterClasses.Filter.fromText = function(text) |
| 161 { |
| 162 return new modules.filterClasses.Filter(text); |
| 163 }; |
| 164 |
| 165 modules.filterValidation = |
| 166 { |
| 167 parseFilter: function(text) |
| 168 { |
| 169 if (params.filterError) |
| 170 return {error: "Invalid filter"}; |
| 171 return {filter: modules.filterClasses.Filter.fromText(text)}; |
116 }, | 172 }, |
117 BlockingFilter: function() {} | 173 parseFilters: function(text) |
118 }; | 174 { |
119 modules.filterClasses.Filter.fromText = function(text) | 175 if (params.filterError) |
120 { | 176 return {errors: ["Invalid filter"]}; |
121 return new modules.filterClasses.Filter(text); | 177 return { |
| 178 filters: text.split("\n") |
| 179 .filter(function(filter) {return !!filter;}) |
| 180 .map(modules.filterClasses.Filter.fromText), |
| 181 errors: [] |
| 182 }; |
| 183 } |
122 }; | 184 }; |
123 | 185 |
124 modules.synchronizer = { | 186 modules.synchronizer = { |
125 Synchronizer: {} | 187 Synchronizer: {} |
126 }; | 188 }; |
127 | 189 |
128 modules.matcher = { | 190 modules.matcher = { |
129 defaultMatcher: { | 191 defaultMatcher: { |
130 matchesAny: function(url, requestType, docDomain, thirdParty) | 192 matchesAny: function(url, requestType, docDomain, thirdParty) |
131 { | 193 { |
132 var params = {blockedURLs: ""}; | |
133 updateFromURL(params); | |
134 var blocked = params.blockedURLs.split(","); | 194 var blocked = params.blockedURLs.split(","); |
135 if (blocked.indexOf(url) >= 0) | 195 if (blocked.indexOf(url) >= 0) |
136 return new modules.filterClasses.BlockingFilter(); | 196 return new modules.filterClasses.BlockingFilter(); |
137 else | 197 else |
138 return null; | 198 return null; |
139 } | 199 } |
140 } | 200 } |
141 }; | 201 }; |
142 | 202 |
| 203 modules.cssRules = { |
| 204 CSSRules: { |
| 205 getRulesForDomain: function(domain) { } |
| 206 } |
| 207 }; |
| 208 |
143 var notifierListeners = []; | 209 var notifierListeners = []; |
144 modules.filterNotifier = { | 210 modules.filterNotifier = { |
145 FilterNotifier: { | 211 FilterNotifier: { |
146 addListener: function(listener) | 212 addListener: function(listener) |
147 { | 213 { |
148 if (notifierListeners.indexOf(listener) < 0) | 214 if (notifierListeners.indexOf(listener) < 0) |
149 notifierListeners.push(listener); | 215 notifierListeners.push(listener); |
150 }, | 216 }, |
151 | 217 |
152 removeListener: function(listener) | 218 removeListener: function(listener) |
153 { | 219 { |
154 var index = notifierListeners.indexOf(listener); | 220 var index = notifierListeners.indexOf(listener); |
155 if (index >= 0) | 221 if (index >= 0) |
156 notifierListeners.splice(index, 1); | 222 notifierListeners.splice(index, 1); |
157 }, | 223 }, |
158 | 224 |
159 triggerListeners: function() | 225 triggerListeners: function() |
160 { | 226 { |
161 var args = Array.prototype.slice.apply(arguments); | 227 var args = Array.prototype.slice.apply(arguments); |
162 var listeners = notifierListeners.slice(); | 228 var listeners = notifierListeners.slice(); |
163 for (var i = 0; i < listeners.length; i++) | 229 for (var i = 0; i < listeners.length; i++) |
164 listeners[i].apply(null, args); | 230 listeners[i].apply(null, args); |
165 } | 231 } |
166 } | 232 } |
167 }; | 233 }; |
168 | 234 |
169 modules.devtools = { | |
170 initDevToolsPanel: function(page, inspectedTabId) | |
171 { | |
172 // blocked request | |
173 page.sendMessage({ | |
174 type: "add-record", | |
175 request: { | |
176 url: "http://adserver.example.com/ad_banner.png", | |
177 type: "IMAGE", | |
178 docDomain: "example.com" | |
179 }, | |
180 filter: { | |
181 text: "/ad_banner*$domain=example.com", | |
182 whitelisted: false, | |
183 userDefined: false, | |
184 subscription: "EasyList" | |
185 } | |
186 }); | |
187 | |
188 // whiletisted request | |
189 page.sendMessage({ | |
190 type: "add-record", | |
191 request: { | |
192 url: "http://example.com/looks_like_an_ad_but_isnt_one.html", | |
193 type: "SUBDOCUMENT", | |
194 docDomain: "example.com" | |
195 }, | |
196 filter: { | |
197 text: "@@||example.com/looks_like_an_ad_but_isnt_one.html", | |
198 whitelisted: true, | |
199 userDefined: false, | |
200 subscription: "EasyList" | |
201 } | |
202 }); | |
203 | |
204 // request with long URL and no filter matches | |
205 page.sendMessage({ | |
206 type: "add-record", | |
207 request: { | |
208 url: "https://this.url.has.a.long.domain/and_a_long_path_maybe_not_lon
g_enough_so_i_keep_typing?there=are&a=couple&of=parameters&as=well&and=even&some
=more", | |
209 type: "XMLHTTPREQUEST", | |
210 docDomain: "example.com" | |
211 }, | |
212 filter: null | |
213 }); | |
214 | |
215 // matching element hiding filter | |
216 page.sendMessage({ | |
217 type: "add-record", | |
218 request: { | |
219 type: "ELEMHIDE", | |
220 docDomain: "example.com" | |
221 }, | |
222 filter: { | |
223 text: "example.com##.ad_banner", | |
224 whitelisted: false, | |
225 userDefined: false, | |
226 subscription: "EasyList" | |
227 } | |
228 }); | |
229 | |
230 // user-defined filter | |
231 page.sendMessage({ | |
232 type: "add-record", | |
233 request: { | |
234 url: "http://example.com/some-annoying-popup", | |
235 type: "POPUP", | |
236 docDomain: "example.com" | |
237 }, | |
238 filter: { | |
239 text: "||example.com/some-annoying-popup$popup", | |
240 whitelisted: false, | |
241 userDefined: true, | |
242 subscription: null | |
243 } | |
244 }); | |
245 } | |
246 }; | |
247 | |
248 modules.info = { | 235 modules.info = { |
249 platform: "gecko", | 236 platform: "gecko", |
250 platformVersion: "34.0", | 237 platformVersion: "34.0", |
251 application: "firefox", | 238 application: "firefox", |
252 applicationVersion: "34.0" | 239 applicationVersion: "34.0", |
| 240 addonName: "adblockplus", |
| 241 addonVersion: "2.6.7" |
253 }; | 242 }; |
254 updateFromURL(modules.info); | 243 updateFromURL(modules.info); |
255 | 244 |
256 global.Services = { | 245 global.Services = { |
257 vc: { | 246 vc: { |
258 compare: function(v1, v2) | 247 compare: function(v1, v2) |
259 { | 248 { |
260 return parseFloat(v1) - parseFloat(v2); | 249 return parseFloat(v1) - parseFloat(v2); |
261 } | 250 } |
262 } | 251 } |
263 }; | 252 }; |
264 | 253 |
265 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; | 254 var filters = [ |
266 updateFromURL(issues); | 255 "@@||alternate.de^$document", |
267 global.seenDataCorruption = issues.seenDataCorruption; | 256 "@@||der.postillion.com^$document", |
268 global.filterlistsReinitialized = issues.filterlistsReinitialized; | 257 "@@||taz.de^$document", |
| 258 "@@||amazon.de^$document", |
| 259 "||biglemon.am/bg_poster/banner.jpg", |
| 260 "winfuture.de###header_logo_link", |
| 261 "###WerbungObenRechts10_GesamtDIV", |
| 262 "###WerbungObenRechts8_GesamtDIV", |
| 263 "###WerbungObenRechts9_GesamtDIV", |
| 264 "###WerbungUntenLinks4_GesamtDIV", |
| 265 "###WerbungUntenLinks7_GesamtDIV", |
| 266 "###WerbungUntenLinks8_GesamtDIV", |
| 267 "###WerbungUntenLinks9_GesamtDIV", |
| 268 "###Werbung_Sky", |
| 269 "###Werbung_Wide", |
| 270 "###__ligatus_placeholder__", |
| 271 "###ad-bereich1-08", |
| 272 "###ad-bereich1-superbanner", |
| 273 "###ad-bereich2-08", |
| 274 "###ad-bereich2-skyscrapper" |
| 275 ]; |
| 276 var knownFilters = filters.map(modules.filterClasses.Filter.fromText); |
| 277 |
| 278 var subscriptions = [ |
| 279 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", |
| 280 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", |
| 281 "https://easylist-downloads.adblockplus.org/fanboy-social.txt", |
| 282 "~user~786254" |
| 283 ]; |
| 284 var knownSubscriptions = Object.create(null); |
| 285 for (var subscriptionUrl of subscriptions) |
| 286 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti
on.fromURL(subscriptionUrl); |
| 287 var customSubscription = knownSubscriptions["~user~786254"]; |
| 288 |
| 289 global.seenDataCorruption = params.seenDataCorruption; |
| 290 global.filterlistsReinitialized = params.filterlistsReinitialized; |
| 291 |
| 292 if (params.addSubscription) |
| 293 { |
| 294 // We don't know how long it will take for the page to fully load |
| 295 // so we'll post the message after one second |
| 296 setTimeout(function() |
| 297 { |
| 298 window.postMessage({ |
| 299 type: "message", |
| 300 payload: { |
| 301 title: "Custom subscription", |
| 302 url: "http://example.com/custom.txt", |
| 303 type: "add-subscription" |
| 304 } |
| 305 }, "*"); |
| 306 }, 1000); |
| 307 } |
| 308 |
| 309 ext.devtools.onCreated.addListener(function(panel) |
| 310 { |
| 311 // blocked request |
| 312 panel.sendMessage({ |
| 313 type: "add-record", |
| 314 request: { |
| 315 url: "http://adserver.example.com/ad_banner.png", |
| 316 type: "IMAGE", |
| 317 docDomain: "example.com" |
| 318 }, |
| 319 filter: { |
| 320 text: "/ad_banner*$domain=example.com", |
| 321 whitelisted: false, |
| 322 userDefined: false, |
| 323 subscription: "EasyList" |
| 324 } |
| 325 }); |
| 326 |
| 327 // whitelisted request |
| 328 panel.sendMessage({ |
| 329 type: "add-record", |
| 330 request: { |
| 331 url: "http://example.com/looks_like_an_ad_but_isnt_one.html", |
| 332 type: "SUBDOCUMENT", |
| 333 docDomain: "example.com" |
| 334 }, |
| 335 filter: { |
| 336 text: "@@||example.com/looks_like_an_ad_but_isnt_one.html", |
| 337 whitelisted: true, |
| 338 userDefined: false, |
| 339 subscription: "EasyList" |
| 340 } |
| 341 }); |
| 342 |
| 343 // request with long URL and no filter matches |
| 344 panel.sendMessage({ |
| 345 type: "add-record", |
| 346 request: { |
| 347 url: "https://this.url.has.a.long.domain/and_a_long_path_maybe_not_long_
enough_so_i_keep_typing?there=are&a=couple&of=parameters&as=well&and=even&some=m
ore", |
| 348 type: "XMLHTTPREQUEST", |
| 349 docDomain: "example.com" |
| 350 }, |
| 351 filter: null |
| 352 }); |
| 353 |
| 354 // matching element hiding filter |
| 355 panel.sendMessage({ |
| 356 type: "add-record", |
| 357 request: { |
| 358 type: "ELEMHIDE", |
| 359 docDomain: "example.com" |
| 360 }, |
| 361 filter: { |
| 362 text: "example.com##.ad_banner", |
| 363 whitelisted: false, |
| 364 userDefined: false, |
| 365 subscription: "EasyList" |
| 366 } |
| 367 }); |
| 368 |
| 369 // user-defined filter |
| 370 panel.sendMessage({ |
| 371 type: "add-record", |
| 372 request: { |
| 373 url: "http://example.com/some-annoying-popup", |
| 374 type: "POPUP", |
| 375 docDomain: "example.com" |
| 376 }, |
| 377 filter: { |
| 378 text: "||example.com/some-annoying-popup$popup", |
| 379 whitelisted: false, |
| 380 userDefined: true, |
| 381 subscription: null |
| 382 } |
| 383 }); |
| 384 }); |
269 })(this); | 385 })(this); |
LEFT | RIGHT |