Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: mobile-options.js

Issue 29573083: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockplusui/
Patch Set: Add polyfill.js to README.md Created Oct. 17, 2017, 12:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mobile-options.html ('k') | polyfill.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 /* globals getDocLink */ 18 /* globals getDocLink */
19 19
20 "use strict"; 20 "use strict";
21 21
22 { 22 {
23 const {getMessage} = chrome.i18n; 23 const {getMessage} = browser.i18n;
24 24
25 const dialogSubscribe = "subscribe"; 25 const dialogSubscribe = "subscribe";
26 const idAcceptableAds = "acceptableAds"; 26 const idAcceptableAds = "acceptableAds";
27 const idRecommended = "subscriptions-recommended"; 27 const idRecommended = "subscriptions-recommended";
28 let whitelistFilter = null; 28 let whitelistFilter = null;
29 let promisedAcceptableAdsUrl = getAcceptableAdsUrl(); 29 let promisedAcceptableAdsUrl = getAcceptableAdsUrl();
30 30
31 /* Utility functions */ 31 /* Utility functions */
32 32
33 function get(selector, origin) 33 function get(selector, origin)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 chrome.runtime.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 chrome.runtime.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 chrome.runtime.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 chrome.runtime.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
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 chrome.runtime.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
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 chrome.runtime.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 chrome.runtime.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 chrome.runtime.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 }
OLDNEW
« no previous file with comments | « mobile-options.html ('k') | polyfill.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld