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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 parent.appendChild(element); | 69 parent.appendChild(element); |
70 return element; | 70 return element; |
71 } | 71 } |
72 | 72 |
73 /* Extension interactions */ | 73 /* Extension interactions */ |
74 | 74 |
75 function getInstalled() | 75 function getInstalled() |
76 { | 76 { |
77 return new Promise((resolve, reject) => | 77 return new Promise((resolve, reject) => |
78 { | 78 { |
79 ext.backgroundPage.sendMessage( | 79 browser.runtime.sendMessage( |
80 {type: "subscriptions.get", downloadable: true}, | 80 {type: "subscriptions.get", downloadable: true}, |
81 resolve | 81 resolve |
82 ); | 82 ); |
83 }); | 83 }); |
84 } | 84 } |
85 | 85 |
86 function getAcceptableAdsUrl() | 86 function getAcceptableAdsUrl() |
87 { | 87 { |
88 return new Promise((resolve, reject) => | 88 return new Promise((resolve, reject) => |
89 { | 89 { |
90 ext.backgroundPage.sendMessage( | 90 browser.runtime.sendMessage( |
91 {type: "prefs.get", key: "subscriptions_exceptionsurl"}, | 91 {type: "prefs.get", key: "subscriptions_exceptionsurl"}, |
92 resolve | 92 resolve |
93 ); | 93 ); |
94 }); | 94 }); |
95 } | 95 } |
96 | 96 |
97 function getRecommendedAds() | 97 function getRecommendedAds() |
98 { | 98 { |
99 return fetch("subscriptions.xml") | 99 return fetch("subscriptions.xml") |
100 .then((response) => response.text()) | 100 .then((response) => response.text()) |
101 .then((text) => | 101 .then((text) => |
102 { | 102 { |
103 let doc = new DOMParser().parseFromString(text, "application/xml"); | 103 let doc = new DOMParser().parseFromString(text, "application/xml"); |
104 let elements = Array.from(doc.getElementsByTagName("subscription")); | 104 let elements = Array.from(doc.getElementsByTagName("subscription")); |
105 | 105 |
106 return elements | 106 return elements |
107 .filter((element) => element.getAttribute("type") == "ads") | 107 .filter((element) => element.getAttribute("type") == "ads") |
108 .map((element) => | 108 .map((element) => |
109 { | 109 { |
110 return { | 110 return { |
111 title: element.getAttribute("title"), | 111 title: element.getAttribute("title"), |
112 url: element.getAttribute("url") | 112 url: element.getAttribute("url") |
113 }; | 113 }; |
114 }); | 114 }); |
115 }); | 115 }); |
116 } | 116 } |
117 | 117 |
118 function installSubscription(url, title) | 118 function installSubscription(url, title) |
119 { | 119 { |
120 ext.backgroundPage.sendMessage({type: "subscriptions.add", url, title}); | 120 browser.runtime.sendMessage({type: "subscriptions.add", url, title}); |
121 } | 121 } |
122 | 122 |
123 function uninstallSubscription(url) | 123 function uninstallSubscription(url) |
124 { | 124 { |
125 ext.backgroundPage.sendMessage({type: "subscriptions.remove", url}); | 125 browser.runtime.sendMessage({type: "subscriptions.remove", url}); |
126 } | 126 } |
127 | 127 |
128 /* Actions */ | 128 /* Actions */ |
129 | 129 |
130 function setFilter({disabled, text}, action) | 130 function setFilter({disabled, text}, action) |
131 { | 131 { |
132 if (!whitelistFilter || text != whitelistFilter) | 132 if (!whitelistFilter || text != whitelistFilter) |
133 return; | 133 return; |
134 | 134 |
135 get("#enabled").checked = (action == "remove" || disabled); | 135 get("#enabled").checked = (action == "remove" || disabled); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 uninstallSubscription(acceptableAdsUrl); | 283 uninstallSubscription(acceptableAdsUrl); |
284 } | 284 } |
285 }); | 285 }); |
286 } | 286 } |
287 document.addEventListener("change", onChange); | 287 document.addEventListener("change", onChange); |
288 | 288 |
289 function toggleWhitelistFilter(toggle) | 289 function toggleWhitelistFilter(toggle) |
290 { | 290 { |
291 if (whitelistFilter) | 291 if (whitelistFilter) |
292 { | 292 { |
293 ext.backgroundPage.sendMessage( | 293 browser.runtime.sendMessage( |
294 { | 294 { |
295 type: (toggle.checked) ? "filters.remove" : "filters.add", | 295 type: (toggle.checked) ? "filters.remove" : "filters.add", |
296 text: whitelistFilter | 296 text: whitelistFilter |
297 }, | 297 }, |
298 (errors) => | 298 (errors) => |
299 { | 299 { |
300 if (errors.length < 1) | 300 if (errors.length < 1) |
301 return; | 301 return; |
302 | 302 |
303 console.error(errors); | 303 console.error(errors); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // not installed so we shouldn't add those by accident | 406 // not installed so we shouldn't add those by accident |
407 setSubscription(subscription, "update"); | 407 setSubscription(subscription, "update"); |
408 break; | 408 break; |
409 } | 409 } |
410 break; | 410 break; |
411 } | 411 } |
412 } | 412 } |
413 } | 413 } |
414 ext.onMessage.addListener(onMessage); | 414 ext.onMessage.addListener(onMessage); |
415 | 415 |
416 ext.backgroundPage.sendMessage({ | 416 browser.runtime.sendMessage({ |
417 type: "app.listen", | 417 type: "app.listen", |
418 filter: ["addSubscription", "showPageOptions"] | 418 filter: ["addSubscription", "showPageOptions"] |
419 }); | 419 }); |
420 | 420 |
421 ext.backgroundPage.sendMessage({ | 421 browser.runtime.sendMessage({ |
422 type: "filters.listen", | 422 type: "filters.listen", |
423 filter: ["added", "removed"] | 423 filter: ["added", "removed"] |
424 }); | 424 }); |
425 | 425 |
426 ext.backgroundPage.sendMessage({ | 426 browser.runtime.sendMessage({ |
427 type: "subscriptions.listen", | 427 type: "subscriptions.listen", |
428 filter: ["added", "disabled", "removed", "title"] | 428 filter: ["added", "disabled", "removed", "title"] |
429 }); | 429 }); |
430 | 430 |
431 /* Initialization */ | 431 /* Initialization */ |
432 | 432 |
433 populateLists(); | 433 populateLists(); |
434 | 434 |
435 getDocLink("acceptable_ads", (link) => | 435 getDocLink("acceptable_ads", (link) => |
436 { | 436 { |
437 get("#acceptableAds-more").href = link; | 437 get("#acceptableAds-more").href = link; |
438 }); | 438 }); |
439 | 439 |
440 get("#dialog-subscribe [name='title']").setAttribute( | 440 get("#dialog-subscribe [name='title']").setAttribute( |
441 "placeholder", | 441 "placeholder", |
442 getMessage("mops_subscribe_title") | 442 getMessage("mops_subscribe_title") |
443 ); | 443 ); |
444 | 444 |
445 get("#dialog-subscribe [name='url']").setAttribute( | 445 get("#dialog-subscribe [name='url']").setAttribute( |
446 "placeholder", | 446 "placeholder", |
447 getMessage("mops_subscribe_url") | 447 getMessage("mops_subscribe_url") |
448 ); | 448 ); |
449 } | 449 } |
LEFT | RIGHT |