Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: options.js

Issue 29369459: Issue 4752 - Improve options page performance for lots of custom filters (Closed)
Patch Set: Improve raw filter box toggle performance Created Dec. 21, 2016, 10:40 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 var list = document.getElementById(id);
524 while (list.lastChild)
525 list.removeChild(list.lastChild);
526 }
527
528 // Add a filter string to the list box. 521 // Add a filter string to the list box.
529 function appendToListBox(boxId, text) 522 function appendToListBox(boxId, text)
530 { 523 {
531 // Note: document.createElement("option") is unreliable in Opera 524 // Note: document.createElement("option") is unreliable in Opera
532 var elt = new Option(); 525 var elt = new Option();
533 elt.text = text; 526 elt.text = text;
534 elt.value = text; 527 elt.value = text;
535 document.getElementById(boxId).appendChild(elt); 528 document.getElementById(boxId).appendChild(elt);
536 } 529 }
537 530
538 // Remove a filter string from a list box. 531 // Remove a filter string from a list box.
539 function removeFromListBox(boxId, text) 532 function removeFromListBox(boxId, text)
540 { 533 {
541 var list = document.getElementById(boxId); 534 let list = document.getElementById(boxId);
542 for (var i = 0; i < list.length; i++) 535 let selector = "option[value=" + CSS.escape(text) + "]";
543 if (list.options[i].value == text) 536 for (let option of list.querySelectorAll(selector))
544 list.remove(i--); 537 list.removeChild(option);
545 } 538 }
546 539
547 function addWhitelistDomain(event) 540 function addWhitelistDomain(event)
548 { 541 {
549 event.preventDefault(); 542 event.preventDefault();
550 543
551 var domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g , ""); 544 var domain = document.getElementById("newWhitelistDomain").value.replace(/\s/g , "");
552 document.getElementById("newWhitelistDomain").value = ""; 545 document.getElementById("newWhitelistDomain").value = "";
553 if (!domain) 546 if (!domain)
554 return; 547 return;
(...skipping 30 matching lines...) Expand all
585 return; 578 return;
586 579
587 for (var i = 0; i < remove.length; i++) 580 for (var i = 0; i < remove.length; i++)
588 removeFilter("@@||" + remove[i] + "^$document"); 581 removeFilter("@@||" + remove[i] + "^$document");
589 } 582 }
590 583
591 // Removes all currently selected filters 584 // Removes all currently selected filters
592 function removeSelectedFilters(event) 585 function removeSelectedFilters(event)
593 { 586 {
594 event.preventDefault(); 587 event.preventDefault();
595 var userFiltersBox = document.getElementById("userFiltersBox"); 588 for (let option of document.querySelectorAll("#userFiltersBox > option:checked "))
596 var remove = []; 589 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 } 590 }
606 591
607 // 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
608 function toggleFiltersInRawFormat(event) 593 function toggleFiltersInRawFormat(event)
609 { 594 {
610 event.preventDefault(); 595 event.preventDefault();
611 596
612 $("#rawFilters").toggle(); 597 let rawFilters = document.getElementById("rawFilters");
613 if ($("#rawFilters").is(":visible")) 598 let filters = [];
599
600 if (rawFilters.style.display == "none")
614 { 601 {
615 var userFiltersBox = document.getElementById("userFiltersBox"); 602 rawFilters.style.display = "table-row";
kzar 2016/12/21 10:44:01 I checked what jQuery was doing when the toggle me
616 var text = ""; 603 for (let option of document.getElementById("userFiltersBox").options)
617 for (var i = 0; i < userFiltersBox.length; i++) 604 filters.push(option.value);
618 text += userFiltersBox.options[i].value + "\n";
619 document.getElementById("rawFiltersText").value = text;
620 } 605 }
606 else
607 {
608 rawFilters.style.display = "none";
609 }
610
611 document.getElementById("rawFiltersText").value = filters.join("\n");
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
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 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld