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

Side by Side Diff: new-options.js

Issue 29519669: Issue 5539 - Implement "Acceptable Ads notification" (Closed)
Patch Set: Rebased Created Sept. 22, 2017, 10:05 a.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 | « new-options.html ('k') | skin/new-options.css » ('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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ]); 365 ]);
366 collections.filterLists = new Collection([ 366 collections.filterLists = new Collection([
367 { 367 {
368 id: "all-filter-lists-table", 368 id: "all-filter-lists-table",
369 useOriginalTitle: true 369 useOriginalTitle: true
370 } 370 }
371 ]); 371 ]);
372 372
373 function addSubscription(subscription) 373 function addSubscription(subscription)
374 { 374 {
375 let disabled = subscription.disabled; 375 let {disabled} = subscription;
376 let collection = null; 376 let collection = null;
377 if (subscription.recommended) 377 if (subscription.recommended)
378 { 378 {
379 if (subscription.recommended == "ads") 379 if (subscription.recommended == "ads")
380 { 380 {
381 if (disabled == false) 381 if (disabled == false)
382 collection = collections.langs; 382 collection = collections.langs;
383 383
384 collections.allLangs.addItem(subscription); 384 collections.allLangs.addItem(subscription);
385 } 385 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 type: "filters.importRaw", 620 type: "filters.importRaw",
621 text: E("custom-filters-raw").value, 621 text: E("custom-filters-raw").value,
622 removeExisting: true 622 removeExisting: true
623 }, 623 },
624 () => 624 () =>
625 { 625 {
626 setCustomFiltersView("read"); 626 setCustomFiltersView("read");
627 }); 627 });
628 break; 628 break;
629 case "switch-acceptable-ads": 629 case "switch-acceptable-ads":
630 let {value} = element; 630 let value = element.value || element.dataset.value;
631 ext.backgroundPage.sendMessage({ 631 ext.backgroundPage.sendMessage({
632 type: value == "privacy" ? "subscriptions.add" : 632 type: value == "privacy" ? "subscriptions.add" :
633 "subscriptions.remove", 633 "subscriptions.remove",
634 url: acceptableAdsPrivacyUrl 634 url: acceptableAdsPrivacyUrl
635 }); 635 });
636 ext.backgroundPage.sendMessage({ 636 ext.backgroundPage.sendMessage({
637 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", 637 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove",
638 url: acceptableAdsUrl 638 url: acceptableAdsUrl
639 }); 639 });
640 break; 640 break;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 document.body.addEventListener("click", onClick, false); 850 document.body.addEventListener("click", onClick, false);
851 document.body.addEventListener("keyup", onKeyUp, false); 851 document.body.addEventListener("keyup", onKeyUp, false);
852 let exampleValue = getMessage("options_whitelist_placeholder_example", 852 let exampleValue = getMessage("options_whitelist_placeholder_example",
853 ["www.example.com"]); 853 ["www.example.com"]);
854 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); 854 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
855 E("whitelisting-textbox").addEventListener("keyup", (e) => 855 E("whitelisting-textbox").addEventListener("keyup", (e) =>
856 { 856 {
857 E("whitelisting-add-button").disabled = !e.target.value; 857 E("whitelisting-add-button").disabled = !e.target.value;
858 }, false); 858 }, false);
859 859
860
861 getDocLink("contribute", (link) => 860 getDocLink("contribute", (link) =>
862 { 861 {
863 E("contribute").href = link; 862 E("contribute").href = link;
864 }); 863 });
865 getDocLink("acceptable_ads_criteria", (link) => 864 getDocLink("acceptable_ads_criteria", (link) =>
866 { 865 {
867 setLinks("enable-aa-description", link); 866 setLinks("enable-aa-description", link);
868 }); 867 });
869 868
870 // Advanced tab 869 // Advanced tab
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 document.forms["acceptable-ads"].classList.add("show-dnt-notification"); 1018 document.forms["acceptable-ads"].classList.add("show-dnt-notification");
1020 } 1019 }
1021 document.forms["acceptable-ads"]["acceptable-ads"].value = option; 1020 document.forms["acceptable-ads"]["acceptable-ads"].value = option;
1022 } 1021 }
1023 1022
1024 function isAcceptableAds(url) 1023 function isAcceptableAds(url)
1025 { 1024 {
1026 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl; 1025 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl;
1027 } 1026 }
1028 1027
1028 function hasPrivacyConflict()
1029 {
1030 let acceptableAdsList = subscriptionsMap[acceptableAdsUrl];
1031 let privacyList = null;
1032 for (let url in subscriptionsMap)
1033 {
1034 let subscription = subscriptionsMap[url];
1035 if (subscription.recommended == "privacy")
1036 {
1037 privacyList = subscription;
1038 break;
1039 }
1040 }
1041 return acceptableAdsList && acceptableAdsList.disabled == false &&
1042 privacyList && privacyList.disabled == false;
1043 }
1044
1029 function populateLists() 1045 function populateLists()
1030 { 1046 {
1031 subscriptionsMap = Object.create(null); 1047 subscriptionsMap = Object.create(null);
1032 filtersMap = Object.create(null); 1048 filtersMap = Object.create(null);
1033 1049
1034 // Empty collections and lists 1050 // Empty collections and lists
1035 for (let property in collections) 1051 for (let property in collections)
1036 collections[property].clearAll(); 1052 collections[property].clearAll();
1037 1053
1038 ext.backgroundPage.sendMessage({ 1054 ext.backgroundPage.sendMessage({
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 updateSubscription(subscription); 1198 updateSubscription(subscription);
1183 break; 1199 break;
1184 case "downloading": 1200 case "downloading":
1185 case "downloadStatus": 1201 case "downloadStatus":
1186 case "homepage": 1202 case "homepage":
1187 case "lastDownload": 1203 case "lastDownload":
1188 case "title": 1204 case "title":
1189 updateSubscription(subscription); 1205 updateSubscription(subscription);
1190 break; 1206 break;
1191 case "added": 1207 case "added":
1192 if (subscription.url in subscriptionsMap) 1208 let {url} = subscription;
1209 if (url in subscriptionsMap)
1193 updateSubscription(subscription); 1210 updateSubscription(subscription);
1194 else 1211 else
1195 addSubscription(subscription); 1212 addSubscription(subscription);
1196 1213
1197 if (isAcceptableAds(subscription.url)) 1214 if (isAcceptableAds(url))
1198 setAcceptableAds(); 1215 setAcceptableAds();
1199 1216
1217 if (url == acceptableAdsUrl || subscription.recommended == "privacy")
1218 {
1219 getPref("ui_warn_tracking", (showTrackingWarning) =>
1220 {
1221 if (hasPrivacyConflict() && showTrackingWarning)
1222 openDialog("tracking");
1223 });
1224 }
1225
1200 collections.filterLists.addItem(subscription); 1226 collections.filterLists.addItem(subscription);
1201 break; 1227 break;
1202 case "removed": 1228 case "removed":
1203 if (subscription.recommended) 1229 if (subscription.recommended)
1204 { 1230 {
1205 subscription.disabled = true; 1231 subscription.disabled = true;
1206 onSubscriptionMessage("disabled", subscription); 1232 onSubscriptionMessage("disabled", subscription);
1207 } 1233 }
1208 else 1234 else
1209 { 1235 {
1210 delete subscriptionsMap[subscription.url]; 1236 delete subscriptionsMap[subscription.url];
1211 if (isAcceptableAds(subscription.url)) 1237 if (isAcceptableAds(subscription.url))
1212 { 1238 {
1213 setAcceptableAds(); 1239 setAcceptableAds();
1214 } 1240 }
1215 else 1241 else
1216 { 1242 {
1217 collections.more.removeItem(subscription); 1243 collections.more.removeItem(subscription);
1218 } 1244 }
1219 } 1245 }
1220 collections.filterLists.removeItem(subscription); 1246 collections.filterLists.removeItem(subscription);
1221 break; 1247 break;
1222 } 1248 }
1223
1224 } 1249 }
1225 1250
1226 function hidePref(key, value) 1251 function hidePref(key, value)
1227 { 1252 {
1228 let element = document.querySelector("[data-pref='" + key + "']"); 1253 let element = document.querySelector("[data-pref='" + key + "']");
1229 if (element) 1254 if (element)
1230 element.setAttribute("aria-hidden", value); 1255 element.setAttribute("aria-hidden", value);
1231 } 1256 }
1232 1257
1233 function getPref(key, callback) 1258 function getPref(key, callback)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 type: "app.listen", 1364 type: "app.listen",
1340 filter: ["addSubscription", "focusSection"] 1365 filter: ["addSubscription", "focusSection"]
1341 }); 1366 });
1342 ext.backgroundPage.sendMessage({ 1367 ext.backgroundPage.sendMessage({
1343 type: "filters.listen", 1368 type: "filters.listen",
1344 filter: ["added", "loaded", "removed"] 1369 filter: ["added", "loaded", "removed"]
1345 }); 1370 });
1346 ext.backgroundPage.sendMessage({ 1371 ext.backgroundPage.sendMessage({
1347 type: "prefs.listen", 1372 type: "prefs.listen",
1348 filter: ["notifications_ignoredcategories", "notifications_showui", 1373 filter: ["notifications_ignoredcategories", "notifications_showui",
1349 "show_devtools_panel", "shouldShowBlockElementMenu"] 1374 "show_devtools_panel", "shouldShowBlockElementMenu",
1375 "ui_warn_tracking"]
1350 }); 1376 });
1351 ext.backgroundPage.sendMessage({ 1377 ext.backgroundPage.sendMessage({
1352 type: "subscriptions.listen", 1378 type: "subscriptions.listen",
1353 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1379 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1354 "title", "downloadStatus", "downloading"] 1380 "title", "downloadStatus", "downloading"]
1355 }); 1381 });
1356 1382
1357 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1383 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1358 window.addEventListener("hashchange", onHashChange, false); 1384 window.addEventListener("hashchange", onHashChange, false);
1359 } 1385 }
OLDNEW
« no previous file with comments | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld