Left: | ||
Right: |
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._isControlDisabled = function(item, i) | |
67 { | |
68 return item.url == acceptableAdsUrl && | |
69 this.details[i].onClick == toggleDisableSubscription; | |
70 }; | |
71 | |
72 Collection.prototype._getItemTitle = function(item, i) | |
73 { | |
74 var title = null; | |
75 if (this.details[i].useOriginalTitle) | |
76 title = item.originalTitle; | |
77 if (!title) | |
78 title = item.title || item.url || item.text; | |
79 return title; | |
80 }; | |
81 | |
65 Collection.prototype.addItems = function() | 82 Collection.prototype.addItems = function() |
66 { | 83 { |
67 var length = Array.prototype.push.apply(this.items, arguments); | 84 var length = Array.prototype.push.apply(this.items, arguments); |
68 if (length == 0) | 85 if (length == 0) |
69 return; | 86 return; |
70 | 87 |
71 this.items.sort(function(a, b) | 88 this.items.sort(function(a, b) |
72 { | 89 { |
73 var aValue = (a.title || a.text || a.url).toLowerCase(); | 90 var aDisabled = this._isControlDisabled(a, 0); |
74 var bValue = (b.title || b.text || b.url).toLowerCase(); | 91 var bDisabled = this._isControlDisabled(b, 0); |
Thomas Greiner
2016/04/07 17:21:15
It's a nice idea to group together all disabled ch
Sebastian Noack
2016/04/08 14:22:17
Yeah, hard-coding the index isn't great, but we ha
| |
75 return aValue.localeCompare(bValue); | 92 if (aDisabled != bDisabled) |
76 }); | 93 return aDisabled - bDisabled; |
94 | |
95 var aTitle = this._getItemTitle(a, 0).toLowerCase(); | |
Thomas Greiner
2016/04/07 17:21:15
Detail: Hardcoding the table index here might caus
Sebastian Noack
2016/04/08 14:22:17
I know. This is kinda a hack. But at least more co
| |
96 var bTitle = this._getItemTitle(b, 0).toLowerCase(); | |
97 return aTitle.localeCompare(bTitle); | |
98 }.bind(this)); | |
77 | 99 |
78 for (var j = 0; j < this.details.length; j++) | 100 for (var j = 0; j < this.details.length; j++) |
79 { | 101 { |
80 var table = E(this.details[j].id); | 102 var table = E(this.details[j].id); |
81 var template = table.querySelector("template"); | 103 var template = table.querySelector("template"); |
82 for (var i = 0; i < arguments.length; i++) | 104 for (var i = 0; i < arguments.length; i++) |
83 { | 105 { |
84 var item = arguments[i]; | 106 var item = arguments[i]; |
85 var listItem = document.createElement("li"); | 107 var listItem = document.createElement("li"); |
86 listItem.appendChild(document.importNode(template.content, true)); | 108 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) | 183 Collection.prototype.updateItem = function(item) |
162 { | 184 { |
163 var access = (item.url || item.text).replace(/'/g, "\\'"); | 185 var access = (item.url || item.text).replace(/'/g, "\\'"); |
164 for (var i = 0; i < this.details.length; i++) | 186 for (var i = 0; i < this.details.length; i++) |
165 { | 187 { |
166 var table = E(this.details[i].id); | 188 var table = E(this.details[i].id); |
167 var element = table.querySelector("[data-access='" + access + "']"); | 189 var element = table.querySelector("[data-access='" + access + "']"); |
168 if (!element) | 190 if (!element) |
169 continue; | 191 continue; |
170 | 192 |
171 var title = null; | 193 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; | 194 element.querySelector(".display").textContent = title; |
177 if (title) | 195 if (title) |
178 element.setAttribute("data-search", title.toLowerCase()); | 196 element.setAttribute("data-search", title.toLowerCase()); |
179 var control = element.querySelector(".control[role='checkbox']"); | 197 var control = element.querySelector(".control[role='checkbox']"); |
180 if (control) | 198 if (control) |
199 { | |
181 control.setAttribute("aria-checked", item.disabled == false); | 200 control.setAttribute("aria-checked", item.disabled == false); |
201 if (this._isControlDisabled(item, i)) | |
202 control.setAttribute("disabled", true); | |
203 } | |
182 | 204 |
183 var dateElement = element.querySelector(".date"); | 205 var dateElement = element.querySelector(".date"); |
184 var timeElement = element.querySelector(".time"); | 206 var timeElement = element.querySelector(".time"); |
185 if (dateElement && timeElement) | 207 if (dateElement && timeElement) |
186 { | 208 { |
187 var message = element.querySelector(".message"); | 209 var message = element.querySelector(".message"); |
188 if (item.isDownloading) | 210 if (item.isDownloading) |
189 { | 211 { |
190 var text = getMessage("options_filterList_lastDownload_inProgress"); | 212 var text = getMessage("options_filterList_lastDownload_inProgress"); |
191 message.textContent = text; | 213 message.textContent = text; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 { | 449 { |
428 if (property == "title" && subscriptionUrl in recommendationsMap) | 450 if (property == "title" && subscriptionUrl in recommendationsMap) |
429 knownSubscription.originalTitle = subscription.title; | 451 knownSubscription.originalTitle = subscription.title; |
430 else | 452 else |
431 knownSubscription[property] = subscription[property]; | 453 knownSubscription[property] = subscription[property]; |
432 } | 454 } |
433 } | 455 } |
434 else | 456 else |
435 { | 457 { |
436 observeSubscription(subscription); | 458 observeSubscription(subscription); |
437 getAcceptableAdsURL(function(acceptableAdsUrl) | 459 |
460 var collection; | |
461 if (subscriptionUrl in recommendationsMap) | |
438 { | 462 { |
439 var collection = null; | 463 var recommendation = recommendationsMap[subscriptionUrl]; |
440 if (subscriptionUrl in recommendationsMap) | 464 if (recommendation.type != "ads") |
441 { | 465 collection = collections.popular; |
442 var recommendation = recommendationsMap[subscriptionUrl]; | 466 else if (subscription.disabled == false) |
443 if (recommendation.type != "ads") | 467 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 | 468 else |
453 collection = collections.custom; | 469 collection = collections.allLangs; |
470 } | |
471 else if (subscriptionUrl == acceptableAdsUrl) | |
472 collection = collections.acceptableAds; | |
473 else | |
474 collection = collections.custom; | |
454 | 475 |
455 collection.addItems(subscription); | 476 collection.addItems(subscription); |
456 subscriptionsMap[subscriptionUrl] = subscription; | 477 subscriptionsMap[subscriptionUrl] = subscription; |
457 }); | |
458 } | 478 } |
459 } | 479 } |
460 | 480 |
461 function updateFilter(filter) | 481 function updateFilter(filter) |
462 { | 482 { |
463 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); | 483 var match = filter.text.match(/^@@\|\|([^\/:]+)\^\$document$/); |
464 if (match && !filtersMap[filter.text]) | 484 if (match && !filtersMap[filter.text]) |
465 { | 485 { |
466 filter.title = match[1]; | 486 filter.title = match[1]; |
467 collections.whitelist.addItems(filter); | 487 collections.whitelist.addItems(filter); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 subscriptionUrl: subscriptions[i].url | 856 subscriptionUrl: subscriptions[i].url |
837 }, | 857 }, |
838 function(filters) | 858 function(filters) |
839 { | 859 { |
840 for (var i = 0; i < filters.length; i++) | 860 for (var i = 0; i < filters.length; i++) |
841 updateFilter(filters[i]); | 861 updateFilter(filters[i]); |
842 }); | 862 }); |
843 } | 863 } |
844 }); | 864 }); |
845 loadRecommendations(); | 865 loadRecommendations(); |
846 getAcceptableAdsURL(function(acceptableAdsUrl) | 866 ext.backgroundPage.sendMessage( |
847 { | 867 { |
848 var subscription = Object.create(null); | 868 type: "prefs.get", |
849 subscription.url = acceptableAdsUrl; | 869 key: "subscriptions_exceptionsurl" |
850 subscription.disabled = true; | 870 }, |
851 subscription.title = getMessage("options_acceptableAds_description"); | 871 function(url) |
852 updateSubscription(subscription); | 872 { |
873 acceptableAdsUrl = url; | |
874 updateSubscription({ | |
875 url: acceptableAdsUrl, | |
876 disabled: true, | |
877 title: getMessage("options_acceptableAds_description") | |
878 }); | |
853 | 879 |
854 // Load user subscriptions | 880 // Load user subscriptions |
855 ext.backgroundPage.sendMessage( | 881 ext.backgroundPage.sendMessage( |
856 { | 882 { |
857 type: "subscriptions.get", | 883 type: "subscriptions.get", |
858 downloadable: true | 884 downloadable: true |
859 }, | 885 }, |
860 function(subscriptions) | 886 function(subscriptions) |
861 { | 887 { |
862 for (var i = 0; i < subscriptions.length; i++) | 888 for (var i = 0; i < subscriptions.length; i++) |
(...skipping 20 matching lines...) Expand all Loading... | |
883 | 909 |
884 function editCustomFilters() | 910 function editCustomFilters() |
885 { | 911 { |
886 var customFilterItems = collections.customFilters.items; | 912 var customFilterItems = collections.customFilters.items; |
887 var filterTexts = []; | 913 var filterTexts = []; |
888 for (var i = 0; i < customFilterItems.length; i++) | 914 for (var i = 0; i < customFilterItems.length; i++) |
889 filterTexts.push(customFilterItems[i].text); | 915 filterTexts.push(customFilterItems[i].text); |
890 E("custom-filters-raw").value = filterTexts.join("\n"); | 916 E("custom-filters-raw").value = filterTexts.join("\n"); |
891 } | 917 } |
892 | 918 |
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) | 919 function addEnableSubscription(url, title, homepage) |
906 { | 920 { |
907 var messageType = null; | 921 var messageType = null; |
908 var knownSubscription = subscriptionsMap[url]; | 922 var knownSubscription = subscriptionsMap[url]; |
909 if (knownSubscription && knownSubscription.disabled == true) | 923 if (knownSubscription && knownSubscription.disabled == true) |
910 messageType = "subscriptions.toggle" | 924 messageType = "subscriptions.toggle" |
911 else | 925 else |
912 messageType = "subscriptions.add" | 926 messageType = "subscriptions.add" |
913 | 927 |
914 var message = { | 928 var message = { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 collections.filterLists.addItems(knownSubscription); | 971 collections.filterLists.addItems(knownSubscription); |
958 else | 972 else |
959 collections.filterLists.addItems(subscription); | 973 collections.filterLists.addItems(subscription); |
960 break; | 974 break; |
961 case "disabled": | 975 case "disabled": |
962 updateSubscription(subscription); | 976 updateSubscription(subscription); |
963 updateShareLink(); | 977 updateShareLink(); |
964 break; | 978 break; |
965 case "removed": | 979 case "removed": |
966 var knownSubscription = subscriptionsMap[subscription.url]; | 980 var knownSubscription = subscriptionsMap[subscription.url]; |
967 getAcceptableAdsURL(function(acceptableAdsUrl) | 981 if (subscription.url == acceptableAdsUrl) |
968 { | 982 { |
969 if (subscription.url == acceptableAdsUrl) | 983 subscription.disabled = true; |
970 { | 984 updateSubscription(subscription); |
971 subscription.disabled = true; | 985 } |
972 updateSubscription(subscription); | 986 else |
973 } | 987 { |
988 if (subscription.url in recommendationsMap) | |
989 knownSubscription.disabled = true; | |
974 else | 990 else |
975 { | 991 { |
976 if (subscription.url in recommendationsMap) | 992 collections.custom.removeItem(knownSubscription); |
977 knownSubscription.disabled = true; | 993 delete subscriptionsMap[subscription.url]; |
978 else | |
979 { | |
980 collections.custom.removeItem(knownSubscription); | |
981 delete subscriptionsMap[subscription.url]; | |
982 } | |
983 } | 994 } |
984 updateShareLink(); | 995 } |
985 collections.filterLists.removeItem(knownSubscription); | 996 updateShareLink(); |
986 }); | 997 collections.filterLists.removeItem(knownSubscription); |
987 break; | 998 break; |
988 default: | 999 default: |
989 updateSubscription(subscription); | 1000 updateSubscription(subscription); |
990 break; | 1001 break; |
991 } | 1002 } |
992 } | 1003 } |
993 | 1004 |
994 function hidePref(key, value) | 1005 function hidePref(key, value) |
995 { | 1006 { |
996 var element = document.querySelector("[data-pref='" + key + "']"); | 1007 var element = document.querySelector("[data-pref='" + key + "']"); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1143 }); | 1154 }); |
1144 ext.backgroundPage.sendMessage( | 1155 ext.backgroundPage.sendMessage( |
1145 { | 1156 { |
1146 type: "subscriptions.listen", | 1157 type: "subscriptions.listen", |
1147 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1158 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1148 "title", "downloadStatus", "downloading"] | 1159 "title", "downloadStatus", "downloading"] |
1149 }); | 1160 }); |
1150 | 1161 |
1151 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1162 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1152 })(); | 1163 })(); |
OLD | NEW |