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

Delta Between Two Patch Sets: new-options.js

Issue 29519669: Issue 5539 - Implement "Acceptable Ads notification" (Closed)
Left Patch Set: Rebased Created Sept. 18, 2017, 10:40 a.m.
Right Patch Set: Addressed Thomas comment from patchset 6 Created Sept. 22, 2017, 10:28 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 11 matching lines...) Expand all
22 22
23 { 23 {
24 let subscriptionsMap = Object.create(null); 24 let subscriptionsMap = Object.create(null);
25 let filtersMap = Object.create(null); 25 let filtersMap = Object.create(null);
26 let collections = Object.create(null); 26 let collections = Object.create(null);
27 let acceptableAdsUrl = null; 27 let acceptableAdsUrl = null;
28 let acceptableAdsPrivacyUrl = null; 28 let acceptableAdsPrivacyUrl = null;
29 let isCustomFiltersLoaded = false; 29 let isCustomFiltersLoaded = false;
30 let {getMessage} = ext.i18n; 30 let {getMessage} = ext.i18n;
31 let customFilters = []; 31 let customFilters = [];
32 let showTrackingWarning = false;
33 let filterErrors = new Map([ 32 let filterErrors = new Map([
34 ["synchronize_invalid_url", 33 ["synchronize_invalid_url",
35 "options_filterList_lastDownload_invalidURL"], 34 "options_filterList_lastDownload_invalidURL"],
36 ["synchronize_connection_error", 35 ["synchronize_connection_error",
37 "options_filterList_lastDownload_connectionError"], 36 "options_filterList_lastDownload_connectionError"],
38 ["synchronize_invalid_data", 37 ["synchronize_invalid_data",
39 "options_filterList_lastDownload_invalidData"], 38 "options_filterList_lastDownload_invalidData"],
40 ["synchronize_checksum_mismatch", 39 ["synchronize_checksum_mismatch",
41 "options_filterList_lastDownload_checksumMismatch"] 40 "options_filterList_lastDownload_checksumMismatch"]
42 ]); 41 ]);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 ]); 365 ]);
367 collections.filterLists = new Collection([ 366 collections.filterLists = new Collection([
368 { 367 {
369 id: "all-filter-lists-table", 368 id: "all-filter-lists-table",
370 useOriginalTitle: true 369 useOriginalTitle: true
371 } 370 }
372 ]); 371 ]);
373 372
374 function addSubscription(subscription) 373 function addSubscription(subscription)
375 { 374 {
376 let disabled = subscription.disabled; 375 let {disabled} = subscription;
377 let collection = null; 376 let collection = null;
378 if (subscription.recommended) 377 if (subscription.recommended)
379 { 378 {
380 if (subscription.recommended == "ads") 379 if (subscription.recommended == "ads")
381 { 380 {
382 if (disabled == false) 381 if (disabled == false)
383 collection = collections.langs; 382 collection = collections.langs;
384 383
385 collections.allLangs.addItem(subscription); 384 collections.allLangs.addItem(subscription);
386 } 385 }
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 ext.backgroundPage.sendMessage({ 670 ext.backgroundPage.sendMessage({
672 type: "subscriptions.update" 671 type: "subscriptions.update"
673 }); 672 });
674 break; 673 break;
675 case "update-subscription": 674 case "update-subscription":
676 ext.backgroundPage.sendMessage({ 675 ext.backgroundPage.sendMessage({
677 type: "subscriptions.update", 676 type: "subscriptions.update",
678 url: findParentData(element, "access", false) 677 url: findParentData(element, "access", false)
679 }); 678 });
680 break; 679 break;
680 case "validate-import-subscription":
681 let form = findParentData(element, "validation", true);
682 if (!form)
683 return;
684
685 if (form.checkValidity())
686 {
687 addEnableSubscription(E("import-list-url").value,
688 E("import-list-title").value);
689 form.reset();
690 closeDialog();
691 }
692 else
693 {
694 form.querySelector(":invalid").focus();
695 }
696 break;
681 } 697 }
682 } 698 }
683 699
684 function setCustomFiltersView(mode) 700 function setCustomFiltersView(mode)
685 { 701 {
686 let customFiltersElement = E("custom-filters-raw"); 702 let customFiltersElement = E("custom-filters-raw");
687 updateCustomFiltersUi(); 703 updateCustomFiltersUi();
688 if (mode == "read") 704 if (mode == "read")
689 { 705 {
690 customFiltersElement.disabled = true; 706 customFiltersElement.disabled = true;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 document.body.addEventListener("click", onClick, false); 850 document.body.addEventListener("click", onClick, false);
835 document.body.addEventListener("keyup", onKeyUp, false); 851 document.body.addEventListener("keyup", onKeyUp, false);
836 let exampleValue = getMessage("options_whitelist_placeholder_example", 852 let exampleValue = getMessage("options_whitelist_placeholder_example",
837 ["www.example.com"]); 853 ["www.example.com"]);
838 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); 854 E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
839 E("whitelisting-textbox").addEventListener("keyup", (e) => 855 E("whitelisting-textbox").addEventListener("keyup", (e) =>
840 { 856 {
841 E("whitelisting-add-button").disabled = !e.target.value; 857 E("whitelisting-add-button").disabled = !e.target.value;
842 }, false); 858 }, false);
843 859
844 getPref("ui_warn_tracking", (value) =>
845 {
846 showTrackingWarning = value;
847 });
848 getDocLink("contribute", (link) => 860 getDocLink("contribute", (link) =>
849 { 861 {
850 E("contribute").href = link; 862 E("contribute").href = link;
851 }); 863 });
852 getDocLink("acceptable_ads_criteria", (link) => 864 getDocLink("acceptable_ads_criteria", (link) =>
853 { 865 {
854 setLinks("enable-aa-description", link); 866 setLinks("enable-aa-description", link);
855 }); 867 });
856 868
857 // Advanced tab 869 // Advanced tab
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 updateSubscription(subscription); 1198 updateSubscription(subscription);
1187 break; 1199 break;
1188 case "downloading": 1200 case "downloading":
1189 case "downloadStatus": 1201 case "downloadStatus":
1190 case "homepage": 1202 case "homepage":
1191 case "lastDownload": 1203 case "lastDownload":
1192 case "title": 1204 case "title":
1193 updateSubscription(subscription); 1205 updateSubscription(subscription);
1194 break; 1206 break;
1195 case "added": 1207 case "added":
1196 let url = subscription.url; 1208 let {url, recommended} = subscription;
1197 if (url in subscriptionsMap) 1209 if (url in subscriptionsMap)
1198 updateSubscription(subscription); 1210 updateSubscription(subscription);
1199 else 1211 else
1200 addSubscription(subscription); 1212 addSubscription(subscription);
1201 1213
1202 if (isAcceptableAds(url)) 1214 if (isAcceptableAds(url))
1203 setAcceptableAds(); 1215 setAcceptableAds();
1204 1216
1205 if (url == acceptableAdsUrl || subscription.recommended == "privacy") 1217 if ((url == acceptableAdsUrl || recommended == "privacy") &&
1206 { 1218 hasPrivacyConflict())
1207 if (hasPrivacyConflict() && showTrackingWarning) 1219 {
1208 openDialog("tracking"); 1220 getPref("ui_warn_tracking", (showTrackingWarning) =>
1221 {
1222 if (showTrackingWarning)
1223 openDialog("tracking");
1224 });
1209 } 1225 }
1210 1226
1211 collections.filterLists.addItem(subscription); 1227 collections.filterLists.addItem(subscription);
1212 break; 1228 break;
1213 case "removed": 1229 case "removed":
1214 if (subscription.recommended) 1230 if (subscription.recommended)
1215 { 1231 {
1216 subscription.disabled = true; 1232 subscription.disabled = true;
1217 onSubscriptionMessage("disabled", subscription); 1233 onSubscriptionMessage("disabled", subscription);
1218 } 1234 }
1219 else 1235 else
1220 { 1236 {
1221 delete subscriptionsMap[subscription.url]; 1237 delete subscriptionsMap[subscription.url];
1222 if (isAcceptableAds(subscription.url)) 1238 if (isAcceptableAds(subscription.url))
1223 { 1239 {
1224 setAcceptableAds(); 1240 setAcceptableAds();
1225 } 1241 }
1226 else 1242 else
1227 { 1243 {
1228 collections.more.removeItem(subscription); 1244 collections.more.removeItem(subscription);
1229 } 1245 }
1230 } 1246 }
1231 collections.filterLists.removeItem(subscription); 1247 collections.filterLists.removeItem(subscription);
1232 break; 1248 break;
1233 } 1249 }
1234
1235 } 1250 }
1236 1251
1237 function hidePref(key, value) 1252 function hidePref(key, value)
1238 { 1253 {
1239 let element = document.querySelector("[data-pref='" + key + "']"); 1254 let element = document.querySelector("[data-pref='" + key + "']");
1240 if (element) 1255 if (element)
1241 element.setAttribute("aria-hidden", value); 1256 element.setAttribute("aria-hidden", value);
1242 } 1257 }
1243 1258
1244 function getPref(key, callback) 1259 function getPref(key, callback)
(...skipping 30 matching lines...) Expand all
1275 function onPrefMessage(key, value, initial) 1290 function onPrefMessage(key, value, initial)
1276 { 1291 {
1277 switch (key) 1292 switch (key)
1278 { 1293 {
1279 case "notifications_ignoredcategories": 1294 case "notifications_ignoredcategories":
1280 value = value.indexOf("*") == -1; 1295 value = value.indexOf("*") == -1;
1281 break; 1296 break;
1282 1297
1283 case "notifications_showui": 1298 case "notifications_showui":
1284 hidePref("notifications_ignoredcategories", !value); 1299 hidePref("notifications_ignoredcategories", !value);
1285 break;
1286
1287 case "ui_warn_tracking":
1288 showTrackingWarning = value;
1289 break; 1300 break;
1290 } 1301 }
1291 1302
1292 let checkbox = document.querySelector( 1303 let checkbox = document.querySelector(
1293 "[data-pref='" + key + "'] button[role='checkbox']" 1304 "[data-pref='" + key + "'] button[role='checkbox']"
1294 ); 1305 );
1295 if (checkbox) 1306 if (checkbox)
1296 checkbox.setAttribute("aria-checked", value); 1307 checkbox.setAttribute("aria-checked", value);
1297 } 1308 }
1298 1309
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 }); 1377 });
1367 ext.backgroundPage.sendMessage({ 1378 ext.backgroundPage.sendMessage({
1368 type: "subscriptions.listen", 1379 type: "subscriptions.listen",
1369 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1380 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1370 "title", "downloadStatus", "downloading"] 1381 "title", "downloadStatus", "downloading"]
1371 }); 1382 });
1372 1383
1373 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1384 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1374 window.addEventListener("hashchange", onHashChange, false); 1385 window.addEventListener("hashchange", onHashChange, false);
1375 } 1386 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld