OLD | NEW |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 "use strict"; | 18 "use strict"; |
19 | 19 |
20 (function() | 20 (function() |
21 { | 21 { |
22 var subscriptionsMap = Object.create(null); | 22 var subscriptionsMap = Object.create(null); |
23 var recommendationsMap = Object.create(null); | 23 var recommendationsMap = Object.create(null); |
24 var filtersMap = Object.create(null); | 24 var filtersMap = Object.create(null); |
25 var collections = Object.create(null); | 25 var collections = Object.create(null); |
| 26 var acceptableAdsUrl = null; |
26 var maxLabelId = 0; | 27 var maxLabelId = 0; |
27 var getMessage = ext.i18n.getMessage; | 28 var getMessage = ext.i18n.getMessage; |
28 var filterErrors = | 29 var filterErrors = |
29 { | 30 { |
30 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", | 31 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", |
31 "synchronize_connection_error": "options_filterList_lastDownload_connectionE
rror", | 32 "synchronize_connection_error": "options_filterList_lastDownload_connectionE
rror", |
32 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", | 33 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", |
33 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi
smatch" | 34 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi
smatch" |
34 }; | 35 }; |
35 | 36 |
(...skipping 19 matching lines...) Expand all Loading... |
55 | 56 |
56 Collection.prototype._createElementQuery = function(item) | 57 Collection.prototype._createElementQuery = function(item) |
57 { | 58 { |
58 var access = (item.url || item.text).replace(/'/g, "\\'"); | 59 var access = (item.url || item.text).replace(/'/g, "\\'"); |
59 return function(container) | 60 return function(container) |
60 { | 61 { |
61 return container.querySelector("[data-access='" + access + "']"); | 62 return container.querySelector("[data-access='" + access + "']"); |
62 }; | 63 }; |
63 }; | 64 }; |
64 | 65 |
| 66 Collection.prototype._getItemTitle = function(item, i) |
| 67 { |
| 68 var title = null; |
| 69 if (this.details[i].useOriginalTitle) |
| 70 title = item.originalTitle; |
| 71 if (!title) |
| 72 title = item.title || item.url || item.text; |
| 73 return title; |
| 74 }; |
| 75 |
65 Collection.prototype.addItems = function() | 76 Collection.prototype.addItems = function() |
66 { | 77 { |
67 var length = Array.prototype.push.apply(this.items, arguments); | 78 var length = Array.prototype.push.apply(this.items, arguments); |
68 if (length == 0) | 79 if (length == 0) |
69 return; | 80 return; |
70 | 81 |
71 this.items.sort(function(a, b) | 82 this.items.sort(function(a, b) |
72 { | 83 { |
73 var aValue = (a.title || a.text || a.url).toLowerCase(); | 84 // Make sure that Acceptable Ads is always last, since it cannot be |
74 var bValue = (b.title || b.text || b.url).toLowerCase(); | 85 // disabled, but only be removed. That way it's grouped together with |
75 return aValue.localeCompare(bValue); | 86 // the "Own filter list" which cannot be disabled either at the bottom |
76 }); | 87 // of the filter lists in the Advanced tab. |
| 88 if (a.url == acceptableAdsUrl) |
| 89 return 1; |
| 90 if (b.url == acceptableAdsUrl) |
| 91 return -1; |
| 92 |
| 93 var aTitle = this._getItemTitle(a, 0).toLowerCase(); |
| 94 var bTitle = this._getItemTitle(b, 0).toLowerCase(); |
| 95 return aTitle.localeCompare(bTitle); |
| 96 }.bind(this)); |
77 | 97 |
78 for (var j = 0; j < this.details.length; j++) | 98 for (var j = 0; j < this.details.length; j++) |
79 { | 99 { |
80 var table = E(this.details[j].id); | 100 var table = E(this.details[j].id); |
81 var template = table.querySelector("template"); | 101 var template = table.querySelector("template"); |
82 for (var i = 0; i < arguments.length; i++) | 102 for (var i = 0; i < arguments.length; i++) |
83 { | 103 { |
84 var item = arguments[i]; | 104 var item = arguments[i]; |
85 var listItem = document.createElement("li"); | 105 var listItem = document.createElement("li"); |
86 listItem.appendChild(document.importNode(template.content, true)); | 106 listItem.appendChild(document.importNode(template.content, true)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 Collection.prototype.updateItem = function(item) | 181 Collection.prototype.updateItem = function(item) |
162 { | 182 { |
163 var access = (item.url || item.text).replace(/'/g, "\\'"); | 183 var access = (item.url || item.text).replace(/'/g, "\\'"); |
164 for (var i = 0; i < this.details.length; i++) | 184 for (var i = 0; i < this.details.length; i++) |
165 { | 185 { |
166 var table = E(this.details[i].id); | 186 var table = E(this.details[i].id); |
167 var element = table.querySelector("[data-access='" + access + "']"); | 187 var element = table.querySelector("[data-access='" + access + "']"); |
168 if (!element) | 188 if (!element) |
169 continue; | 189 continue; |
170 | 190 |
171 var title = null; | 191 var title = this._getItemTitle(item, i); |
172 if (this.details[i].useOriginalTitle) | |
173 title = item.originalTitle; | |
174 if (!title) | |
175 title = item.title || item.url || item.text; | |
176 element.querySelector(".display").textContent = title; | 192 element.querySelector(".display").textContent = title; |
177 if (title) | 193 if (title) |
178 element.setAttribute("data-search", title.toLowerCase()); | 194 element.setAttribute("data-search", title.toLowerCase()); |
179 var control = element.querySelector(".control[role='checkbox']"); | 195 var control = element.querySelector(".control[role='checkbox']"); |
180 if (control) | 196 if (control) |
| 197 { |
181 control.setAttribute("aria-checked", item.disabled == false); | 198 control.setAttribute("aria-checked", item.disabled == false); |
| 199 if (item.url == acceptableAdsUrl && this.details[i].onClick == |
| 200 toggleDisableSubscription) |
| 201 control.setAttribute("disabled", true); |
| 202 } |
182 | 203 |
183 var dateElement = element.querySelector(".date"); | 204 var dateElement = element.querySelector(".date"); |
184 var timeElement = element.querySelector(".time"); | 205 var timeElement = element.querySelector(".time"); |
185 if (dateElement && timeElement) | 206 if (dateElement && timeElement) |
186 { | 207 { |
187 var message = element.querySelector(".message"); | 208 var message = element.querySelector(".message"); |
188 if (item.isDownloading) | 209 if (item.isDownloading) |
189 { | 210 { |
190 var text = getMessage("options_filterList_lastDownload_inProgress"); | 211 var text = getMessage("options_filterList_lastDownload_inProgress"); |
191 message.textContent = text; | 212 message.textContent = text; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 { | 448 { |
428 if (property == "title" && subscriptionUrl in recommendationsMap) | 449 if (property == "title" && subscriptionUrl in recommendationsMap) |
429 knownSubscription.originalTitle = subscription.title; | 450 knownSubscription.originalTitle = subscription.title; |
430 else | 451 else |
431 knownSubscription[property] = subscription[property]; | 452 knownSubscription[property] = subscription[property]; |
432 } | 453 } |
433 } | 454 } |
434 else | 455 else |
435 { | 456 { |
436 observeSubscription(subscription); | 457 observeSubscription(subscription); |
437 getAcceptableAdsURL(function(acceptableAdsUrl) | 458 |
| 459 var collection; |
| 460 if (subscriptionUrl in recommendationsMap) |
438 { | 461 { |
439 var collection = null; | 462 var recommendation = recommendationsMap[subscriptionUrl]; |
440 if (subscriptionUrl in recommendationsMap) | 463 if (recommendation.type != "ads") |
441 { | 464 collection = collections.popular; |
442 var recommendation = recommendationsMap[subscriptionUrl]; | 465 else if (subscription.disabled == false) |
443 if (recommendation.type != "ads") | 466 collection = collections.langs; |
444 collection = collections.popular; | |
445 else if (subscription.disabled == false) | |
446 collection = collections.langs; | |
447 else | |
448 collection = collections.allLangs; | |
449 } | |
450 else if (subscriptionUrl == acceptableAdsUrl) | |
451 collection = collections.acceptableAds; | |
452 else | 467 else |
453 collection = collections.custom; | 468 collection = collections.allLangs; |
| 469 } |
| 470 else if (subscriptionUrl == acceptableAdsUrl) |
| 471 collection = collections.acceptableAds; |
| 472 else |
| 473 collection = collections.custom; |
454 | 474 |
455 collection.addItems(subscription); | 475 collection.addItems(subscription); |
456 subscriptionsMap[subscriptionUrl] = subscription; | 476 subscriptionsMap[subscriptionUrl] = subscription; |
457 }); | |
458 } | 477 } |
459 } | 478 } |
460 | 479 |
461 function updateFilter(filter) | 480 function updateFilter(filter) |
462 { | 481 { |
463 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); | 482 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); |
464 if (match && !filtersMap[filter.text]) | 483 if (match && !filtersMap[filter.text]) |
465 { | 484 { |
466 filter.title = match[1]; | 485 filter.title = match[1]; |
467 collections.whitelist.addItems(filter); | 486 collections.whitelist.addItems(filter); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 subscriptionUrl: subscriptions[i].url | 855 subscriptionUrl: subscriptions[i].url |
837 }, | 856 }, |
838 function(filters) | 857 function(filters) |
839 { | 858 { |
840 for (var i = 0; i < filters.length; i++) | 859 for (var i = 0; i < filters.length; i++) |
841 updateFilter(filters[i]); | 860 updateFilter(filters[i]); |
842 }); | 861 }); |
843 } | 862 } |
844 }); | 863 }); |
845 loadRecommendations(); | 864 loadRecommendations(); |
846 getAcceptableAdsURL(function(acceptableAdsUrl) | 865 ext.backgroundPage.sendMessage( |
847 { | 866 { |
848 var subscription = Object.create(null); | 867 type: "prefs.get", |
849 subscription.url = acceptableAdsUrl; | 868 key: "subscriptions_exceptionsurl" |
850 subscription.disabled = true; | 869 }, |
851 subscription.title = getMessage("options_acceptableAds_description"); | 870 function(url) |
852 updateSubscription(subscription); | 871 { |
| 872 acceptableAdsUrl = url; |
| 873 updateSubscription({ |
| 874 url: acceptableAdsUrl, |
| 875 disabled: true, |
| 876 title: getMessage("options_acceptableAds_description") |
| 877 }); |
853 | 878 |
854 // Load user subscriptions | 879 // Load user subscriptions |
855 ext.backgroundPage.sendMessage( | 880 ext.backgroundPage.sendMessage( |
856 { | 881 { |
857 type: "subscriptions.get", | 882 type: "subscriptions.get", |
858 downloadable: true | 883 downloadable: true |
859 }, | 884 }, |
860 function(subscriptions) | 885 function(subscriptions) |
861 { | 886 { |
862 for (var i = 0; i < subscriptions.length; i++) | 887 for (var i = 0; i < subscriptions.length; i++) |
(...skipping 20 matching lines...) Expand all Loading... |
883 | 908 |
884 function editCustomFilters() | 909 function editCustomFilters() |
885 { | 910 { |
886 var customFilterItems = collections.customFilters.items; | 911 var customFilterItems = collections.customFilters.items; |
887 var filterTexts = []; | 912 var filterTexts = []; |
888 for (var i = 0; i < customFilterItems.length; i++) | 913 for (var i = 0; i < customFilterItems.length; i++) |
889 filterTexts.push(customFilterItems[i].text); | 914 filterTexts.push(customFilterItems[i].text); |
890 E("custom-filters-raw").value = filterTexts.join("\n"); | 915 E("custom-filters-raw").value = filterTexts.join("\n"); |
891 } | 916 } |
892 | 917 |
893 function getAcceptableAdsURL(callback) | |
894 { | |
895 getPref("subscriptions_exceptionsurl", function(value) | |
896 { | |
897 getAcceptableAdsURL = function(callback) | |
898 { | |
899 callback(value); | |
900 }; | |
901 getAcceptableAdsURL(callback); | |
902 }); | |
903 } | |
904 | |
905 function addEnableSubscription(url, title, homepage) | 918 function addEnableSubscription(url, title, homepage) |
906 { | 919 { |
907 var messageType = null; | 920 var messageType = null; |
908 var knownSubscription = subscriptionsMap[url]; | 921 var knownSubscription = subscriptionsMap[url]; |
909 if (knownSubscription && knownSubscription.disabled == true) | 922 if (knownSubscription && knownSubscription.disabled == true) |
910 messageType = "subscriptions.toggle" | 923 messageType = "subscriptions.toggle" |
911 else | 924 else |
912 messageType = "subscriptions.add" | 925 messageType = "subscriptions.add" |
913 | 926 |
914 var message = { | 927 var message = { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 collections.filterLists.addItems(knownSubscription); | 970 collections.filterLists.addItems(knownSubscription); |
958 else | 971 else |
959 collections.filterLists.addItems(subscription); | 972 collections.filterLists.addItems(subscription); |
960 break; | 973 break; |
961 case "disabled": | 974 case "disabled": |
962 updateSubscription(subscription); | 975 updateSubscription(subscription); |
963 updateShareLink(); | 976 updateShareLink(); |
964 break; | 977 break; |
965 case "removed": | 978 case "removed": |
966 var knownSubscription = subscriptionsMap[subscription.url]; | 979 var knownSubscription = subscriptionsMap[subscription.url]; |
967 getAcceptableAdsURL(function(acceptableAdsUrl) | 980 if (subscription.url == acceptableAdsUrl) |
968 { | 981 { |
969 if (subscription.url == acceptableAdsUrl) | 982 subscription.disabled = true; |
970 { | 983 updateSubscription(subscription); |
971 subscription.disabled = true; | 984 } |
972 updateSubscription(subscription); | 985 else |
973 } | 986 { |
| 987 if (subscription.url in recommendationsMap) |
| 988 knownSubscription.disabled = true; |
974 else | 989 else |
975 { | 990 { |
976 if (subscription.url in recommendationsMap) | 991 collections.custom.removeItem(knownSubscription); |
977 knownSubscription.disabled = true; | 992 delete subscriptionsMap[subscription.url]; |
978 else | |
979 { | |
980 collections.custom.removeItem(knownSubscription); | |
981 delete subscriptionsMap[subscription.url]; | |
982 } | |
983 } | 993 } |
984 updateShareLink(); | 994 } |
985 collections.filterLists.removeItem(knownSubscription); | 995 updateShareLink(); |
986 }); | 996 collections.filterLists.removeItem(knownSubscription); |
987 break; | 997 break; |
988 default: | 998 default: |
989 updateSubscription(subscription); | 999 updateSubscription(subscription); |
990 break; | 1000 break; |
991 } | 1001 } |
992 } | 1002 } |
993 | 1003 |
994 function hidePref(key, value) | 1004 function hidePref(key, value) |
995 { | 1005 { |
996 var element = document.querySelector("[data-pref='" + key + "']"); | 1006 var element = document.querySelector("[data-pref='" + key + "']"); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 }); | 1153 }); |
1144 ext.backgroundPage.sendMessage( | 1154 ext.backgroundPage.sendMessage( |
1145 { | 1155 { |
1146 type: "subscriptions.listen", | 1156 type: "subscriptions.listen", |
1147 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1157 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1148 "title", "downloadStatus", "downloading"] | 1158 "title", "downloadStatus", "downloading"] |
1149 }); | 1159 }); |
1150 | 1160 |
1151 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1161 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1152 })(); | 1162 })(); |
OLD | NEW |