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

Side by Side Diff: desktop-options.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Update buildtools dependency Created Oct. 16, 2017, 12:10 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 | « desktop-options.html ('k') | devtools.html » ('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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 if (paramValues.length > 0) 43 if (paramValues.length > 0)
44 { 44 {
45 let lastArg = paramValues[paramValues.length - 1]; 45 let lastArg = paramValues[paramValues.length - 1];
46 if (typeof lastArg == "function") 46 if (typeof lastArg == "function")
47 callback = lastArg; 47 callback = lastArg;
48 48
49 for (let i = 0; i < paramValues.length - (callback ? 1 : 0); i++) 49 for (let i = 0; i < paramValues.length - (callback ? 1 : 0); i++)
50 message[paramKeys[i]] = paramValues[i]; 50 message[paramKeys[i]] = paramValues[i];
51 } 51 }
52 52
53 chrome.runtime.sendMessage(message, callback); 53 browser.runtime.sendMessage(message, callback);
54 }; 54 };
55 } 55 }
56 56
57 const getDocLink = wrapper({type: "app.get", what: "doclink"}, "link"); 57 const getDocLink = wrapper({type: "app.get", what: "doclink"}, "link");
58 const getInfo = wrapper({type: "app.get"}, "what"); 58 const getInfo = wrapper({type: "app.get"}, "what");
59 const getPref = wrapper({type: "prefs.get"}, "key"); 59 const getPref = wrapper({type: "prefs.get"}, "key");
60 const togglePref = wrapper({type: "prefs.toggle"}, "key"); 60 const togglePref = wrapper({type: "prefs.toggle"}, "key");
61 const getSubscriptions = wrapper({type: "subscriptions.get"}, 61 const getSubscriptions = wrapper({type: "subscriptions.get"},
62 "downloadable", "special"); 62 "downloadable", "special");
63 const removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); 63 const removeSubscription = wrapper({type: "subscriptions.remove"}, "url");
(...skipping 20 matching lines...) Expand all
84 "filters_subscription_lastDownload_checksumMismatch"] 84 "filters_subscription_lastDownload_checksumMismatch"]
85 ]); 85 ]);
86 86
87 let delayedSubscriptionSelection = null; 87 let delayedSubscriptionSelection = null;
88 let acceptableAdsUrl; 88 let acceptableAdsUrl;
89 89
90 // Loads options from localStorage and sets UI elements accordingly 90 // Loads options from localStorage and sets UI elements accordingly
91 function loadOptions() 91 function loadOptions()
92 { 92 {
93 // Set page title to i18n version of "Adblock Plus Options" 93 // Set page title to i18n version of "Adblock Plus Options"
94 document.title = chrome.i18n.getMessage("options"); 94 document.title = browser.i18n.getMessage("options");
95 95
96 // Set links 96 // Set links
97 getPref("subscriptions_exceptionsurl", url => 97 getPref("subscriptions_exceptionsurl", url =>
98 { 98 {
99 acceptableAdsUrl = url; 99 acceptableAdsUrl = url;
100 $("#acceptableAdsLink").attr("href", acceptableAdsUrl); 100 $("#acceptableAdsLink").attr("href", acceptableAdsUrl);
101 }); 101 });
102 getDocLink("acceptable_ads", url => 102 getDocLink("acceptable_ads", url =>
103 { 103 {
104 $("#acceptableAdsDocs").attr("href", url); 104 $("#acceptableAdsDocs").attr("href", url);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 if (!features.devToolsPanel) 154 if (!features.devToolsPanel)
155 document.getElementById("showDevtoolsPanelContainer").hidden = true; 155 document.getElementById("showDevtoolsPanelContainer").hidden = true;
156 }); 156 });
157 getPref("notifications_showui", showNotificationsUI => 157 getPref("notifications_showui", showNotificationsUI =>
158 { 158 {
159 if (!showNotificationsUI) 159 if (!showNotificationsUI)
160 document.getElementById("shouldShowNotificationsContainer").hidden = true; 160 document.getElementById("shouldShowNotificationsContainer").hidden = true;
161 }); 161 });
162 162
163 // Register listeners in the background message responder 163 // Register listeners in the background message responder
164 chrome.runtime.sendMessage({ 164 browser.runtime.sendMessage({
165 type: "app.listen", 165 type: "app.listen",
166 filter: ["addSubscription", "focusSection"] 166 filter: ["addSubscription", "focusSection"]
167 }); 167 });
168 chrome.runtime.sendMessage({ 168 browser.runtime.sendMessage({
169 type: "filters.listen", 169 type: "filters.listen",
170 filter: ["added", "loaded", "removed"] 170 filter: ["added", "loaded", "removed"]
171 }); 171 });
172 chrome.runtime.sendMessage({ 172 browser.runtime.sendMessage({
173 type: "prefs.listen", 173 type: "prefs.listen",
174 filter: ["notifications_ignoredcategories", "notifications_showui", 174 filter: ["notifications_ignoredcategories", "notifications_showui",
175 "show_devtools_panel", "shouldShowBlockElementMenu"] 175 "show_devtools_panel", "shouldShowBlockElementMenu"]
176 }); 176 });
177 chrome.runtime.sendMessage({ 177 browser.runtime.sendMessage({
178 type: "subscriptions.listen", 178 type: "subscriptions.listen",
179 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 179 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
180 "title", "downloadStatus", "downloading"] 180 "title", "downloadStatus", "downloading"]
181 }); 181 });
182 182
183 // Load recommended subscriptions 183 // Load recommended subscriptions
184 loadRecommendations(); 184 loadRecommendations();
185 185
186 // Show user's filters 186 // Show user's filters
187 reloadFilters(); 187 reloadFilters();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 { 298 {
299 selectedIndex = i; 299 selectedIndex = i;
300 selectedPrefix = prefix; 300 selectedPrefix = prefix;
301 } 301 }
302 } 302 }
303 } 303 }
304 list.appendChild(option); 304 list.appendChild(option);
305 } 305 }
306 306
307 let option = new Option(); 307 let option = new Option();
308 let label = chrome.i18n.getMessage("filters_addSubscriptionOther_label"); 308 let label = browser.i18n.getMessage("filters_addSubscriptionOther_label");
309 option.text = label + "\u2026"; 309 option.text = label + "\u2026";
310 option._data = null; 310 option._data = null;
311 list.appendChild(option); 311 list.appendChild(option);
312 312
313 list.selectedIndex = selectedIndex; 313 list.selectedIndex = selectedIndex;
314 314
315 if (delayedSubscriptionSelection) 315 if (delayedSubscriptionSelection)
316 startSubscriptionSelection(...delayedSubscriptionSelection); 316 startSubscriptionSelection(...delayedSubscriptionSelection);
317 }); 317 });
318 } 318 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 let list = document.getElementById("subscriptionSelector"); 358 let list = document.getElementById("subscriptionSelector");
359 let data = list.options[list.selectedIndex]._data; 359 let data = list.options[list.selectedIndex]._data;
360 if (data) 360 if (data)
361 addSubscription(data.url, data.title, data.homepage); 361 addSubscription(data.url, data.title, data.homepage);
362 else 362 else
363 { 363 {
364 let url = document.getElementById("customSubscriptionLocation") 364 let url = document.getElementById("customSubscriptionLocation")
365 .value.trim(); 365 .value.trim();
366 if (!/^https?:/i.test(url)) 366 if (!/^https?:/i.test(url))
367 { 367 {
368 alert(chrome.i18n.getMessage("global_subscription_invalid_location")); 368 alert(browser.i18n.getMessage("global_subscription_invalid_location"));
369 $("#customSubscriptionLocation").focus(); 369 $("#customSubscriptionLocation").focus();
370 return; 370 return;
371 } 371 }
372 372
373 let title = document.getElementById("customSubscriptionTitle").value.trim(); 373 let title = document.getElementById("customSubscriptionTitle").value.trim();
374 if (!title) 374 if (!title)
375 title = url; 375 title = url;
376 376
377 addSubscription(url, title, null); 377 addSubscription(url, title, null);
378 } 378 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 414
415 let enabled = element.getElementsByClassName("subscriptionEnabled")[0]; 415 let enabled = element.getElementsByClassName("subscriptionEnabled")[0];
416 enabled.checked = !subscription.disabled; 416 enabled.checked = !subscription.disabled;
417 417
418 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; 418 let lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0];
419 lastUpdate.classList.remove("error"); 419 lastUpdate.classList.remove("error");
420 420
421 let {downloadStatus} = subscription; 421 let {downloadStatus} = subscription;
422 if (subscription.isDownloading) 422 if (subscription.isDownloading)
423 { 423 {
424 lastUpdate.textContent = chrome.i18n.getMessage( 424 lastUpdate.textContent = browser.i18n.getMessage(
425 "filters_subscription_lastDownload_inProgress" 425 "filters_subscription_lastDownload_inProgress"
426 ); 426 );
427 } 427 }
428 else if (downloadStatus && downloadStatus != "synchronize_ok") 428 else if (downloadStatus && downloadStatus != "synchronize_ok")
429 { 429 {
430 if (statusMessages.has(downloadStatus)) 430 if (statusMessages.has(downloadStatus))
431 { 431 {
432 lastUpdate.textContent = chrome.i18n.getMessage( 432 lastUpdate.textContent = browser.i18n.getMessage(
433 statusMessages.get(downloadStatus) 433 statusMessages.get(downloadStatus)
434 ); 434 );
435 } 435 }
436 else 436 else
437 lastUpdate.textContent = downloadStatus; 437 lastUpdate.textContent = downloadStatus;
438 lastUpdate.classList.add("error"); 438 lastUpdate.classList.add("error");
439 } 439 }
440 else if (subscription.lastDownload > 0) 440 else if (subscription.lastDownload > 0)
441 { 441 {
442 let timeDate = i18nTimeDateStrings(subscription.lastDownload * 1000); 442 let timeDate = i18nTimeDateStrings(subscription.lastDownload * 1000);
443 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); 443 let messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today");
444 lastUpdate.textContent = chrome.i18n.getMessage(messageID, timeDate); 444 lastUpdate.textContent = browser.i18n.getMessage(messageID, timeDate);
445 } 445 }
446 } 446 }
447 447
448 function onSubscriptionMessage(action, subscription) 448 function onSubscriptionMessage(action, subscription)
449 { 449 {
450 let element = findSubscriptionElement(subscription); 450 let element = findSubscriptionElement(subscription);
451 451
452 switch (action) 452 switch (action)
453 { 453 {
454 case "disabled": 454 case "disabled":
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 element.removeAttribute("id"); 649 element.removeAttribute("id");
650 element._subscription = subscription; 650 element._subscription = subscription;
651 651
652 let removeButton = element.getElementsByClassName( 652 let removeButton = element.getElementsByClassName(
653 "subscriptionRemoveButton" 653 "subscriptionRemoveButton"
654 )[0]; 654 )[0];
655 removeButton.setAttribute("title", removeButton.textContent); 655 removeButton.setAttribute("title", removeButton.textContent);
656 removeButton.textContent = "\xD7"; 656 removeButton.textContent = "\xD7";
657 removeButton.addEventListener("click", () => 657 removeButton.addEventListener("click", () =>
658 { 658 {
659 if (!confirm(chrome.i18n.getMessage("global_remove_subscription_warning"))) 659 if (!confirm(browser.i18n.getMessage("global_remove_subscription_warning")))
660 return; 660 return;
661 661
662 removeSubscription(subscription.url); 662 removeSubscription(subscription.url);
663 }, false); 663 }, false);
664 664
665 getPref("additional_subscriptions", additionalSubscriptions => 665 getPref("additional_subscriptions", additionalSubscriptions =>
666 { 666 {
667 if (additionalSubscriptions.includes(subscription.url)) 667 if (additionalSubscriptions.includes(subscription.url))
668 removeButton.style.visibility = "hidden"; 668 removeButton.style.visibility = "hidden";
669 }); 669 });
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 onFilterMessage(message.action, message.args[0]); 739 onFilterMessage(message.action, message.args[0]);
740 break; 740 break;
741 case "prefs.respond": 741 case "prefs.respond":
742 onPrefMessage(message.action, message.args[0]); 742 onPrefMessage(message.action, message.args[0]);
743 break; 743 break;
744 case "subscriptions.respond": 744 case "subscriptions.respond":
745 onSubscriptionMessage(message.action, message.args[0]); 745 onSubscriptionMessage(message.action, message.args[0]);
746 break; 746 break;
747 } 747 }
748 }); 748 });
OLDNEW
« no previous file with comments | « desktop-options.html ('k') | devtools.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld