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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 | 77 |
78 Collection.prototype._getItemTitle = function(item, i) | 78 Collection.prototype._getItemTitle = function(item, i) |
79 { | 79 { |
80 if (item.url == acceptableAdsUrl) | 80 if (item.url == acceptableAdsUrl) |
81 return getMessage("options_acceptableAds_description"); | 81 return getMessage("options_acceptableAds_description"); |
82 if (this.details[i].useOriginalTitle && item.originalTitle) | 82 if (this.details[i].useOriginalTitle && item.originalTitle) |
83 return item.originalTitle; | 83 return item.originalTitle; |
84 return item.title || item.url || item.text; | 84 return item.title || item.url || item.text; |
85 }; | 85 }; |
86 | 86 |
87 Collection.prototype.addItem = function(item) | 87 Collection.prototype._sortItems = function() |
88 { | 88 { |
89 if (this.items.indexOf(item) >= 0) | |
90 return; | |
91 | |
92 this.items.push(item); | |
93 this.items.sort((a, b) => | 89 this.items.sort((a, b) => |
94 { | 90 { |
95 // Make sure that Acceptable Ads is always last, since it cannot be | 91 // Make sure that Acceptable Ads is always last, since it cannot be |
96 // disabled, but only be removed. That way it's grouped together with | 92 // disabled, but only be removed. That way it's grouped together with |
97 // the "Own filter list" which cannot be disabled either at the bottom | 93 // the "Own filter list" which cannot be disabled either at the bottom |
98 // of the filter lists in the Advanced tab. | 94 // of the filter lists in the Advanced tab. |
99 if (a.url == acceptableAdsUrl) | 95 if (a.url == acceptableAdsUrl) |
100 return 1; | 96 return 1; |
101 if (b.url == acceptableAdsUrl) | 97 if (b.url == acceptableAdsUrl) |
102 return -1; | 98 return -1; |
103 if (a[timestampUI]) | 99 |
104 return b[timestampUI] ? b[timestampUI] - a[timestampUI] : -1; | 100 // Make sure that newly added entries always appear on top in descending |
105 if (b[timestampUI]) | 101 // chronological order |
106 return a[timestampUI] ? a[timestampUI] - b[timestampUI] : 1; | 102 let aTimestamp = a[timestampUI] || 0; |
Thomas Greiner
2017/05/26 11:10:39
This condition is duplicated and contradictory bec
Thomas Greiner
2017/05/26 11:10:40
Detail: Please add a comment as we did with the sp
saroyanm
2017/05/31 08:30:27
Done.
saroyanm
2017/05/31 08:30:28
Done.
| |
103 let bTimestamp = b[timestampUI] || 0; | |
104 if (aTimestamp || bTimestamp) | |
105 return bTimestamp - aTimestamp; | |
107 | 106 |
108 let aTitle = this._getItemTitle(a, 0).toLowerCase(); | 107 let aTitle = this._getItemTitle(a, 0).toLowerCase(); |
109 let bTitle = this._getItemTitle(b, 0).toLowerCase(); | 108 let bTitle = this._getItemTitle(b, 0).toLowerCase(); |
110 return aTitle.localeCompare(bTitle); | 109 return aTitle.localeCompare(bTitle); |
111 }); | 110 }); |
112 | 111 }; |
112 | |
113 Collection.prototype.addItem = function(item) | |
114 { | |
115 if (this.items.indexOf(item) >= 0) | |
116 return; | |
117 | |
118 this.items.push(item); | |
119 this._sortItems(); | |
113 for (let j = 0; j < this.details.length; j++) | 120 for (let j = 0; j < this.details.length; j++) |
114 { | 121 { |
115 let table = E(this.details[j].id); | 122 let table = E(this.details[j].id); |
116 let template = table.querySelector("template"); | 123 let template = table.querySelector("template"); |
117 let listItem = document.createElement("li"); | 124 let listItem = document.createElement("li"); |
118 listItem.appendChild(document.importNode(template.content, true)); | 125 listItem.appendChild(document.importNode(template.content, true)); |
119 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); | 126 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); |
120 listItem.setAttribute("data-access", item.url || item.text); | 127 listItem.setAttribute("data-access", item.url || item.text); |
121 listItem.setAttribute("role", "section"); | 128 listItem.setAttribute("role", "section"); |
122 | 129 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 } | 191 } |
185 | 192 |
186 element.parentElement.removeChild(element); | 193 element.parentElement.removeChild(element); |
187 if (this.items.length == 0) | 194 if (this.items.length == 0) |
188 this._setEmpty(table, detail.emptyText); | 195 this._setEmpty(table, detail.emptyText); |
189 } | 196 } |
190 }; | 197 }; |
191 | 198 |
192 Collection.prototype.updateItem = function(item) | 199 Collection.prototype.updateItem = function(item) |
193 { | 200 { |
201 let oldIndex = this.items.indexOf(item); | |
202 this._sortItems(); | |
194 let access = (item.url || item.text).replace(/'/g, "\\'"); | 203 let access = (item.url || item.text).replace(/'/g, "\\'"); |
195 for (let i = 0; i < this.details.length; i++) | 204 for (let i = 0; i < this.details.length; i++) |
196 { | 205 { |
197 let table = E(this.details[i].id); | 206 let table = E(this.details[i].id); |
198 let element = table.querySelector("[data-access='" + access + "']"); | 207 let element = table.querySelector("[data-access='" + access + "']"); |
199 if (!element) | 208 if (!element) |
200 continue; | 209 continue; |
201 | 210 |
202 let title = this._getItemTitle(item, i); | 211 let title = this._getItemTitle(item, i); |
203 element.querySelector(".display").textContent = title; | 212 element.querySelector(".display").textContent = title; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 { | 255 { |
247 if (item.homepage) | 256 if (item.homepage) |
248 websiteElement.setAttribute("href", item.homepage); | 257 websiteElement.setAttribute("href", item.homepage); |
249 else | 258 else |
250 websiteElement.setAttribute("aria-hidden", true); | 259 websiteElement.setAttribute("aria-hidden", true); |
251 } | 260 } |
252 | 261 |
253 let sourceElement = element.querySelector(".context-menu .source"); | 262 let sourceElement = element.querySelector(".context-menu .source"); |
254 if (sourceElement) | 263 if (sourceElement) |
255 sourceElement.setAttribute("href", item.url); | 264 sourceElement.setAttribute("href", item.url); |
265 | |
266 let newIndex = this.items.indexOf(item); | |
267 if (oldIndex != newIndex) | |
268 table.insertBefore(element, table.childNodes[newIndex]); | |
256 } | 269 } |
257 }; | 270 }; |
258 | 271 |
259 Collection.prototype.clearAll = function() | 272 Collection.prototype.clearAll = function() |
260 { | 273 { |
261 this.items = []; | 274 this.items = []; |
262 for (let detail of this.details) | 275 for (let detail of this.details) |
263 { | 276 { |
264 let table = E(detail.id); | 277 let table = E(detail.id); |
265 let element = table.firstChild; | 278 let element = table.firstChild; |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
745 | 758 |
746 updateShareLink(); | 759 updateShareLink(); |
747 updateTooltips(); | 760 updateTooltips(); |
748 | 761 |
749 // Initialize interactive UI elements | 762 // Initialize interactive UI elements |
750 document.body.addEventListener("click", onClick, false); | 763 document.body.addEventListener("click", onClick, false); |
751 document.body.addEventListener("keyup", onKeyUp, false); | 764 document.body.addEventListener("keyup", onKeyUp, false); |
752 let placeholderValue = getMessage("options_dialog_language_find"); | 765 let placeholderValue = getMessage("options_dialog_language_find"); |
753 E("find-language").setAttribute("placeholder", placeholderValue); | 766 E("find-language").setAttribute("placeholder", placeholderValue); |
754 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 767 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
755 let exampleValue = getMessages("options_whitelist_placeholder_example", | 768 let exampleValue = getMessage("options_whitelist_placeholder_example", |
756 ["www.example.com"]); | 769 ["www.example.com"]); |
757 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); | 770 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); |
758 E("whitelisting-textbox").addEventListener("keyup", (e) => | 771 E("whitelisting-textbox").addEventListener("keyup", (e) => |
759 { | 772 { |
760 let addWhitelistButton = E("whitelisting-add-button"); | 773 E("whitelisting-add-button").disabled = !e.target.value; |
761 addWhitelistButton.disabled = false; | |
762 if (getKey(e) == "Enter") | |
763 { | |
764 if (!addWhitelistButton.disabled) | |
765 addWhitelistedDomain(); | |
766 } | |
767 else | |
768 { | |
769 if (!e.target.value) | |
770 { | |
771 addWhitelistButton.disabled = true; | |
Thomas Greiner
2017/05/26 11:10:39
Detail: Now that we reduced it to a simple check,
saroyanm
2017/05/31 08:30:27
Done.
| |
772 } | |
773 } | |
774 }, false); | 774 }, false); |
775 | 775 |
776 // Advanced tab | 776 // Advanced tab |
777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); | 777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); |
778 tweaks = Array.prototype.map.call(tweaks, (checkbox) => | 778 tweaks = Array.prototype.map.call(tweaks, (checkbox) => |
779 { | 779 { |
780 return checkbox.getAttribute("data-pref"); | 780 return checkbox.getAttribute("data-pref"); |
781 }); | 781 }); |
782 for (let key of tweaks) | 782 for (let key of tweaks) |
783 { | 783 { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 }); | 976 }); |
977 } | 977 } |
978 | 978 |
979 function addWhitelistedDomain() | 979 function addWhitelistedDomain() |
980 { | 980 { |
981 let domain = E("whitelisting-textbox"); | 981 let domain = E("whitelisting-textbox"); |
982 for (let whitelistItem of collections.whitelist.items) | 982 for (let whitelistItem of collections.whitelist.items) |
983 { | 983 { |
984 if (whitelistItem.title == domain.value) | 984 if (whitelistItem.title == domain.value) |
985 { | 985 { |
986 collections.whitelist.removeItem(whitelistItem); | |
987 whitelistItem[timestampUI] = Date.now(); | 986 whitelistItem[timestampUI] = Date.now(); |
988 collections.whitelist.addItem(whitelistItem); | 987 collections.whitelist.updateItem(whitelistItem); |
Thomas Greiner
2017/05/26 11:10:40
Removing and then adding the item again is quite a
saroyanm
2017/05/30 12:30:43
I agree with you.
The problem is that we are curr
saroyanm
2017/05/31 08:30:27
Done.
| |
989 domain.value = ""; | 988 domain.value = ""; |
Thomas Greiner
2017/05/26 11:10:39
No need to continue the loop because we already fo
saroyanm
2017/05/31 08:30:27
Done.
| |
989 break; | |
990 } | 990 } |
991 } | 991 } |
992 if (domain.value) | 992 if (domain.value) |
993 { | 993 { |
994 sendMessageHandleErrors({ | 994 sendMessageHandleErrors({ |
995 type: "filters.add", | 995 type: "filters.add", |
996 text: "@@||" + domain.value.toLowerCase() + "^$document" | 996 text: "@@||" + domain.value.toLowerCase() + "^$document" |
997 }); | 997 }); |
998 } | 998 } |
999 | 999 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1035 message.homepage = homepage; | 1035 message.homepage = homepage; |
1036 | 1036 |
1037 ext.backgroundPage.sendMessage(message); | 1037 ext.backgroundPage.sendMessage(message); |
1038 } | 1038 } |
1039 | 1039 |
1040 function onFilterMessage(action, filter) | 1040 function onFilterMessage(action, filter) |
1041 { | 1041 { |
1042 switch (action) | 1042 switch (action) |
1043 { | 1043 { |
1044 case "added": | 1044 case "added": |
1045 filter[timestampUI] = Date.now(); | |
1045 updateFilter(filter); | 1046 updateFilter(filter); |
1046 updateShareLink(); | 1047 updateShareLink(); |
1047 break; | 1048 break; |
1048 case "loaded": | 1049 case "loaded": |
1049 populateLists(); | 1050 populateLists(); |
1050 break; | 1051 break; |
1051 case "removed": | 1052 case "removed": |
1052 let knownFilter = filtersMap[filter.text]; | 1053 let knownFilter = filtersMap[filter.text]; |
1053 collections.whitelist.removeItem(knownFilter); | 1054 collections.whitelist.removeItem(knownFilter); |
1054 collections.customFilters.removeItem(knownFilter); | 1055 collections.customFilters.removeItem(knownFilter); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1315 }); | 1316 }); |
1316 ext.backgroundPage.sendMessage({ | 1317 ext.backgroundPage.sendMessage({ |
1317 type: "subscriptions.listen", | 1318 type: "subscriptions.listen", |
1318 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1319 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1319 "title", "downloadStatus", "downloading"] | 1320 "title", "downloadStatus", "downloading"] |
1320 }); | 1321 }); |
1321 | 1322 |
1322 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1323 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1323 window.addEventListener("hashchange", onHashChange, false); | 1324 window.addEventListener("hashchange", onHashChange, false); |
1324 } | 1325 } |
LEFT | RIGHT |