| 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-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 25 matching lines...) Expand all Loading... | |
| 36 ["synchronize_checksum_mismatch", | 36 ["synchronize_checksum_mismatch", |
| 37 "options_filterList_lastDownload_checksumMismatch"] | 37 "options_filterList_lastDownload_checksumMismatch"] |
| 38 ]); | 38 ]); |
| 39 | 39 |
| 40 function Collection(details) | 40 function Collection(details) |
| 41 { | 41 { |
| 42 this.details = details; | 42 this.details = details; |
| 43 this.items = []; | 43 this.items = []; |
| 44 } | 44 } |
| 45 | 45 |
| 46 Collection.prototype._setEmpty = function(table, text) | 46 Collection.prototype._setEmpty = function(table, texts) |
| 47 { | 47 { |
| 48 let placeholder = table.querySelector(".empty-placeholder"); | 48 let placeholders = table.querySelectorAll(".empty-placeholder"); |
| 49 if (text && !placeholder) | 49 |
| 50 if (texts && placeholders.length == 0) | |
| 50 { | 51 { |
| 51 placeholder = document.createElement("li"); | 52 for (let i = 0; i < texts.length; i++) |
|
Thomas Greiner
2017/05/09 13:42:56
Detail: You're not using the index so I'd recommen
saroyanm
2017/05/16 20:20:07
Well spotted, done.
| |
| 52 placeholder.className = "empty-placeholder"; | 53 { |
| 53 placeholder.textContent = getMessage(text); | 54 let placeholder = document.createElement("li"); |
| 54 table.appendChild(placeholder); | 55 placeholder.className = "empty-placeholder"; |
| 56 placeholder.textContent = getMessage(texts[i]); | |
| 57 table.appendChild(placeholder); | |
| 58 } | |
| 55 } | 59 } |
| 56 else if (placeholder) | 60 else if (placeholders.length > 0) |
| 57 table.removeChild(placeholder); | 61 { |
| 62 for (let i = 0; i < placeholders.length; i++) | |
| 63 table.removeChild(placeholders[i]); | |
| 64 } | |
| 58 }; | 65 }; |
| 59 | 66 |
| 60 Collection.prototype._createElementQuery = function(item) | 67 Collection.prototype._createElementQuery = function(item) |
| 61 { | 68 { |
| 62 let access = (item.url || item.text).replace(/'/g, "\\'"); | 69 let access = (item.url || item.text).replace(/'/g, "\\'"); |
| 63 return function(container) | 70 return function(container) |
| 64 { | 71 { |
| 65 return container.querySelector("[data-access='" + access + "']"); | 72 return container.querySelector("[data-access='" + access + "']"); |
| 66 }; | 73 }; |
| 67 }; | 74 }; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 } | 284 } |
| 278 | 285 |
| 279 collections.popular = new Collection([ | 286 collections.popular = new Collection([ |
| 280 { | 287 { |
| 281 id: "recommend-list-table" | 288 id: "recommend-list-table" |
| 282 } | 289 } |
| 283 ]); | 290 ]); |
| 284 collections.langs = new Collection([ | 291 collections.langs = new Collection([ |
| 285 { | 292 { |
| 286 id: "blocking-languages-table", | 293 id: "blocking-languages-table", |
| 287 emptyText: "options_dialog_language_added_empty" | 294 emptyText: ["options_dialog_language_added_empty"] |
| 288 }, | 295 }, |
| 289 { | 296 { |
| 290 id: "blocking-languages-dialog-table", | 297 id: "blocking-languages-dialog-table", |
| 291 emptyText: "options_dialog_language_added_empty" | 298 emptyText: ["options_dialog_language_added_empty"] |
| 292 } | 299 } |
| 293 ]); | 300 ]); |
| 294 collections.allLangs = new Collection([ | 301 collections.allLangs = new Collection([ |
| 295 { | 302 { |
| 296 id: "all-lang-table", | 303 id: "all-lang-table", |
| 297 emptyText: "options_dialog_language_other_empty", | 304 emptyText: ["options_dialog_language_other_empty"], |
| 298 searchable: true | 305 searchable: true |
| 299 } | 306 } |
| 300 ]); | 307 ]); |
| 301 collections.acceptableAds = new Collection([ | 308 collections.acceptableAds = new Collection([ |
| 302 { | 309 { |
| 303 id: "acceptableads-table" | 310 id: "acceptableads-table" |
| 304 } | 311 } |
| 305 ]); | 312 ]); |
| 306 collections.custom = new Collection([ | 313 collections.custom = new Collection([ |
| 307 { | 314 { |
| 308 id: "custom-list-table" | 315 id: "custom-list-table" |
| 309 } | 316 } |
| 310 ]); | 317 ]); |
| 311 collections.whitelist = new Collection([ | 318 collections.whitelist = new Collection([ |
| 312 { | 319 { |
| 313 id: "whitelisting-table", | 320 id: "whitelisting-table", |
| 314 emptyText: "options_whitelisted_empty" | 321 emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"] |
| 315 } | 322 } |
| 316 ]); | 323 ]); |
| 317 collections.customFilters = new Collection([ | 324 collections.customFilters = new Collection([ |
| 318 { | 325 { |
| 319 id: "custom-filters-table", | 326 id: "custom-filters-table", |
| 320 emptyText: "options_customFilters_empty" | 327 emptyText: ["options_customFilters_empty"] |
| 321 } | 328 } |
| 322 ]); | 329 ]); |
| 323 collections.filterLists = new Collection([ | 330 collections.filterLists = new Collection([ |
| 324 { | 331 { |
| 325 id: "all-filter-lists-table", | 332 id: "all-filter-lists-table", |
| 326 useOriginalTitle: true | 333 useOriginalTitle: true |
| 327 } | 334 } |
| 328 ]); | 335 ]); |
| 329 | 336 |
| 330 function toggleShowLanguage(subscription) | 337 function toggleShowLanguage(subscription) |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 | 767 |
| 761 updateShareLink(); | 768 updateShareLink(); |
| 762 updateTooltips(); | 769 updateTooltips(); |
| 763 | 770 |
| 764 // Initialize interactive UI elements | 771 // Initialize interactive UI elements |
| 765 document.body.addEventListener("click", onClick, false); | 772 document.body.addEventListener("click", onClick, false); |
| 766 document.body.addEventListener("keyup", onKeyUp, false); | 773 document.body.addEventListener("keyup", onKeyUp, false); |
| 767 let placeholderValue = getMessage("options_dialog_language_find"); | 774 let placeholderValue = getMessage("options_dialog_language_find"); |
| 768 E("find-language").setAttribute("placeholder", placeholderValue); | 775 E("find-language").setAttribute("placeholder", placeholderValue); |
| 769 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 776 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); |
| 770 E("whitelisting-textbox").addEventListener("keypress", (e) => | 777 let exampleValue = getMessage("options_whitelist_placeholder_example"); |
| 778 exampleValue += " www.example.com"; | |
| 779 E("whitelisting-textbox").setAttribute("placeholder", exampleValue); | |
| 780 E("whitelisting-textbox").addEventListener("keyup", (e) => | |
|
Thomas Greiner
2017/05/09 13:42:56
I'm not sure it's a good idea to validate the inpu
saroyanm
2017/05/16 20:20:06
It will, that's why I'm using keyUp instead.
saroyanm
2017/05/18 16:21:52
Fine for now because we are checking for only empt
| |
| 771 { | 781 { |
| 782 let addWhitelistButton = E("whitelisting-add-button"); | |
| 783 let validationElement = E("whitelisting-validation"); | |
| 772 if (getKey(e) == "Enter") | 784 if (getKey(e) == "Enter") |
| 773 addWhitelistedDomain(); | 785 { |
| 786 if (!E("whitelisting-add-button").hasAttribute("disabled")) | |
| 787 addWhitelistedDomain(); | |
| 788 } | |
| 789 else | |
| 790 { | |
| 791 let validIpAddressRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25" | |
|
saroyanm
2017/04/21 12:03:17
Regular expression to match Hostname and IP addres
Thomas Greiner
2017/05/09 13:42:56
Detail: Those are constants that we can simply com
Thomas Greiner
2017/05/09 13:42:56
I don't think we need to be that specific. Somethi
saroyanm
2017/05/16 20:20:07
I think this is not anymore relevant, while the va
| |
| 792 + "[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"; | |
|
Thomas Greiner
2017/05/09 13:42:56
You need to escape the escape characters since you
| |
| 793 let validHostnameRegex = "^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9]" | |
|
Thomas Greiner
2017/05/09 13:42:56
Same here. I don't think we need to be that specif
| |
| 794 +")\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$"; | |
| 795 | |
| 796 let isDuplicate = false; | |
| 797 for (let i = 0; i < collections.whitelist.items.length; i++) | |
| 798 { | |
| 799 if (collections.whitelist.items[i].title == e.target.value) | |
| 800 isDuplicate = true; | |
|
Thomas Greiner
2017/05/09 13:42:56
Detail: Why do we need this variable? We could jus
| |
| 801 } | |
| 802 | |
| 803 if (isDuplicate) | |
| 804 { | |
| 805 addWhitelistButton.setAttribute("disabled", ""); | |
|
saroyanm
2017/04/21 12:03:17
I think we should use checkValidity() method inste
Thomas Greiner
2017/05/09 13:42:56
Detail: Can't we just do `addWhitelistButton.disab
saroyanm
2017/05/16 20:20:06
done.
| |
| 806 validationElement.textContent = | |
| 807 getMessage("options_whitelist_duplicate"); | |
| 808 } | |
| 809 else if (new RegExp(validIpAddressRegex).test(e.target.value) || | |
| 810 new RegExp(validHostnameRegex).test(e.target.value)) | |
| 811 { | |
| 812 addWhitelistButton.removeAttribute("disabled"); | |
| 813 validationElement.textContent = ""; | |
| 814 } | |
| 815 else if (!e.target.value) | |
| 816 { | |
| 817 validationElement.textContent = ""; | |
| 818 addWhitelistButton.setAttribute("disabled", ""); | |
| 819 } | |
| 820 else | |
| 821 { | |
| 822 addWhitelistButton.setAttribute("disabled", ""); | |
| 823 validationElement.textContent = | |
| 824 getMessage("options_whitelist_invalid"); | |
| 825 | |
| 826 } | |
| 827 } | |
| 774 }, false); | 828 }, false); |
| 775 | 829 |
| 776 // Advanced tab | 830 // Advanced tab |
| 777 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); | 831 let tweaks = document.querySelectorAll("#tweaks li[data-pref]"); |
| 778 tweaks = Array.prototype.map.call(tweaks, (checkbox) => | 832 tweaks = Array.prototype.map.call(tweaks, (checkbox) => |
| 779 { | 833 { |
| 780 return checkbox.getAttribute("data-pref"); | 834 return checkbox.getAttribute("data-pref"); |
| 781 }); | 835 }); |
| 782 for (let key of tweaks) | 836 for (let key of tweaks) |
| 783 { | 837 { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 let domain = E("whitelisting-textbox"); | 1033 let domain = E("whitelisting-textbox"); |
| 980 if (domain.value) | 1034 if (domain.value) |
| 981 { | 1035 { |
| 982 sendMessageHandleErrors({ | 1036 sendMessageHandleErrors({ |
| 983 type: "filters.add", | 1037 type: "filters.add", |
| 984 text: "@@||" + domain.value.toLowerCase() + "^$document" | 1038 text: "@@||" + domain.value.toLowerCase() + "^$document" |
| 985 }); | 1039 }); |
| 986 } | 1040 } |
| 987 | 1041 |
| 988 domain.value = ""; | 1042 domain.value = ""; |
| 989 document.querySelector("#whitelisting .controls") | 1043 E("whitelisting-add-button").setAttribute("disabled", ""); |
| 990 .classList.remove("mode-edit"); | |
| 991 } | 1044 } |
| 992 | 1045 |
| 993 function editCustomFilters() | 1046 function editCustomFilters() |
| 994 { | 1047 { |
| 995 let filterTexts = []; | 1048 let filterTexts = []; |
| 996 for (let customFilterItem of collections.customFilters.items) | 1049 for (let customFilterItem of collections.customFilters.items) |
| 997 filterTexts.push(customFilterItem.text); | 1050 filterTexts.push(customFilterItem.text); |
| 998 E("custom-filters-raw").value = filterTexts.join("\n"); | 1051 E("custom-filters-raw").value = filterTexts.join("\n"); |
| 999 } | 1052 } |
| 1000 | 1053 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1297 }); | 1350 }); |
| 1298 ext.backgroundPage.sendMessage({ | 1351 ext.backgroundPage.sendMessage({ |
| 1299 type: "subscriptions.listen", | 1352 type: "subscriptions.listen", |
| 1300 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1353 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
| 1301 "title", "downloadStatus", "downloading"] | 1354 "title", "downloadStatus", "downloading"] |
| 1302 }); | 1355 }); |
| 1303 | 1356 |
| 1304 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1357 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 1305 window.addEventListener("hashchange", onHashChange, false); | 1358 window.addEventListener("hashchange", onHashChange, false); |
| 1306 } | 1359 } |
| OLD | NEW |