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-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 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 if (subscription.url == acceptableAdsUrl) | 216 if (subscription.url == acceptableAdsUrl) |
217 $("#acceptableAds").prop("checked", !subscription.disabled); | 217 $("#acceptableAds").prop("checked", !subscription.disabled); |
218 else | 218 else |
219 addSubscriptionEntry(subscription); | 219 addSubscriptionEntry(subscription); |
220 } | 220 } |
221 }); | 221 }); |
222 | 222 |
223 // User-entered filters | 223 // User-entered filters |
224 getSubscriptions(false, true, function(subscriptions) | 224 getSubscriptions(false, true, function(subscriptions) |
225 { | 225 { |
226 clearListBox("userFiltersBox"); | 226 document.getElementById("userFiltersBox").innerHTML = ""; |
227 clearListBox("excludedDomainsBox"); | 227 document.getElementById("excludedDomainsBox").innerHTML = ""; |
228 | 228 |
229 for (var i = 0; i < subscriptions.length; i++) | 229 for (var i = 0; i < subscriptions.length; i++) |
230 convertSpecialSubscription(subscriptions[i]); | 230 convertSpecialSubscription(subscriptions[i]); |
231 }); | 231 }); |
232 } | 232 } |
233 | 233 |
234 function initCheckbox(id, key) | 234 function initCheckbox(id, key) |
235 { | 235 { |
236 key = key || id; | 236 key = key || id; |
237 var checkbox = document.getElementById(id); | 237 var checkbox = document.getElementById(id); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 break; | 511 break; |
512 case "removed": | 512 case "removed": |
513 if (whitelistedDomainRegexp.test(filter.text)) | 513 if (whitelistedDomainRegexp.test(filter.text)) |
514 removeFromListBox("excludedDomainsBox", RegExp.$1); | 514 removeFromListBox("excludedDomainsBox", RegExp.$1); |
515 else | 515 else |
516 removeFromListBox("userFiltersBox", filter.text); | 516 removeFromListBox("userFiltersBox", filter.text); |
517 break; | 517 break; |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 function clearListBox(id) | |
522 { | |
523 document.getElementById(id).innerHTML = ""; | |
Sebastian Noack
2016/12/20 21:38:18
IMO, this isn't worth a function anymore, and shou
kzar
2016/12/21 10:44:01
Done.
| |
524 } | |
525 | |
526 // Add a filter string to the list box. | 521 // Add a filter string to the list box. |
527 function appendToListBox(boxId, text) | 522 function appendToListBox(boxId, text) |
528 { | 523 { |
529 // Note: document.createElement("option") is unreliable in Opera | 524 // Note: document.createElement("option") is unreliable in Opera |
530 var elt = new Option(); | 525 var elt = new Option(); |
531 elt.text = text; | 526 elt.text = text; |
532 elt.value = text; | 527 elt.value = text; |
533 document.getElementById(boxId).appendChild(elt); | 528 document.getElementById(boxId).appendChild(elt); |
534 } | 529 } |
535 | 530 |
536 // Remove a filter string from a list box. | 531 // Remove a filter string from a list box. |
537 function removeFromListBox(boxId, text) | 532 function removeFromListBox(boxId, text) |
538 { | 533 { |
539 let list = document.getElementById(boxId); | 534 let list = document.getElementById(boxId); |
Sebastian Noack
2016/12/20 21:38:18
That is unrelated, but I suppose we should go and
kzar
2016/12/21 10:44:01
Yea I considered that too. It's not as trivial as
Sebastian Noack
2016/12/21 16:13:38
Well, so far we used arrow functions only in code
| |
540 let selector = "option[value=" + CSS.escape(text) + "]"; | 535 let selector = "option[value=" + CSS.escape(text) + "]"; |
541 for (let option of list.querySelectorAll(selector)) | 536 for (let option of list.querySelectorAll(selector)) |
542 list.removeChild(option); | 537 list.removeChild(option); |
543 } | 538 } |
544 | 539 |
545 function addWhitelistDomain(event) | 540 function addWhitelistDomain(event) |
546 { | 541 { |
547 event.preventDefault(); | 542 event.preventDefault(); |
548 | 543 |
549 var domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g , ""); | 544 var domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g , ""); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 event.preventDefault(); | 587 event.preventDefault(); |
593 for (let option of document.querySelectorAll("#userFiltersBox > option:checked ")) | 588 for (let option of document.querySelectorAll("#userFiltersBox > option:checked ")) |
594 removeFilter(option.value); | 589 removeFilter(option.value); |
595 } | 590 } |
596 | 591 |
597 // Shows raw filters box and fills it with the current user filters | 592 // Shows raw filters box and fills it with the current user filters |
598 function toggleFiltersInRawFormat(event) | 593 function toggleFiltersInRawFormat(event) |
599 { | 594 { |
600 event.preventDefault(); | 595 event.preventDefault(); |
601 | 596 |
602 let text = ""; | 597 let rawFilters = document.getElementById("rawFilters"); |
603 | 598 let filters = []; |
604 $("#rawFilters").toggle(); | 599 |
605 if ($("#rawFilters").is(":visible")) | 600 if (rawFilters.style.display != "table-row") |
606 { | 601 { |
602 rawFilters.style.display = "table-row"; | |
607 for (let option of document.getElementById("userFiltersBox").options) | 603 for (let option of document.getElementById("userFiltersBox").options) |
608 text += option.value + "\n"; | 604 filters.push(option.value); |
Sebastian Noack
2016/12/20 21:38:18
String concatenation using a loop is potentially s
kzar
2016/12/21 10:44:01
Done, it does perform a little better. Interesting
| |
609 } | 605 } |
610 | 606 else |
611 document.getElementById("rawFiltersText").value = text; | 607 { |
608 rawFilters.style.display = "none"; | |
609 } | |
610 | |
611 document.getElementById("rawFiltersText").value = filters.join("\n"); | |
612 } | 612 } |
613 | 613 |
614 // Imports filters in the raw text box | 614 // Imports filters in the raw text box |
615 function importRawFiltersText() | 615 function importRawFiltersText() |
616 { | 616 { |
617 var text = document.getElementById("rawFiltersText").value; | 617 var text = document.getElementById("rawFiltersText").value; |
618 | 618 |
619 importRawFilters(text, true, function(errors) | 619 importRawFilters(text, true, function(errors) |
620 { | 620 { |
621 if (errors.length > 0) | 621 if (errors.length > 0) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 onFilterMessage(message.action, message.args[0]); | 727 onFilterMessage(message.action, message.args[0]); |
728 break; | 728 break; |
729 case "prefs.respond": | 729 case "prefs.respond": |
730 onPrefMessage(message.action, message.args[0]); | 730 onPrefMessage(message.action, message.args[0]); |
731 break; | 731 break; |
732 case "subscriptions.respond": | 732 case "subscriptions.respond": |
733 onSubscriptionMessage(message.action, message.args[0]); | 733 onSubscriptionMessage(message.action, message.args[0]); |
734 break; | 734 break; |
735 } | 735 } |
736 }); | 736 }); |
LEFT | RIGHT |