| Left: | ||
| Right: |
| 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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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 = true; | |
|
Thomas Greiner
2017/09/15 16:15:24
This value needs to come from the preferences. Oth
saroyanm
2017/09/15 18:37:35
Well spotted, thanks. Done.
| |
| 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 303 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 type: "subscriptions.add", | 573 type: "subscriptions.add", |
| 574 url: findParentData(element, "access", false) | 574 url: findParentData(element, "access", false) |
| 575 }); | 575 }); |
| 576 break; | 576 break; |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 break; | 579 break; |
| 580 case "close-dialog": | 580 case "close-dialog": |
| 581 closeDialog(); | 581 closeDialog(); |
| 582 break; | 582 break; |
| 583 case "disallow-tracking": | |
| 584 execAction("switch-acceptable-ads", {value: "privacy"}); | |
| 585 break; | |
| 586 case "edit-custom-filters": | 583 case "edit-custom-filters": |
| 587 setCustomFiltersView("write"); | 584 setCustomFiltersView("write"); |
| 588 break; | 585 break; |
| 589 case "hide-notification": | 586 case "hide-notification": |
| 590 hideNotification(); | 587 hideNotification(); |
| 591 break; | 588 break; |
| 592 case "import-subscription": { | 589 case "import-subscription": { |
| 593 let url = E("blockingList-textbox").value; | 590 let url = E("blockingList-textbox").value; |
| 594 addEnableSubscription(url); | 591 addEnableSubscription(url); |
| 595 closeDialog(); | 592 closeDialog(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 623 type: "filters.importRaw", | 620 type: "filters.importRaw", |
| 624 text: E("custom-filters-raw").value, | 621 text: E("custom-filters-raw").value, |
| 625 removeExisting: true | 622 removeExisting: true |
| 626 }, | 623 }, |
| 627 () => | 624 () => |
| 628 { | 625 { |
| 629 setCustomFiltersView("read"); | 626 setCustomFiltersView("read"); |
| 630 }); | 627 }); |
| 631 break; | 628 break; |
| 632 case "switch-acceptable-ads": | 629 case "switch-acceptable-ads": |
| 633 let {value} = element; | 630 let value = element.value || element.dataset.value; |
| 634 ext.backgroundPage.sendMessage({ | 631 ext.backgroundPage.sendMessage({ |
| 635 type: value == "privacy" ? "subscriptions.add" : | 632 type: value == "privacy" ? "subscriptions.add" : |
| 636 "subscriptions.remove", | 633 "subscriptions.remove", |
| 637 url: acceptableAdsPrivacyUrl | 634 url: acceptableAdsPrivacyUrl |
| 638 }); | 635 }); |
| 639 ext.backgroundPage.sendMessage({ | 636 ext.backgroundPage.sendMessage({ |
| 640 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", | 637 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", |
| 641 url: acceptableAdsUrl | 638 url: acceptableAdsUrl |
| 642 }); | 639 }); |
| 643 break; | 640 break; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 673 ext.backgroundPage.sendMessage({ | 670 ext.backgroundPage.sendMessage({ |
| 674 type: "subscriptions.update" | 671 type: "subscriptions.update" |
| 675 }); | 672 }); |
| 676 break; | 673 break; |
| 677 case "update-subscription": | 674 case "update-subscription": |
| 678 ext.backgroundPage.sendMessage({ | 675 ext.backgroundPage.sendMessage({ |
| 679 type: "subscriptions.update", | 676 type: "subscriptions.update", |
| 680 url: findParentData(element, "access", false) | 677 url: findParentData(element, "access", false) |
| 681 }); | 678 }); |
| 682 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; | |
| 683 } | 697 } |
| 684 } | 698 } |
| 685 | 699 |
| 686 function setCustomFiltersView(mode) | 700 function setCustomFiltersView(mode) |
| 687 { | 701 { |
| 688 let customFiltersElement = E("custom-filters-raw"); | 702 let customFiltersElement = E("custom-filters-raw"); |
| 689 updateCustomFiltersUi(); | 703 updateCustomFiltersUi(); |
| 690 if (mode == "read") | 704 if (mode == "read") |
| 691 { | 705 { |
| 692 customFiltersElement.disabled = true; | 706 customFiltersElement.disabled = true; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 // Initialize interactive UI elements | 849 // Initialize interactive UI elements |
| 836 document.body.addEventListener("click", onClick, false); | 850 document.body.addEventListener("click", onClick, false); |
| 837 document.body.addEventListener("keyup", onKeyUp, false); | 851 document.body.addEventListener("keyup", onKeyUp, false); |
| 838 let exampleValue = getMessage("options_whitelist_placeholder_example", | 852 let exampleValue = getMessage("options_whitelist_placeholder_example", |
| 839 ["www.example.com"]); | 853 ["www.example.com"]); |
| 840 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); | 854 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); |
| 841 E("whitelisting-textbox").addEventListener("keyup", (e) => | 855 E("whitelisting-textbox").addEventListener("keyup", (e) => |
| 842 { | 856 { |
| 843 E("whitelisting-add-button").disabled = !e.target.value; | 857 E("whitelisting-add-button").disabled = !e.target.value; |
| 844 }, false); | 858 }, false); |
| 845 | |
| 846 | 859 |
| 847 getDocLink("contribute", (link) => | 860 getDocLink("contribute", (link) => |
| 848 { | 861 { |
| 849 E("contribute").href = link; | 862 E("contribute").href = link; |
| 850 }); | 863 }); |
| 851 getDocLink("acceptable_ads_criteria", (link) => | 864 getDocLink("acceptable_ads_criteria", (link) => |
| 852 { | 865 { |
| 853 setLinks("enable-aa-description", link); | 866 setLinks("enable-aa-description", link); |
| 854 }); | 867 }); |
| 855 | 868 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1019 for (let url in subscriptionsMap) | 1032 for (let url in subscriptionsMap) |
| 1020 { | 1033 { |
| 1021 let subscription = subscriptionsMap[url]; | 1034 let subscription = subscriptionsMap[url]; |
| 1022 if (subscription.recommended == "privacy") | 1035 if (subscription.recommended == "privacy") |
| 1023 { | 1036 { |
| 1024 privacyList = subscription; | 1037 privacyList = subscription; |
| 1025 break; | 1038 break; |
| 1026 } | 1039 } |
| 1027 } | 1040 } |
| 1028 return acceptableAdsList && acceptableAdsList.disabled == false && | 1041 return acceptableAdsList && acceptableAdsList.disabled == false && |
| 1029 privacyList && privacyList.disabled == false && showTrackingWarning; | 1042 privacyList && privacyList.disabled == false; |
|
Thomas Greiner
2017/09/15 16:15:24
Based on its name, the purpose of this function is
saroyanm
2017/09/15 18:37:35
Agree, Done.
| |
| 1030 } | 1043 } |
| 1031 | 1044 |
| 1032 function populateLists() | 1045 function populateLists() |
| 1033 { | 1046 { |
| 1034 subscriptionsMap = Object.create(null); | 1047 subscriptionsMap = Object.create(null); |
| 1035 filtersMap = Object.create(null); | 1048 filtersMap = Object.create(null); |
| 1036 | 1049 |
| 1037 // Empty collections and lists | 1050 // Empty collections and lists |
| 1038 for (let property in collections) | 1051 for (let property in collections) |
| 1039 collections[property].clearAll(); | 1052 collections[property].clearAll(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1185 updateSubscription(subscription); | 1198 updateSubscription(subscription); |
| 1186 break; | 1199 break; |
| 1187 case "downloading": | 1200 case "downloading": |
| 1188 case "downloadStatus": | 1201 case "downloadStatus": |
| 1189 case "homepage": | 1202 case "homepage": |
| 1190 case "lastDownload": | 1203 case "lastDownload": |
| 1191 case "title": | 1204 case "title": |
| 1192 updateSubscription(subscription); | 1205 updateSubscription(subscription); |
| 1193 break; | 1206 break; |
| 1194 case "added": | 1207 case "added": |
| 1195 let url = subscription.url; | 1208 let {url, recommended} = subscription; |
| 1196 if (url in subscriptionsMap) | 1209 if (url in subscriptionsMap) |
| 1197 updateSubscription(subscription); | 1210 updateSubscription(subscription); |
| 1198 else | 1211 else |
| 1199 addSubscription(subscription); | 1212 addSubscription(subscription); |
| 1200 | 1213 |
| 1201 if (isAcceptableAds(url)) | 1214 if (isAcceptableAds(url)) |
| 1202 setAcceptableAds(); | 1215 setAcceptableAds(); |
| 1203 | 1216 |
| 1204 if (url == acceptableAdsUrl || subscription.recommended == "privacy") | 1217 if ((url == acceptableAdsUrl || recommended == "privacy") && |
| 1205 { | 1218 hasPrivacyConflict()) |
| 1206 if (hasPrivacyConflict()) | 1219 { |
| 1207 openDialog("tracking"); | 1220 getPref("ui_warn_tracking", (showTrackingWarning) => |
| 1221 { | |
| 1222 if (showTrackingWarning) | |
| 1223 openDialog("tracking"); | |
| 1224 }); | |
| 1208 } | 1225 } |
| 1209 | 1226 |
| 1210 collections.filterLists.addItem(subscription); | 1227 collections.filterLists.addItem(subscription); |
| 1211 break; | 1228 break; |
| 1212 case "removed": | 1229 case "removed": |
| 1213 if (subscription.recommended) | 1230 if (subscription.recommended) |
| 1214 { | 1231 { |
| 1215 subscription.disabled = true; | 1232 subscription.disabled = true; |
| 1216 onSubscriptionMessage("disabled", subscription); | 1233 onSubscriptionMessage("disabled", subscription); |
| 1217 } | 1234 } |
| 1218 else | 1235 else |
| 1219 { | 1236 { |
| 1220 delete subscriptionsMap[subscription.url]; | 1237 delete subscriptionsMap[subscription.url]; |
| 1221 if (isAcceptableAds(subscription.url)) | 1238 if (isAcceptableAds(subscription.url)) |
| 1222 { | 1239 { |
| 1223 setAcceptableAds(); | 1240 setAcceptableAds(); |
| 1224 } | 1241 } |
| 1225 else | 1242 else |
| 1226 { | 1243 { |
| 1227 collections.custom.removeItem(subscription); | 1244 collections.more.removeItem(subscription); |
| 1228 } | 1245 } |
| 1229 } | 1246 } |
| 1230 collections.filterLists.removeItem(subscription); | 1247 collections.filterLists.removeItem(subscription); |
| 1231 break; | 1248 break; |
| 1232 } | 1249 } |
| 1233 | |
| 1234 } | 1250 } |
| 1235 | 1251 |
| 1236 function hidePref(key, value) | 1252 function hidePref(key, value) |
| 1237 { | 1253 { |
| 1238 let element = document.querySelector("[data-pref='" + key + "']"); | 1254 let element = document.querySelector("[data-pref='" + key + "']"); |
| 1239 if (element) | 1255 if (element) |
| 1240 element.setAttribute("aria-hidden", value); | 1256 element.setAttribute("aria-hidden", value); |
| 1241 } | 1257 } |
| 1242 | 1258 |
| 1243 function getPref(key, callback) | 1259 function getPref(key, callback) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1274 function onPrefMessage(key, value, initial) | 1290 function onPrefMessage(key, value, initial) |
| 1275 { | 1291 { |
| 1276 switch (key) | 1292 switch (key) |
| 1277 { | 1293 { |
| 1278 case "notifications_ignoredcategories": | 1294 case "notifications_ignoredcategories": |
| 1279 value = value.indexOf("*") == -1; | 1295 value = value.indexOf("*") == -1; |
| 1280 break; | 1296 break; |
| 1281 | 1297 |
| 1282 case "notifications_showui": | 1298 case "notifications_showui": |
| 1283 hidePref("notifications_ignoredcategories", !value); | 1299 hidePref("notifications_ignoredcategories", !value); |
| 1284 break; | |
| 1285 | |
| 1286 case "ui_warn_tracking": | |
| 1287 showTrackingWarning = value; | |
| 1288 break; | 1300 break; |
| 1289 } | 1301 } |
| 1290 | 1302 |
| 1291 let checkbox = document.querySelector( | 1303 let checkbox = document.querySelector( |
| 1292 "[data-pref='" + key + "'] button[role='checkbox']" | 1304 "[data-pref='" + key + "'] button[role='checkbox']" |
| 1293 ); | 1305 ); |
| 1294 if (checkbox) | 1306 if (checkbox) |
| 1295 checkbox.setAttribute("aria-checked", value); | 1307 checkbox.setAttribute("aria-checked", value); |
| 1296 } | 1308 } |
| 1297 | 1309 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1365 }); | 1377 }); |
| 1366 ext.backgroundPage.sendMessage({ | 1378 ext.backgroundPage.sendMessage({ |
| 1367 type: "subscriptions.listen", | 1379 type: "subscriptions.listen", |
| 1368 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1380 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
| 1369 "title", "downloadStatus", "downloading"] | 1381 "title", "downloadStatus", "downloading"] |
| 1370 }); | 1382 }); |
| 1371 | 1383 |
| 1372 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1384 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 1373 window.addEventListener("hashchange", onHashChange, false); | 1385 window.addEventListener("hashchange", onHashChange, false); |
| 1374 } | 1386 } |
| LEFT | RIGHT |