Left: | ||
Right: |
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 |
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 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 (function() | 20 (function() |
21 { | 21 { |
22 var subscriptionsMap = Object.create(null); | 22 var subscriptionsMap = Object.create(null); |
23 var recommendationsMap = Object.create(null); | 23 var recommendationsMap = Object.create(null); |
24 var filtersMap = Object.create(null); | 24 var filtersMap = Object.create(null); |
25 var collections = Object.create(null); | 25 var collections = Object.create(null); |
26 | 26 |
27 function Collection(details) | 27 function Collection(details) |
Felix Dahlke
2015/06/07 21:09:59
Does details have to be an array? From what I've s
saroyanm
2015/06/09 15:29:13
on line 139 I'm passing array from 2 elements.
"Ad
Felix Dahlke
2015/06/11 14:40:20
True, fair enough.
| |
28 { | 28 { |
29 this.details = details; | 29 this.details = details; |
30 } | 30 this.items = []; |
31 | 31 } |
32 Collection.prototype = Object.create(Array.prototype); | 32 |
Felix Dahlke
2015/06/07 21:09:59
From what I've seen, the only member functions use
saroyanm
2015/06/09 15:29:13
I would like to understand why it's more preferabl
Felix Dahlke
2015/06/11 14:40:20
It's a pretty common principle in OOP (http://en.w
saroyanm
2015/06/12 10:51:18
Done.
| |
33 Collection.prototype.addItems = function() | 33 Collection.prototype.addItems = function() |
34 { | 34 { |
35 var length = Array.prototype.push.apply(this, arguments); | 35 var length = Array.prototype.push.apply(this.items, arguments); |
36 if (length == 0) | 36 if (length == 0) |
37 return; | 37 return; |
38 | 38 |
39 this.sort(function(a, b) | 39 this.items.sort(function(a, b) |
40 { | 40 { |
41 var aValue = (a.title || a.url || a.text).toLowerCase(); | 41 var aValue = (a.title || a.url || a.text).toLowerCase(); |
42 var bValue = (b.title || b.url || a.text).toLowerCase(); | 42 var bValue = (b.title || b.url || a.text).toLowerCase(); |
43 if (aValue < bValue) | 43 return aValue.localeCompare(bValue); |
Felix Dahlke
2015/06/07 21:09:59
Nit: Would be shorter using localeCompare: `return
saroyanm
2015/06/09 15:29:13
I like this :) Done.
| |
44 return -1; | |
45 if (aValue > bValue) | |
46 return 1; | |
47 return 0; | |
48 }); | 44 }); |
49 | 45 |
50 for (var j = 0; j < this.details.length; j++) | 46 for (var j = 0; j < this.details.length; j++) |
51 { | 47 { |
52 var table = E(this.details[j].id); | 48 var table = E(this.details[j].id); |
53 var template = table.querySelector("template"); | 49 var template = table.querySelector("template"); |
54 for (var i = 0; i < arguments.length; i++) | 50 for (var i = 0; i < arguments.length; i++) |
55 { | 51 { |
56 var item = arguments[i]; | 52 var item = arguments[i]; |
57 var text = item.title || item.url || item.text; | 53 var text = item.title || item.url || item.text; |
58 var listItem = document.createElement("li"); | 54 var listItem = document.createElement("li"); |
59 listItem.appendChild(document.importNode(template.content, true)); | 55 listItem.appendChild(document.importNode(template.content, true)); |
60 listItem.dataset.access = item.url || item.text; | 56 listItem.dataset.access = item.url || item.text; |
61 listItem.querySelector(".display").textContent = text; | 57 listItem.querySelector(".display").textContent = text; |
62 if (text) | 58 if (text) |
63 listItem.dataset.search = text.toLowerCase(); | 59 listItem.dataset.search = text.toLowerCase(); |
64 | 60 |
65 var control = listItem.querySelector(".control"); | 61 var control = listItem.querySelector(".control"); |
66 if (control) | 62 if (control) |
67 { | 63 { |
68 control.addEventListener("click", this.details[j].onClick, false); | 64 control.addEventListener("click", this.details[j].onClick, false); |
69 control.checked = item.disabled == false; | 65 control.checked = item.disabled == false; |
Felix Dahlke
2015/06/07 21:09:59
Nit: "Do not compare x == true or x == false. Use
Felix Dahlke
2015/06/07 21:15:24
Sorry, wrong link, should have been: https://devel
saroyanm
2015/06/09 15:29:13
In this case is bit complicated, while the design
Felix Dahlke
2015/06/11 14:40:20
Oh I didn't realise that. No then it's fine.
| |
70 } | 66 } |
71 | 67 |
72 if (table.hasChildNodes) | 68 if (table.hasChildNodes()) |
Felix Dahlke
2015/06/07 21:09:59
Shouldn't this be `table.hasChildNodes()`?
saroyanm
2015/06/09 15:29:13
Done.
| |
73 table.insertBefore(listItem, table.childNodes[this.indexOf(item)]); | 69 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item) ]); |
74 else | 70 else |
75 table.appendChild(listItem); | 71 table.appendChild(listItem); |
76 } | 72 } |
77 } | 73 } |
78 return length; | 74 return length; |
79 }; | 75 }; |
80 | 76 |
81 Collection.prototype.removeItem = function(item) | 77 Collection.prototype.removeItem = function(item) |
82 { | 78 { |
83 var index = this.indexOf(item); | 79 var index = this.items.indexOf(item); |
84 if (index == -1) | 80 if (index == -1) |
85 return; | 81 return; |
86 | 82 |
87 this.splice(index, 1); | 83 this.items.splice(index, 1); |
88 var access = (item.url || item.text).replace(/'/g, "\\'"); | 84 var access = (item.url || item.text).replace(/'/g, "\\'"); |
89 for (var i = 0; i < this.details.length; i++) | 85 for (var i = 0; i < this.details.length; i++) |
90 { | 86 { |
91 var table = E(this.details[i].id); | 87 var table = E(this.details[i].id); |
92 var element = table.querySelector("[data-access='" + access + "']"); | 88 var element = table.querySelector("[data-access='" + access + "']"); |
93 element.parentElement.removeChild(element); | 89 element.parentElement.removeChild(element); |
94 } | 90 } |
95 }; | 91 }; |
96 | 92 |
97 Collection.prototype.clearAll = function() | 93 Collection.prototype.clearAll = function() |
98 { | 94 { |
99 for (var i = 0; i < this.details.length; i++) | 95 for (var i = 0; i < this.details.length; i++) |
100 { | 96 { |
101 var table = E(this.details[i].id); | 97 var table = E(this.details[i].id); |
102 var template = table.querySelector("template"); | 98 var template = table.querySelector("template"); |
103 table.innerHTML = ""; | 99 table.innerHTML = ""; |
104 table.appendChild(template); | 100 table.appendChild(template); |
105 } | 101 } |
106 this.length = 0; | 102 this.items.length = 0; |
107 }; | 103 }; |
108 | 104 |
109 function toggleSubscription(e) | 105 function onToggleSubscriptionClick(e) |
Felix Dahlke
2015/06/07 21:09:59
Nit: Wouldn't insist on it, but being an event han
saroyanm
2015/06/09 15:29:13
Done.
| |
110 { | 106 { |
111 e.preventDefault(); | 107 e.preventDefault(); |
112 var subscriptionUrl = e.target.parentNode.dataset.access; | 108 var subscriptionUrl = e.target.parentNode.dataset.access; |
113 if (!e.target.checked) | 109 if (!e.target.checked) |
114 removeSubscription(subscriptionUrl); | 110 removeSubscription(subscriptionUrl); |
115 else | 111 else |
116 addEnableSubscription(subscriptionUrl); | 112 addEnableSubscription(subscriptionUrl); |
117 } | 113 } |
118 | 114 |
119 function addLanguageSubscription(e) | 115 function onAddLanguageSubscriptionClick(e) |
120 { | 116 { |
121 e.preventDefault(); | 117 e.preventDefault(); |
122 var url = this.parentNode.dataset.access; | 118 var url = this.parentNode.dataset.access; |
123 addEnableSubscription(url); | 119 addEnableSubscription(url); |
124 } | 120 } |
125 | 121 |
126 function triggerRemoveFilter() | 122 function onRemoveFilterClick() |
127 { | 123 { |
128 var filter = this.parentNode.dataset.access; | 124 var filter = this.parentNode.dataset.access; |
129 removeFilter(filter); | 125 removeFilter(filter); |
130 } | 126 } |
131 | 127 |
132 collections.popular = new Collection( | 128 collections.popular = new Collection( |
133 [ | 129 [ |
134 { | 130 { |
135 id: "recommend-list-table", | 131 id: "recommend-list-table", |
136 onClick: toggleSubscription | 132 onClick: onToggleSubscriptionClick |
137 } | 133 } |
138 ]); | 134 ]); |
139 collections.langs = new Collection( | 135 collections.langs = new Collection( |
140 [ | 136 [ |
141 { | 137 { |
142 id: "blocking-languages-table", | 138 id: "blocking-languages-table", |
143 onClick: toggleSubscription | 139 onClick: onToggleSubscriptionClick |
144 }, | 140 }, |
145 { | 141 { |
146 id: "blocking-languages-modal-table" | 142 id: "blocking-languages-dialog-table" |
147 } | 143 } |
148 ]); | 144 ]); |
149 collections.allLangs = new Collection( | 145 collections.allLangs = new Collection( |
150 [ | 146 [ |
151 { | 147 { |
152 id: "all-lang-table", | 148 id: "all-lang-table", |
153 onClick: addLanguageSubscription | 149 onClick: onAddLanguageSubscriptionClick |
154 } | 150 } |
155 ]); | 151 ]); |
156 collections.acceptableAds = new Collection( | 152 collections.acceptableAds = new Collection( |
157 [ | 153 [ |
158 { | 154 { |
159 id: "acceptableads-table", | 155 id: "acceptableads-table", |
160 onClick: toggleSubscription | 156 onClick: onToggleSubscriptionClick |
161 } | 157 } |
162 ]); | 158 ]); |
163 collections.custom = new Collection( | 159 collections.custom = new Collection( |
164 [ | 160 [ |
165 { | 161 { |
166 id: "custom-list-table", | 162 id: "custom-list-table", |
167 onClick: toggleSubscription | 163 onClick: onToggleSubscriptionClick |
168 } | 164 } |
169 ]); | 165 ]); |
170 collections.whitelist = new Collection( | 166 collections.whitelist = new Collection( |
171 [ | 167 [ |
172 { | 168 { |
173 id: "whitelisting-table", | 169 id: "whitelisting-table", |
174 onClick: triggerRemoveFilter | 170 onClick: onRemoveFilterClick |
175 } | 171 } |
176 ]); | 172 ]); |
177 | 173 |
178 function updateSubscription(subscription) | 174 function updateSubscription(subscription) |
179 { | 175 { |
180 var subscriptionUrl = subscription.url; | 176 var subscriptionUrl = subscription.url; |
181 var knownSubscription = subscriptionsMap[subscriptionUrl]; | 177 var knownSubscription = subscriptionsMap[subscriptionUrl]; |
182 if (knownSubscription) | 178 if (knownSubscription) |
183 knownSubscription.disabled = subscription.disabled; | 179 knownSubscription.disabled = subscription.disabled; |
184 else | 180 else |
(...skipping 25 matching lines...) Expand all Loading... | |
210 collections.allLangs.addItems(subscription); | 206 collections.allLangs.addItems(subscription); |
211 collections.langs.removeItem(subscription); | 207 collections.langs.removeItem(subscription); |
212 } | 208 } |
213 } | 209 } |
214 } | 210 } |
215 } | 211 } |
216 } | 212 } |
217 | 213 |
218 if (!Object.observe) | 214 if (!Object.observe) |
219 { | 215 { |
216 // Currently only "disabled" property of subscription used for observa tion | |
217 // but with Advanced tab implementation we should also add more proper ties. | |
220 ["disabled"].forEach(function(property) | 218 ["disabled"].forEach(function(property) |
Felix Dahlke
2015/06/07 21:09:59
This could be simplified :D
saroyanm
2015/06/09 15:29:13
For future we are going to not only listen to "dis
Felix Dahlke
2015/06/11 14:40:20
If we're absolutely sure we'll need it, I'm OK wit
| |
221 { | 219 { |
222 subscription["$" + property] = subscription[property]; | 220 subscription["$" + property] = subscription[property]; |
223 Object.defineProperty(subscription, property, | 221 Object.defineProperty(subscription, property, |
224 { | 222 { |
225 get: function() | 223 get: function() |
226 { | 224 { |
227 return this["$" + property]; | 225 return this["$" + property]; |
228 }, | 226 }, |
229 set: function(value) | 227 set: function(value) |
230 { | 228 { |
231 this["$" + property] = value; | 229 this["$" + property] = value; |
232 onObjectChanged(); | 230 onObjectChanged(); |
233 } | 231 } |
234 }); | 232 }); |
235 }); | 233 }); |
236 } | 234 } |
237 else | 235 else |
238 { | 236 { |
239 Object.observe(subscription, function(changes) | 237 Object.observe(subscription, onObjectChanged); |
Felix Dahlke
2015/06/07 21:09:59
Nit: Why not just `Object.observe(subscription, on
saroyanm
2015/06/09 15:29:13
Done.
| |
240 { | |
241 onObjectChanged(); | |
242 }); | |
243 } | 238 } |
244 | 239 |
245 var collection = null; | 240 var collection = null; |
246 if (subscriptionUrl in recommendationsMap) | 241 if (subscriptionUrl in recommendationsMap) |
247 { | 242 { |
248 var recommendation = recommendationsMap[subscriptionUrl]; | 243 var recommendation = recommendationsMap[subscriptionUrl]; |
249 if (recommendation.isPopular) | 244 if (recommendation.isPopular) |
250 collection = collections.popular; | 245 collection = collections.popular; |
251 else if (recommendation.isAdsType && subscription.disabled == false) | 246 else if (recommendation.isAdsType && subscription.disabled == false) |
252 collection = collections.langs; | 247 collection = collections.langs; |
(...skipping 23 matching lines...) Expand all Loading... | |
276 else | 271 else |
277 { | 272 { |
278 // TODO: add `filters[i].text` to list of custom filters | 273 // TODO: add `filters[i].text` to list of custom filters |
279 } | 274 } |
280 } | 275 } |
281 | 276 |
282 function loadRecommendations() | 277 function loadRecommendations() |
283 { | 278 { |
284 var request = new XMLHttpRequest(); | 279 var request = new XMLHttpRequest(); |
285 request.open("GET", "subscriptions.xml", false); | 280 request.open("GET", "subscriptions.xml", false); |
286 request.onload = function() | 281 request.addEventListener("load", function() |
Felix Dahlke
2015/06/07 21:09:59
Nit: Use addEventListener()?
saroyanm
2015/06/09 15:29:13
Done.
| |
287 { | 282 { |
288 var list = document.getElementById("subscriptionSelector"); | 283 var list = document.getElementById("subscriptionSelector"); |
289 var docElem = request.responseXML.documentElement; | 284 var docElem = request.responseXML.documentElement; |
290 var elements = docElem.getElementsByTagName("subscription"); | 285 var elements = docElem.getElementsByTagName("subscription"); |
291 for (var i = 0; i < elements.length; i++) | 286 for (var i = 0; i < elements.length; i++) |
292 { | 287 { |
293 var element = elements[i]; | 288 var element = elements[i]; |
294 var subscription = Object.create(null); | 289 var subscription = Object.create(null); |
295 subscription.title = element.getAttribute("title"); | 290 subscription.title = element.getAttribute("title"); |
296 subscription.url = element.getAttribute("url"); | 291 subscription.url = element.getAttribute("url"); |
(...skipping 13 matching lines...) Expand all Loading... | |
310 } | 305 } |
311 else | 306 else |
312 subscription.title = element.getAttribute("specialization"); | 307 subscription.title = element.getAttribute("specialization"); |
313 | 308 |
314 if (element.getAttribute("popular")) | 309 if (element.getAttribute("popular")) |
315 recommendation.isPopular = true; | 310 recommendation.isPopular = true; |
316 | 311 |
317 recommendationsMap[subscription.url] = recommendation; | 312 recommendationsMap[subscription.url] = recommendation; |
318 updateSubscription(subscription); | 313 updateSubscription(subscription); |
319 } | 314 } |
320 }; | 315 }, false); |
321 request.send(null); | 316 request.send(null); |
322 } | 317 } |
323 | 318 |
324 function onDOMLoaded() | 319 function onDOMLoaded() |
325 { | 320 { |
326 var recommendationTemplate = document.querySelector("#recommend-list-table t emplate"); | 321 var recommendationTemplate = document.querySelector("#recommend-list-table t emplate"); |
327 var popularText = ext.i18n.getMessage("options_popular"); | 322 var popularText = ext.i18n.getMessage("options_popular"); |
328 recommendationTemplate.content.querySelector(".popular").textContent = popul arText; | 323 recommendationTemplate.content.querySelector(".popular").textContent = popul arText; |
329 var languagesTemplate = document.querySelector("#all-lang-table template"); | 324 var languagesTemplate = document.querySelector("#all-lang-table template"); |
330 var buttonText = ext.i18n.getMessage("options_button_add"); | 325 var buttonText = ext.i18n.getMessage("options_button_add"); |
331 languagesTemplate.content.querySelector(".button-add span").textContent = bu ttonText; | 326 languagesTemplate.content.querySelector(".button-add span").textContent = bu ttonText; |
332 | 327 |
333 updateShareLink(); | 328 updateShareLink(); |
334 populateLists(); | 329 populateLists(); |
335 | 330 |
336 var tabList = document.querySelectorAll("#main-navigation-tabs li"); | 331 var tabList = document.querySelectorAll("#main-navigation-tabs li"); |
337 for (var i = 0; i < tabList.length; i++) | 332 for (var i = 0; i < tabList.length; i++) |
338 { | 333 { |
339 tabList[i].addEventListener("click", function(e) | 334 tabList[i].addEventListener("click", function(e) |
340 { | 335 { |
341 document.body.dataset.tab = e.currentTarget.dataset.show; | 336 document.body.dataset.tab = e.currentTarget.dataset.show; |
342 }, false); | 337 }, false); |
343 } | 338 } |
344 | 339 |
345 function searchLanguage() | 340 function onFindLanguageKeyUp() |
Felix Dahlke
2015/06/07 21:09:59
Nit: Similar to above, I'd find this easier to und
saroyanm
2015/06/09 15:29:13
Done.
| |
346 { | 341 { |
347 var searchStyle = E("search-style"); | 342 var searchStyle = E("search-style"); |
348 if (!this.value) | 343 if (!this.value) |
349 searchStyle.innerHTML = ""; | 344 searchStyle.innerHTML = ""; |
350 else | 345 else |
351 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; | 346 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; |
352 } | 347 } |
353 | 348 |
354 // Update version number in navigation sidebar | 349 // Update version number in navigation sidebar |
355 ext.backgroundPage.sendMessage( | 350 ext.backgroundPage.sendMessage( |
356 { | 351 { |
357 method: "app.get", | 352 method: "app.get", |
358 what: "addonVersion" | 353 what: "addonVersion" |
359 }, | 354 }, |
360 function(addonVersion) | 355 function(addonVersion) |
361 { | 356 { |
362 E("abp-version").textContent = addonVersion; | 357 E("abp-version").textContent = addonVersion; |
363 }); | 358 }); |
364 | 359 |
365 var placeholderValue = ext.i18n.getMessage("options_modal_language_find"); | 360 var placeholderValue = ext.i18n.getMessage("options_dialog_language_find"); |
366 E("find-language").setAttribute("placeholder", placeholderValue); | 361 E("find-language").setAttribute("placeholder", placeholderValue); |
367 E("add-blocking-list").addEventListener("click", function() | 362 E("add-blocking-list").addEventListener("click", function() |
368 { | 363 { |
369 openModal("customlist"); | 364 openDialog("customlist"); |
370 }, false); | 365 }, false); |
371 E("add-website-language").addEventListener("click", function() | 366 E("add-website-language").addEventListener("click", function() |
372 { | 367 { |
373 openModal("language"); | 368 openDialog("language"); |
374 }, false); | 369 }, false); |
375 E("modal-close").addEventListener("click", function() | 370 E("dialog-close").addEventListener("click", function() |
376 { | 371 { |
377 delete document.body.dataset.modal; | 372 delete document.body.dataset.dialog; |
378 }, false); | 373 }, false); |
379 E("edit-ownBlockingList-button").addEventListener("click", editCustomFilters , false); | 374 E("edit-ownBlockingList-button").addEventListener("click", editCustomFilters , false); |
380 E("find-language").addEventListener("keyup", searchLanguage, false); | 375 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
381 E("whitelisting").addEventListener("click", function(e) | 376 E("whitelisting").addEventListener("click", function(e) |
382 { | 377 { |
383 var id = e.target.id; | 378 var id = e.target.id; |
384 if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon") | 379 if (id == "whitelisting-add-icon" || id == "whitelisting-enter-icon") |
385 addWhitelistedDomain(); | 380 addWhitelistedDomain(); |
386 else if (id == "whitelisting-cancel-button") | 381 else if (id == "whitelisting-cancel-button") |
387 E("whitelisting-textbox").value = ""; | 382 E("whitelisting-textbox").value = ""; |
388 }, false); | 383 }, false); |
389 E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain, false); | 384 E("whitelisting-add-button").addEventListener("click", addWhitelistedDomain, false); |
390 E("whitelisting-textbox").addEventListener("keypress", function(e) | 385 E("whitelisting-textbox").addEventListener("keypress", function(e) |
391 { | 386 { |
392 // e.keyCode has been deprecated so we use e.key instead | 387 // e.keyCode has been deprecated so we attempt to use e.key |
Felix Dahlke
2015/06/07 21:09:59
Nit: "so we attempt to use e.key"? Since we're act
saroyanm
2015/06/09 15:29:13
Done.
| |
393 if (e.key && e.key == "Enter") | 388 // keyCode "13" corresponds to "Enter" |
394 addWhitelistedDomain(); | 389 if ((e.key && e.key == "Enter") || (!e.key && e.keyCode == 13)) |
395 else if (!e.key && e.keyCode == 13) //keyCode "13" corresponds to "Enter" | |
396 addWhitelistedDomain(); | 390 addWhitelistedDomain(); |
Felix Dahlke
2015/06/07 21:09:59
Nit: Seeing how the else body is identical to the
saroyanm
2015/06/09 15:29:13
Done.
| |
397 }, false); | 391 }, false); |
398 E("import-blockingList-button").addEventListener("click", function() | 392 E("import-blockingList-button").addEventListener("click", function() |
399 { | 393 { |
400 var url = E("blockingList-textbox").value; | 394 var url = E("blockingList-textbox").value; |
401 addEnableSubscription(url); | 395 addEnableSubscription(url); |
402 delete document.body.dataset.modal; | 396 delete document.body.dataset.dialog; |
403 }, false); | 397 }, false); |
404 } | 398 } |
405 | 399 |
406 function openModal(name) | 400 function openDialog(name) |
407 { | 401 { |
408 document.body.dataset.modal = name; | 402 document.body.dataset.dialog = name; |
409 } | 403 } |
410 | 404 |
411 function populateLists() | 405 function populateLists() |
412 { | 406 { |
413 subscriptionsMap = Object.create(null); | 407 subscriptionsMap = Object.create(null); |
414 filtersMap = Object.create(null); | 408 filtersMap = Object.create(null); |
415 recommendationsMap = Object.create(null); | 409 recommendationsMap = Object.create(null); |
416 | 410 |
417 // Empty collections and lists | 411 // Empty collections and lists |
418 for (var property in collections) | 412 for (var property in collections) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 type: "filters.add", | 467 type: "filters.add", |
474 text: "@@||" + domain.value.toLowerCase() + "^$document" | 468 text: "@@||" + domain.value.toLowerCase() + "^$document" |
475 }); | 469 }); |
476 } | 470 } |
477 | 471 |
478 domain.value = ""; | 472 domain.value = ""; |
479 } | 473 } |
480 | 474 |
481 function editCustomFilters() | 475 function editCustomFilters() |
482 { | 476 { |
483 | 477 //TODO: NYI |
Felix Dahlke
2015/06/07 21:09:59
Nit: Seeing how we have a bunch of TODO comments h
saroyanm
2015/06/09 15:29:13
Done.
| |
484 } | 478 } |
485 | 479 |
486 function getAcceptableAdsURL(callback) | 480 function getAcceptableAdsURL(callback) |
487 { | 481 { |
488 ext.backgroundPage.sendMessage( | 482 ext.backgroundPage.sendMessage( |
489 { | 483 { |
490 type: "prefs.get", | 484 type: "prefs.get", |
491 key: "subscriptions_exceptionsurl" | 485 key: "subscriptions_exceptionsurl" |
492 }, | 486 }, |
493 function(value) | 487 function(value) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 updateShareLink(); | 551 updateShareLink(); |
558 break; | 552 break; |
559 } | 553 } |
560 } | 554 } |
561 | 555 |
562 function onSubscriptionMessage(action, subscription) | 556 function onSubscriptionMessage(action, subscription) |
563 { | 557 { |
564 switch (action) | 558 switch (action) |
565 { | 559 { |
566 case "added": | 560 case "added": |
567 updateSubscription(subscription); | |
568 updateShareLink(); | |
569 break; | |
570 case "disabled": | 561 case "disabled": |
Felix Dahlke
2015/06/07 21:09:59
Merge with case "added" above?
saroyanm
2015/06/09 15:29:13
Done.
| |
571 updateSubscription(subscription); | 562 updateSubscription(subscription); |
572 updateShareLink(); | 563 updateShareLink(); |
573 break; | 564 break; |
574 case "homepage": | 565 case "homepage": |
575 // TODO: NYI | 566 // TODO: NYI |
576 break; | 567 break; |
577 case "removed": | 568 case "removed": |
578 getAcceptableAdsURL(function(acceptableAdsUrl) | 569 getAcceptableAdsURL(function(acceptableAdsUrl) |
579 { | 570 { |
580 if (subscription.url == acceptableAdsUrl) | 571 if (subscription.url == acceptableAdsUrl) |
(...skipping 17 matching lines...) Expand all Loading... | |
598 break; | 589 break; |
599 case "title": | 590 case "title": |
600 // TODO: NYI | 591 // TODO: NYI |
601 break; | 592 break; |
602 } | 593 } |
603 } | 594 } |
604 | 595 |
605 function showAddSubscriptionDialog(subscription) | 596 function showAddSubscriptionDialog(subscription) |
606 { | 597 { |
607 E("blockingList-textbox").value = subscription.url; | 598 E("blockingList-textbox").value = subscription.url; |
608 openModal("customlist"); | 599 openDialog("customlist"); |
609 } | 600 } |
610 | 601 |
611 function updateShareLink() | 602 function updateShareLink() |
612 { | 603 { |
613 ext.backgroundPage.sendMessage( | 604 ext.backgroundPage.sendMessage( |
614 { | 605 { |
615 type: "filters.blocked", | 606 type: "filters.blocked", |
616 url: "https://platform.twitter.com/widgets/", | 607 url: "https://platform.twitter.com/widgets/", |
617 requestType: "SCRIPT", | 608 requestType: "SCRIPT", |
618 docDomain: "adblockplus.org", | 609 docDomain: "adblockplus.org", |
619 thirdParty: true | 610 thirdParty: true |
620 }, | 611 }, |
621 function(blocked) | 612 function(blocked) |
622 { | 613 { |
623 // TODO: modify "share" link accordingly | 614 // TODO: modify "share" link accordingly |
624 }); | 615 }); |
625 } | 616 } |
626 | 617 |
627 function E(id) | 618 function E(id) |
Felix Dahlke
2015/06/07 21:09:59
Not a fan of this function, made things harder to
Felix Dahlke
2015/06/08 19:44:51
Just realised that we have E() as well in the Fire
| |
628 { | 619 { |
629 return document.getElementById(id); | 620 return document.getElementById(id); |
630 } | 621 } |
631 | 622 |
632 ext.onMessage.addListener(function(message) | 623 ext.onMessage.addListener(function(message) |
633 { | 624 { |
634 switch (message.type) | 625 switch (message.type) |
635 { | 626 { |
636 case "app.listen": | 627 case "app.listen": |
637 if (message.action == "addSubscription") | 628 if (message.action == "addSubscription") |
(...skipping 19 matching lines...) Expand all Loading... | |
657 filter: ["added", "loaded", "removed"] | 648 filter: ["added", "loaded", "removed"] |
658 }); | 649 }); |
659 ext.backgroundPage.sendMessage( | 650 ext.backgroundPage.sendMessage( |
660 { | 651 { |
661 type: "subscriptions.listen", | 652 type: "subscriptions.listen", |
662 filter: ["added", "disabled", "homepage", "removed", "title"] | 653 filter: ["added", "disabled", "homepage", "removed", "title"] |
663 }); | 654 }); |
664 | 655 |
665 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 656 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
666 })(); | 657 })(); |
LEFT | RIGHT |