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

Side by Side Diff: js/desktop-options.js

Issue 29712664: Issue 6432 - Hide remove button for additional filter lists (Closed)
Patch Set: Version with no callback hell Created March 8, 2018, 2:20 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') | skin/icons/checkbox.svg » ('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 checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup, 18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup,
19 setLinks, E */ 19 setLinks, E */
20 20
21 "use strict"; 21 "use strict";
22 22
23 let subscriptionsMap = Object.create(null); 23 let subscriptionsMap = Object.create(null);
24 let filtersMap = Object.create(null); 24 let filtersMap = Object.create(null);
25 let collections = Object.create(null); 25 let collections = Object.create(null);
26 let acceptableAdsUrl = null; 26 let acceptableAdsUrl = null;
27 let acceptableAdsPrivacyUrl = null; 27 let acceptableAdsPrivacyUrl = null;
28 let isCustomFiltersLoaded = false; 28 let isCustomFiltersLoaded = false;
29 let additionalSubscriptions = [];
29 let {getMessage} = browser.i18n; 30 let {getMessage} = browser.i18n;
30 let {setElementText} = ext.i18n; 31 let {setElementText} = ext.i18n;
31 let customFilters = []; 32 let customFilters = [];
32 let filterErrors = new Map([ 33 let filterErrors = new Map([
33 ["synchronize_invalid_url", 34 ["synchronize_invalid_url",
34 "options_filterList_lastDownload_invalidURL"], 35 "options_filterList_lastDownload_invalidURL"],
35 ["synchronize_connection_error", 36 ["synchronize_connection_error",
36 "options_filterList_lastDownload_connectionError"], 37 "options_filterList_lastDownload_connectionError"],
37 ["synchronize_invalid_data", 38 ["synchronize_invalid_data",
38 "options_filterList_lastDownload_invalidData"], 39 "options_filterList_lastDownload_invalidData"],
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 231 }
231 232
232 element.setAttribute("aria-label", title); 233 element.setAttribute("aria-label", title);
233 if (this.details[i].searchable) 234 if (this.details[i].searchable)
234 element.setAttribute("data-search", title.toLowerCase()); 235 element.setAttribute("data-search", title.toLowerCase());
235 let controls = element.querySelectorAll(".control[role='checkbox']"); 236 let controls = element.querySelectorAll(".control[role='checkbox']");
236 for (let control of controls) 237 for (let control of controls)
237 { 238 {
238 control.setAttribute("aria-checked", item.disabled == false); 239 control.setAttribute("aria-checked", item.disabled == false);
239 if (isAcceptableAds(item.url) && this == collections.filterLists) 240 if (isAcceptableAds(item.url) && this == collections.filterLists)
241 {
240 control.disabled = true; 242 control.disabled = true;
243 }
244 }
245 if (additionalSubscriptions.includes(item.url))
246 {
247 element.classList.add("preconfigured");
248 let disablePreconfigures =
249 element.querySelectorAll("[data-disable~='preconfigured']");
250 for (let disablePreconfigure of disablePreconfigures)
251 disablePreconfigure.disabled = true;
241 } 252 }
242 253
243 let lastUpdateElement = element.querySelector(".last-update"); 254 let lastUpdateElement = element.querySelector(".last-update");
244 if (lastUpdateElement) 255 if (lastUpdateElement)
245 { 256 {
246 let message = element.querySelector(".message"); 257 let message = element.querySelector(".message");
247 if (item.isDownloading) 258 if (item.isDownloading)
248 { 259 {
249 let text = getMessage("options_filterList_lastDownload_inProgress"); 260 let text = getMessage("options_filterList_lastDownload_inProgress");
250 message.textContent = text; 261 message.textContent = text;
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 }); 943 });
933 944
934 // Advanced tab 945 // Advanced tab
935 let customize = document.querySelectorAll("#customize li[data-pref]"); 946 let customize = document.querySelectorAll("#customize li[data-pref]");
936 customize = Array.prototype.map.call(customize, (checkbox) => 947 customize = Array.prototype.map.call(customize, (checkbox) =>
937 { 948 {
938 return checkbox.getAttribute("data-pref"); 949 return checkbox.getAttribute("data-pref");
939 }); 950 });
940 for (let key of customize) 951 for (let key of customize)
941 { 952 {
942 getPref(key, (value) => 953 getHidePref(key, (value) =>
943 { 954 {
944 onPrefMessage(key, value, true); 955 onPrefMessage(key, value, true);
945 }); 956 });
946 } 957 }
947 browser.runtime.sendMessage({ 958 browser.runtime.sendMessage({
948 type: "app.get", 959 type: "app.get",
949 what: "features" 960 what: "features"
950 }, 961 },
951 (features) => 962 (features) =>
952 { 963 {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 } 1123 }
1113 return acceptableAdsList && acceptableAdsList.disabled == false && 1124 return acceptableAdsList && acceptableAdsList.disabled == false &&
1114 privacyList && privacyList.disabled == false; 1125 privacyList && privacyList.disabled == false;
1115 } 1126 }
1116 1127
1117 function setPrivacyConflict() 1128 function setPrivacyConflict()
1118 { 1129 {
1119 let acceptableAdsForm = E("acceptable-ads"); 1130 let acceptableAdsForm = E("acceptable-ads");
1120 if (hasPrivacyConflict()) 1131 if (hasPrivacyConflict())
1121 { 1132 {
1122 getPref("ui_warn_tracking", (showTrackingWarning) => 1133 getHidePref("ui_warn_tracking", (showTrackingWarning) =>
1123 { 1134 {
1124 acceptableAdsForm.classList.toggle("show-warning", showTrackingWarning); 1135 acceptableAdsForm.classList.toggle("show-warning", showTrackingWarning);
1125 }); 1136 });
1126 } 1137 }
1127 else 1138 else
1128 { 1139 {
1129 acceptableAdsForm.classList.remove("show-warning"); 1140 acceptableAdsForm.classList.remove("show-warning");
1130 } 1141 }
1131 } 1142 }
1132 1143
(...skipping 14 matching lines...) Expand all
1147 (subscriptions) => 1158 (subscriptions) =>
1148 { 1159 {
1149 let customFilterPromises = subscriptions.map(getSubscriptionFilters); 1160 let customFilterPromises = subscriptions.map(getSubscriptionFilters);
1150 Promise.all(customFilterPromises).then((filters) => 1161 Promise.all(customFilterPromises).then((filters) =>
1151 { 1162 {
1152 loadCustomFilters([].concat(...filters)); 1163 loadCustomFilters([].concat(...filters));
1153 isCustomFiltersLoaded = true; 1164 isCustomFiltersLoaded = true;
1154 }); 1165 });
1155 }); 1166 });
1156 loadRecommendations(); 1167 loadRecommendations();
1157 browser.runtime.sendMessage({ 1168 let preloadPrefs = ["subscriptions_exceptionsurl",
1158 type: "prefs.get", 1169 "subscriptions_exceptionsurl_privacy",
1159 key: "subscriptions_exceptionsurl" 1170 "additional_subscriptions"];
1160 }, 1171 getPrefs(preloadPrefs).then(prefs =>
1161 (url) =>
1162 { 1172 {
1163 acceptableAdsUrl = url; 1173 [acceptableAdsUrl, acceptableAdsPrivacyUrl,
1174 additionalSubscriptions] = prefs;
1164 1175
1165 browser.runtime.sendMessage({ 1176 return browser.runtime.sendMessage({
1166 type: "prefs.get", 1177 type: "subscriptions.get",
1167 key: "subscriptions_exceptionsurl_privacy" 1178 downloadable: true
1168 }, 1179 });
1169 (urlPrivacy) => 1180 }).then((subscriptions) =>
1170 { 1181 {
1171 acceptableAdsPrivacyUrl = urlPrivacy; 1182 for (let subscription of subscriptions)
1183 onSubscriptionMessage("added", subscription);
1172 1184
1173 // Load user subscriptions 1185 setAcceptableAds();
1174 browser.runtime.sendMessage({
1175 type: "subscriptions.get",
1176 downloadable: true
1177 },
1178 (subscriptions) =>
1179 {
1180 for (let subscription of subscriptions)
1181 onSubscriptionMessage("added", subscription);
1182
1183 setAcceptableAds();
1184 });
1185 });
1186 }); 1186 });
1187 } 1187 }
1188 1188
1189 function addWhitelistedDomain() 1189 function addWhitelistedDomain()
1190 { 1190 {
1191 let domain = E("whitelisting-textbox"); 1191 let domain = E("whitelisting-textbox");
1192 for (let whitelistItem of collections.whitelist.items) 1192 for (let whitelistItem of collections.whitelist.items)
1193 { 1193 {
1194 if (whitelistItem.title == domain.value) 1194 if (whitelistItem.title == domain.value)
1195 { 1195 {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 subscriptionUrl: subscription.url}); 1335 subscriptionUrl: subscription.url});
1336 } 1336 }
1337 1337
1338 function hidePref(key, value) 1338 function hidePref(key, value)
1339 { 1339 {
1340 let element = document.querySelector("[data-pref='" + key + "']"); 1340 let element = document.querySelector("[data-pref='" + key + "']");
1341 if (element) 1341 if (element)
1342 element.setAttribute("aria-hidden", value); 1342 element.setAttribute("aria-hidden", value);
1343 } 1343 }
1344 1344
1345 function getPref(key, callback) 1345 function getPrefs(prefKeys)
1346 { 1346 {
1347 let checkPref = getPref.checks[key] || getPref.checkNone; 1347 prefKeys = prefKeys.map(key => browser.runtime.sendMessage({
1348 type: "prefs.get", key
1349 }));
1350 return Promise.all(prefKeys);
1351 }
1352
1353 function getHidePref(key, callback)
1354 {
1355 let checkPref = getHidePref.checks[key] || getHidePref.checkNone;
1348 checkPref((isActive) => 1356 checkPref((isActive) =>
1349 { 1357 {
1350 if (!isActive) 1358 if (!isActive)
1351 { 1359 {
1352 hidePref(key, !isActive); 1360 hidePref(key, !isActive);
1353 return; 1361 return;
1354 } 1362 }
1355 1363
1356 browser.runtime.sendMessage({ 1364 browser.runtime.sendMessage({
1357 type: "prefs.get", 1365 type: "prefs.get",
1358 key 1366 key
1359 }, callback); 1367 }, callback);
1360 }); 1368 });
1361 } 1369 }
1362 1370
1363 getPref.checkNone = function(callback) 1371 getHidePref.checkNone = function(callback)
1364 { 1372 {
1365 callback(true); 1373 callback(true);
1366 }; 1374 };
1367 1375
1368 getPref.checks = 1376 getHidePref.checks =
1369 { 1377 {
1370 notifications_ignoredcategories(callback) 1378 notifications_ignoredcategories(callback)
1371 { 1379 {
1372 getPref("notifications_showui", callback); 1380 getHidePref("notifications_showui", callback);
1373 } 1381 }
1374 }; 1382 };
1375 1383
1376 function onPrefMessage(key, value, initial) 1384 function onPrefMessage(key, value, initial)
1377 { 1385 {
1378 switch (key) 1386 switch (key)
1379 { 1387 {
1380 case "notifications_ignoredcategories": 1388 case "notifications_ignoredcategories":
1381 value = value.indexOf("*") == -1; 1389 value = value.indexOf("*") == -1;
1382 break; 1390 break;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 "ui_warn_tracking"] 1473 "ui_warn_tracking"]
1466 }); 1474 });
1467 browser.runtime.sendMessage({ 1475 browser.runtime.sendMessage({
1468 type: "subscriptions.listen", 1476 type: "subscriptions.listen",
1469 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1477 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1470 "title", "downloadStatus", "downloading"] 1478 "title", "downloadStatus", "downloading"]
1471 }); 1479 });
1472 1480
1473 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1481 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1474 window.addEventListener("hashchange", onHashChange, false); 1482 window.addEventListener("hashchange", onHashChange, false);
OLDNEW
« no previous file with comments | « desktop-options.html ('k') | skin/icons/checkbox.svg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld