| LEFT | RIGHT |
| 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 { | 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 isSubscriptionsLoaded = false; | |
| 31 let {getMessage} = ext.i18n; | 30 let {getMessage} = ext.i18n; |
| 32 let customFilters = []; | 31 let customFilters = []; |
| 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", |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 id: "blocking-languages-table", | 345 id: "blocking-languages-table", |
| 347 emptyText: ["options_language_empty"] | 346 emptyText: ["options_language_empty"] |
| 348 } | 347 } |
| 349 ]); | 348 ]); |
| 350 collections.allLangs = new Collection([ | 349 collections.allLangs = new Collection([ |
| 351 { | 350 { |
| 352 id: "all-lang-table-add", | 351 id: "all-lang-table-add", |
| 353 emptyText: ["options_dialog_language_other_empty"] | 352 emptyText: ["options_dialog_language_other_empty"] |
| 354 } | 353 } |
| 355 ]); | 354 ]); |
| 356 collections.custom = new Collection([ | 355 collections.more = new Collection([ |
| 357 { | 356 { |
| 358 id: "custom-list-table" | 357 id: "more-list-table" |
| 359 } | 358 } |
| 360 ]); | 359 ]); |
| 361 collections.whitelist = new Collection([ | 360 collections.whitelist = new Collection([ |
| 362 { | 361 { |
| 363 id: "whitelisting-table", | 362 id: "whitelisting-table", |
| 364 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] | 363 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] |
| 365 } | 364 } |
| 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 { |
| 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 (subscription.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 } |
| 386 else | 386 else |
| 387 { | 387 { |
| 388 collection = collections.protection; | 388 collection = collections.protection; |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 else if (!isAcceptableAds(subscription.url)) | 391 else if (!isAcceptableAds(subscription.url) && disabled == false) |
| 392 { | 392 { |
| 393 collection = collections.custom; | 393 collection = collections.more; |
| 394 } | 394 } |
| 395 | 395 |
| 396 if (collection) | 396 if (collection) |
| 397 collection.addItem(subscription); | 397 collection.addItem(subscription); |
| 398 | 398 |
| 399 subscriptionsMap[subscription.url] = subscription; | 399 subscriptionsMap[subscription.url] = subscription; |
| 400 updateTooltips(); | 400 updateTooltips(); |
| 401 } | 401 } |
| 402 | 402 |
| 403 function updateSubscription(subscription) | 403 function updateSubscription(subscription) |
| 404 { | 404 { |
| 405 for (let name in collections) | 405 for (let name in collections) |
| 406 collections[name].updateItem(subscription); | 406 collections[name].updateItem(subscription); |
| 407 | 407 |
| 408 if (subscription.recommended == "ads") | 408 if (subscription.recommended == "ads") |
| 409 { | 409 { |
| 410 if (subscription.disabled) | 410 if (subscription.disabled) |
| 411 collections.langs.removeItem(subscription); | 411 collections.langs.removeItem(subscription); |
| 412 else | 412 else |
| 413 collections.langs.addItem(subscription); | 413 collections.langs.addItem(subscription); |
| 414 } | 414 } |
| 415 else if (!subscription.recommended && !isAcceptableAds(subscription.url)) | 415 else if (!subscription.recommended && !isAcceptableAds(subscription.url)) |
| 416 { | 416 { |
| 417 if (subscription.disabled == false) | 417 if (subscription.disabled == false) |
| 418 { | 418 { |
| 419 collections.custom.addItem(subscription); | 419 collections.more.addItem(subscription); |
| 420 updateTooltips(); | 420 updateTooltips(); |
| 421 } | 421 } |
| 422 else | 422 else |
| 423 { | 423 { |
| 424 collections.custom.removeItem(subscription); | 424 collections.more.removeItem(subscription); |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 function updateFilter(filter) | 429 function updateFilter(filter) |
| 430 { | 430 { |
| 431 let match = filter.text.match(whitelistedDomainRegexp); | 431 let match = filter.text.match(whitelistedDomainRegexp); |
| 432 if (match && !filtersMap[filter.text]) | 432 if (match && !filtersMap[filter.text]) |
| 433 { | 433 { |
| 434 filter.title = match[1]; | 434 filter.title = match[1]; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 29 matching lines...) Expand all Loading... |
| 670 ext.backgroundPage.sendMessage({ | 670 ext.backgroundPage.sendMessage({ |
| 671 type: "subscriptions.update" | 671 type: "subscriptions.update" |
| 672 }); | 672 }); |
| 673 break; | 673 break; |
| 674 case "update-subscription": | 674 case "update-subscription": |
| 675 ext.backgroundPage.sendMessage({ | 675 ext.backgroundPage.sendMessage({ |
| 676 type: "subscriptions.update", | 676 type: "subscriptions.update", |
| 677 url: findParentData(element, "access", false) | 677 url: findParentData(element, "access", false) |
| 678 }); | 678 }); |
| 679 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; |
| 680 } | 697 } |
| 681 } | 698 } |
| 682 | 699 |
| 683 function setCustomFiltersView(mode) | 700 function setCustomFiltersView(mode) |
| 684 { | 701 { |
| 685 let customFiltersElement = E("custom-filters-raw"); | 702 let customFiltersElement = E("custom-filters-raw"); |
| 686 updateCustomFiltersUi(); | 703 updateCustomFiltersUi(); |
| 687 if (mode == "read") | 704 if (mode == "read") |
| 688 { | 705 { |
| 689 customFiltersElement.disabled = true; | 706 customFiltersElement.disabled = true; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 // Initialize interactive UI elements | 849 // Initialize interactive UI elements |
| 833 document.body.addEventListener("click", onClick, false); | 850 document.body.addEventListener("click", onClick, false); |
| 834 document.body.addEventListener("keyup", onKeyUp, false); | 851 document.body.addEventListener("keyup", onKeyUp, false); |
| 835 let exampleValue = getMessage("options_whitelist_placeholder_example", | 852 let exampleValue = getMessage("options_whitelist_placeholder_example", |
| 836 ["www.example.com"]); | 853 ["www.example.com"]); |
| 837 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); | 854 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); |
| 838 E("whitelisting-textbox").addEventListener("keyup", (e) => | 855 E("whitelisting-textbox").addEventListener("keyup", (e) => |
| 839 { | 856 { |
| 840 E("whitelisting-add-button").disabled = !e.target.value; | 857 E("whitelisting-add-button").disabled = !e.target.value; |
| 841 }, false); | 858 }, false); |
| 842 | |
| 843 | 859 |
| 844 getDocLink("contribute", (link) => | 860 getDocLink("contribute", (link) => |
| 845 { | 861 { |
| 846 E("contribute").href = link; | 862 E("contribute").href = link; |
| 847 }); | 863 }); |
| 848 getDocLink("acceptable_ads_criteria", (link) => | 864 getDocLink("acceptable_ads_criteria", (link) => |
| 849 { | 865 { |
| 850 setLinks("enable-aa-description", link); | 866 setLinks("enable-aa-description", link); |
| 851 }); | 867 }); |
| 852 | 868 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 document.forms["acceptable-ads"].classList.add("show-dnt-notification"); | 1018 document.forms["acceptable-ads"].classList.add("show-dnt-notification"); |
| 1003 } | 1019 } |
| 1004 document.forms["acceptable-ads"]["acceptable-ads"].value = option; | 1020 document.forms["acceptable-ads"]["acceptable-ads"].value = option; |
| 1005 } | 1021 } |
| 1006 | 1022 |
| 1007 function isAcceptableAds(url) | 1023 function isAcceptableAds(url) |
| 1008 { | 1024 { |
| 1009 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl; | 1025 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl; |
| 1010 } | 1026 } |
| 1011 | 1027 |
| 1012 function isPrivacyAndAdsEnabled() | 1028 function hasPrivacyConflict() |
| 1013 { | 1029 { |
| 1014 let isAcceptableAds = subscriptionsMap[acceptableAdsUrl]; | 1030 let acceptableAdsList = subscriptionsMap[acceptableAdsUrl]; |
| 1015 isAcceptableAds = isAcceptableAds && isAcceptableAds.disabled == false; | 1031 let privacyList = null; |
| 1016 for (let url in subscriptionsMap) | 1032 for (let url in subscriptionsMap) |
| 1017 { | 1033 { |
| 1018 let subscription = subscriptionsMap[url]; | 1034 let subscription = subscriptionsMap[url]; |
| 1019 if (subscription.recommended == "privacy") | 1035 if (subscription.recommended == "privacy") |
| 1020 return subscription.disabled == false && isAcceptableAds; | 1036 { |
| 1021 } | 1037 privacyList = subscription; |
| 1038 break; |
| 1039 } |
| 1040 } |
| 1041 return acceptableAdsList && acceptableAdsList.disabled == false && |
| 1042 privacyList && privacyList.disabled == false; |
| 1022 } | 1043 } |
| 1023 | 1044 |
| 1024 function populateLists() | 1045 function populateLists() |
| 1025 { | 1046 { |
| 1026 subscriptionsMap = Object.create(null); | 1047 subscriptionsMap = Object.create(null); |
| 1027 filtersMap = Object.create(null); | 1048 filtersMap = Object.create(null); |
| 1028 | 1049 |
| 1029 // Empty collections and lists | 1050 // Empty collections and lists |
| 1030 for (let property in collections) | 1051 for (let property in collections) |
| 1031 collections[property].clearAll(); | 1052 collections[property].clearAll(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 | 1097 |
| 1077 // Load user subscriptions | 1098 // Load user subscriptions |
| 1078 ext.backgroundPage.sendMessage({ | 1099 ext.backgroundPage.sendMessage({ |
| 1079 type: "subscriptions.get", | 1100 type: "subscriptions.get", |
| 1080 downloadable: true | 1101 downloadable: true |
| 1081 }, | 1102 }, |
| 1082 (subscriptions) => | 1103 (subscriptions) => |
| 1083 { | 1104 { |
| 1084 for (let subscription of subscriptions) | 1105 for (let subscription of subscriptions) |
| 1085 onSubscriptionMessage("added", subscription); | 1106 onSubscriptionMessage("added", subscription); |
| 1086 isSubscriptionsLoaded = true; | |
| 1087 }); | 1107 }); |
| 1088 }); | 1108 }); |
| 1089 }); | 1109 }); |
| 1090 } | 1110 } |
| 1091 | 1111 |
| 1092 function addWhitelistedDomain() | 1112 function addWhitelistedDomain() |
| 1093 { | 1113 { |
| 1094 let domain = E("whitelisting-textbox"); | 1114 let domain = E("whitelisting-textbox"); |
| 1095 for (let whitelistItem of collections.whitelist.items) | 1115 for (let whitelistItem of collections.whitelist.items) |
| 1096 { | 1116 { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 updateSubscription(subscription); | 1198 updateSubscription(subscription); |
| 1179 break; | 1199 break; |
| 1180 case "downloading": | 1200 case "downloading": |
| 1181 case "downloadStatus": | 1201 case "downloadStatus": |
| 1182 case "homepage": | 1202 case "homepage": |
| 1183 case "lastDownload": | 1203 case "lastDownload": |
| 1184 case "title": | 1204 case "title": |
| 1185 updateSubscription(subscription); | 1205 updateSubscription(subscription); |
| 1186 break; | 1206 break; |
| 1187 case "added": | 1207 case "added": |
| 1188 let url = subscription.url; | 1208 let {url, recommended} = subscription; |
| 1189 if (url in subscriptionsMap) | 1209 if (url in subscriptionsMap) |
| 1190 updateSubscription(subscription); | 1210 updateSubscription(subscription); |
| 1191 else | 1211 else |
| 1192 addSubscription(subscription); | 1212 addSubscription(subscription); |
| 1193 | 1213 |
| 1194 if (isAcceptableAds(url)) | 1214 if (isAcceptableAds(url)) |
| 1195 setAcceptableAds(); | 1215 setAcceptableAds(); |
| 1196 | 1216 |
| 1197 if (url == acceptableAdsPrivacyUrl) | 1217 if ((url == acceptableAdsUrl || recommended == "privacy") && |
| 1198 { | 1218 hasPrivacyConflict()) |
| 1199 if (!navigator.doNotTrack) | 1219 { |
| 1200 setDntNotification(true); | 1220 getPref("ui_warn_tracking", (showTrackingWarning) => |
| 1201 } | 1221 { |
| 1202 | 1222 if (showTrackingWarning) |
| 1203 if (url == acceptableAdsUrl || subscription.recommended == "privacy") | 1223 openDialog("tracking"); |
| 1204 { | 1224 }); |
| 1205 if (isSubscriptionsLoaded && isPrivacyAndAdsEnabled()) | |
| 1206 openDialog("tracking"); | |
| 1207 } | 1225 } |
| 1208 | 1226 |
| 1209 collections.filterLists.addItem(subscription); | 1227 collections.filterLists.addItem(subscription); |
| 1210 break; | 1228 break; |
| 1211 case "removed": | 1229 case "removed": |
| 1212 if (subscription.recommended) | 1230 if (subscription.recommended) |
| 1213 { | 1231 { |
| 1214 subscription.disabled = true; | 1232 subscription.disabled = true; |
| 1215 onSubscriptionMessage("disabled", subscription); | 1233 onSubscriptionMessage("disabled", subscription); |
| 1216 } | 1234 } |
| 1217 else | 1235 else |
| 1218 { | 1236 { |
| 1219 delete subscriptionsMap[subscription.url]; | 1237 delete subscriptionsMap[subscription.url]; |
| 1220 if (isAcceptableAds(subscription.url)) | 1238 if (isAcceptableAds(subscription.url)) |
| 1221 { | 1239 { |
| 1222 setAcceptableAds(); | 1240 setAcceptableAds(); |
| 1223 } | 1241 } |
| 1224 else | 1242 else |
| 1225 { | 1243 { |
| 1226 collections.custom.removeItem(subscription); | 1244 collections.more.removeItem(subscription); |
| 1227 } | 1245 } |
| 1228 } | 1246 } |
| 1229 collections.filterLists.removeItem(subscription); | 1247 collections.filterLists.removeItem(subscription); |
| 1230 break; | 1248 break; |
| 1231 } | 1249 } |
| 1232 | |
| 1233 } | 1250 } |
| 1234 | 1251 |
| 1235 function hidePref(key, value) | 1252 function hidePref(key, value) |
| 1236 { | 1253 { |
| 1237 let element = document.querySelector("[data-pref='" + key + "']"); | 1254 let element = document.querySelector("[data-pref='" + key + "']"); |
| 1238 if (element) | 1255 if (element) |
| 1239 element.setAttribute("aria-hidden", value); | 1256 element.setAttribute("aria-hidden", value); |
| 1240 } | 1257 } |
| 1241 | 1258 |
| 1242 function getPref(key, callback) | 1259 function getPref(key, callback) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 type: "app.listen", | 1365 type: "app.listen", |
| 1349 filter: ["addSubscription", "focusSection"] | 1366 filter: ["addSubscription", "focusSection"] |
| 1350 }); | 1367 }); |
| 1351 ext.backgroundPage.sendMessage({ | 1368 ext.backgroundPage.sendMessage({ |
| 1352 type: "filters.listen", | 1369 type: "filters.listen", |
| 1353 filter: ["added", "loaded", "removed"] | 1370 filter: ["added", "loaded", "removed"] |
| 1354 }); | 1371 }); |
| 1355 ext.backgroundPage.sendMessage({ | 1372 ext.backgroundPage.sendMessage({ |
| 1356 type: "prefs.listen", | 1373 type: "prefs.listen", |
| 1357 filter: ["notifications_ignoredcategories", "notifications_showui", | 1374 filter: ["notifications_ignoredcategories", "notifications_showui", |
| 1358 "show_devtools_panel", "shouldShowBlockElementMenu"] | 1375 "show_devtools_panel", "shouldShowBlockElementMenu", |
| 1376 "ui_warn_tracking"] |
| 1359 }); | 1377 }); |
| 1360 ext.backgroundPage.sendMessage({ | 1378 ext.backgroundPage.sendMessage({ |
| 1361 type: "subscriptions.listen", | 1379 type: "subscriptions.listen", |
| 1362 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1380 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
| 1363 "title", "downloadStatus", "downloading"] | 1381 "title", "downloadStatus", "downloading"] |
| 1364 }); | 1382 }); |
| 1365 | 1383 |
| 1366 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1384 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 1367 window.addEventListener("hashchange", onHashChange, false); | 1385 window.addEventListener("hashchange", onHashChange, false); |
| 1368 } | 1386 } |
| LEFT | RIGHT |