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 |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) | 521 function clearListBox(id) |
522 { | 522 { |
523 var list = document.getElementById(id); | 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 while (list.lastChild) | |
525 list.removeChild(list.lastChild); | |
526 } | 524 } |
527 | 525 |
528 // Add a filter string to the list box. | 526 // Add a filter string to the list box. |
529 function appendToListBox(boxId, text) | 527 function appendToListBox(boxId, text) |
530 { | 528 { |
531 // Note: document.createElement("option") is unreliable in Opera | 529 // Note: document.createElement("option") is unreliable in Opera |
532 var elt = new Option(); | 530 var elt = new Option(); |
533 elt.text = text; | 531 elt.text = text; |
534 elt.value = text; | 532 elt.value = text; |
535 document.getElementById(boxId).appendChild(elt); | 533 document.getElementById(boxId).appendChild(elt); |
536 } | 534 } |
537 | 535 |
538 // Remove a filter string from a list box. | 536 // Remove a filter string from a list box. |
539 function removeFromListBox(boxId, text) | 537 function removeFromListBox(boxId, text) |
540 { | 538 { |
541 var list = document.getElementById(boxId); | 539 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
| |
542 for (var i = 0; i < list.length; i++) | 540 let selector = "option[value=" + CSS.escape(text) + "]"; |
543 if (list.options[i].value == text) | 541 for (let option of list.querySelectorAll(selector)) |
544 list.remove(i--); | 542 list.removeChild(option); |
545 } | 543 } |
546 | 544 |
547 function addWhitelistDomain(event) | 545 function addWhitelistDomain(event) |
548 { | 546 { |
549 event.preventDefault(); | 547 event.preventDefault(); |
550 | 548 |
551 var domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g , ""); | 549 var domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g , ""); |
552 document.getElementById("newWhitelistDomain").value = ""; | 550 document.getElementById("newWhitelistDomain").value = ""; |
553 if (!domain) | 551 if (!domain) |
554 return; | 552 return; |
(...skipping 30 matching lines...) Expand all Loading... | |
585 return; | 583 return; |
586 | 584 |
587 for (var i = 0; i < remove.length; i++) | 585 for (var i = 0; i < remove.length; i++) |
588 removeFilter("@@||" + remove[i] + "^$document"); | 586 removeFilter("@@||" + remove[i] + "^$document"); |
589 } | 587 } |
590 | 588 |
591 // Removes all currently selected filters | 589 // Removes all currently selected filters |
592 function removeSelectedFilters(event) | 590 function removeSelectedFilters(event) |
593 { | 591 { |
594 event.preventDefault(); | 592 event.preventDefault(); |
595 var userFiltersBox = document.getElementById("userFiltersBox"); | 593 for (let option of document.querySelectorAll("#userFiltersBox > option:checked ")) |
596 var remove = []; | 594 removeFilter(option.value); |
597 for (var i = 0; i < userFiltersBox.length; i++) | |
598 if (userFiltersBox.options[i].selected) | |
599 remove.push(userFiltersBox.options[i].value); | |
600 if (!remove.length) | |
601 return; | |
602 | |
603 for (var i = 0; i < remove.length; i++) | |
604 removeFilter(remove[i]); | |
605 } | 595 } |
606 | 596 |
607 // Shows raw filters box and fills it with the current user filters | 597 // Shows raw filters box and fills it with the current user filters |
608 function toggleFiltersInRawFormat(event) | 598 function toggleFiltersInRawFormat(event) |
609 { | 599 { |
610 event.preventDefault(); | 600 event.preventDefault(); |
611 | 601 |
602 let text = ""; | |
603 | |
612 $("#rawFilters").toggle(); | 604 $("#rawFilters").toggle(); |
613 if ($("#rawFilters").is(":visible")) | 605 if ($("#rawFilters").is(":visible")) |
614 { | 606 { |
615 var userFiltersBox = document.getElementById("userFiltersBox"); | 607 for (let option of document.getElementById("userFiltersBox").options) |
616 var text = ""; | 608 text += option.value + "\n"; |
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
| |
617 for (var i = 0; i < userFiltersBox.length; i++) | |
618 text += userFiltersBox.options[i].value + "\n"; | |
619 document.getElementById("rawFiltersText").value = text; | |
620 } | 609 } |
610 | |
611 document.getElementById("rawFiltersText").value = text; | |
621 } | 612 } |
622 | 613 |
623 // Imports filters in the raw text box | 614 // Imports filters in the raw text box |
624 function importRawFiltersText() | 615 function importRawFiltersText() |
625 { | 616 { |
626 var text = document.getElementById("rawFiltersText").value; | 617 var text = document.getElementById("rawFiltersText").value; |
627 | 618 |
628 importRawFilters(text, true, function(errors) | 619 importRawFilters(text, true, function(errors) |
629 { | 620 { |
630 if (errors.length > 0) | 621 if (errors.length > 0) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 onFilterMessage(message.action, message.args[0]); | 727 onFilterMessage(message.action, message.args[0]); |
737 break; | 728 break; |
738 case "prefs.respond": | 729 case "prefs.respond": |
739 onPrefMessage(message.action, message.args[0]); | 730 onPrefMessage(message.action, message.args[0]); |
740 break; | 731 break; |
741 case "subscriptions.respond": | 732 case "subscriptions.respond": |
742 onSubscriptionMessage(message.action, message.args[0]); | 733 onSubscriptionMessage(message.action, message.args[0]); |
743 break; | 734 break; |
744 } | 735 } |
745 }); | 736 }); |
OLD | NEW |