OLD | NEW |
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 ]; | |
39 | |
40 var modules = {}; | 34 var modules = {}; |
41 global.require = function(module) | 35 global.require = function(module) |
42 { | 36 { |
43 return modules[module]; | 37 return modules[module]; |
44 }; | 38 }; |
45 | 39 |
46 modules.utils = { | 40 modules.utils = { |
47 Utils: { | 41 Utils: { |
48 getDocLink: function(link) | 42 getDocLink: function(link) |
49 { | 43 { |
50 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin
k); | 44 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin
k); |
51 } | 45 } |
52 } | 46 } |
53 }; | 47 }; |
54 | 48 |
| 49 modules.prefs = { |
| 50 Prefs: { |
| 51 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org
/exceptionrules.txt" |
| 52 } |
| 53 } |
| 54 |
55 modules.subscriptionClasses = { | 55 modules.subscriptionClasses = { |
56 Subscription: function(url) | 56 Subscription: function(url) |
57 { | 57 { |
58 this.url = url; | 58 this.url = url; |
59 this.title = "Subscription " + url; | 59 this.title = "Subscription " + url; |
60 this.disabled = false; | 60 this.disabled = false; |
61 this.lastDownload = 1234; | 61 this.lastDownload = 1234; |
62 }, | 62 }, |
63 | 63 |
64 SpecialSubscription: function() {} | 64 SpecialSubscription: function(url) |
| 65 { |
| 66 this.url = url; |
| 67 this.disabled = false; |
| 68 this.filters = knownFilters.slice(); |
| 69 } |
65 }; | 70 }; |
66 modules.subscriptionClasses.Subscription.fromURL = function(url) | 71 modules.subscriptionClasses.Subscription.fromURL = function(url) |
67 { | 72 { |
68 return new modules.subscriptionClasses.Subscription(url); | 73 if (/^https?:\/\//.test(url)) |
| 74 return new modules.subscriptionClasses.Subscription(url); |
| 75 else |
| 76 return new modules.subscriptionClasses.SpecialSubscription(url); |
69 }; | 77 }; |
70 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla
sses.Subscription; | 78 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla
sses.Subscription; |
71 | 79 |
72 modules.filterStorage = { | 80 modules.filterStorage = { |
73 FilterStorage: { | 81 FilterStorage: { |
74 get subscriptions() | 82 get subscriptions() |
75 { | 83 { |
76 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; |
77 }, | 88 }, |
78 | 89 |
79 get knownSubscriptions() | 90 get knownSubscriptions() |
80 { | 91 { |
81 var result = {}; | 92 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 }, | 93 }, |
86 | 94 |
87 addSubscription: function(subscription) | 95 addSubscription: function(subscription) |
88 { | 96 { |
89 var index = subscriptions.indexOf(subscription.url); | 97 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc
riptions)) |
90 if (index < 0) | |
91 { | 98 { |
92 subscriptions.push(subscription.url); | 99 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub
scription.fromURL(subscription.url); |
93 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a
dded", subscription); | 100 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a
dded", subscription); |
94 } | 101 } |
95 }, | 102 }, |
96 | 103 |
97 removeSubscription: function(subscription) | 104 removeSubscription: function(subscription) |
98 { | 105 { |
99 var index = subscriptions.indexOf(subscription.url); | 106 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri
ptions) |
100 if (index >= 0) | |
101 { | 107 { |
102 subscriptions.splice(index, 1); | 108 delete knownSubscriptions[subscription.url]; |
103 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r
emoved", subscription); | 109 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r
emoved", subscription); |
104 } | 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) |
| 129 { |
| 130 customSubscription.filters.splice(i, 1); |
| 131 modules.filterNotifier.FilterNotifier.triggerListeners("filter.remov
ed", filter); |
| 132 return; |
| 133 } |
| 134 } |
105 } | 135 } |
106 } | 136 } |
107 }; | 137 }; |
108 | 138 |
109 modules.filterClasses = { | 139 modules.filterClasses = { |
110 BlockingFilter: function() {} | 140 BlockingFilter: function() {}, |
| 141 Filter: function(text) |
| 142 { |
| 143 this.text = text; |
| 144 this.disabled = false; |
| 145 } |
| 146 }; |
| 147 modules.filterClasses.Filter.fromText = function(text) |
| 148 { |
| 149 return new modules.filterClasses.Filter(text); |
111 }; | 150 }; |
112 | 151 |
113 modules.synchronizer = { | 152 modules.synchronizer = { |
114 Synchronizer: {} | 153 Synchronizer: {} |
115 }; | 154 }; |
116 | 155 |
117 modules.matcher = { | 156 modules.matcher = { |
118 defaultMatcher: { | 157 defaultMatcher: { |
119 matchesAny: function(url, requestType, docDomain, thirdParty) | 158 matchesAny: function(url, requestType, docDomain, thirdParty) |
120 { | 159 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 for (var i = 0; i < listeners.length; i++) | 191 for (var i = 0; i < listeners.length; i++) |
153 listeners[i].apply(null, args); | 192 listeners[i].apply(null, args); |
154 } | 193 } |
155 } | 194 } |
156 }; | 195 }; |
157 | 196 |
158 modules.info = { | 197 modules.info = { |
159 platform: "gecko", | 198 platform: "gecko", |
160 platformVersion: "34.0", | 199 platformVersion: "34.0", |
161 application: "firefox", | 200 application: "firefox", |
162 applicationVersion: "34.0" | 201 applicationVersion: "34.0", |
| 202 addonName: "adblockplus", |
| 203 addonVersion: "2.6.7" |
163 }; | 204 }; |
164 updateFromURL(modules.info); | 205 updateFromURL(modules.info); |
165 | 206 |
166 global.Services = { | 207 global.Services = { |
167 vc: { | 208 vc: { |
168 compare: function(v1, v2) | 209 compare: function(v1, v2) |
169 { | 210 { |
170 return parseFloat(v1) - parseFloat(v2); | 211 return parseFloat(v1) - parseFloat(v2); |
171 } | 212 } |
172 } | 213 } |
173 }; | 214 }; |
174 | 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"]; |
| 234 |
175 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; | 235 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; |
176 updateFromURL(issues); | 236 updateFromURL(issues); |
177 global.seenDataCorruption = issues.seenDataCorruption; | 237 global.seenDataCorruption = issues.seenDataCorruption; |
178 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 } |
179 })(this); | 258 })(this); |
OLD | NEW |