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

Side by Side Diff: options.js

Issue 5279235799252992: Issue 491 - Validate custom filters (Closed)
Patch Set: Created Nov. 18, 2014, 3:57 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« block.js ('K') | « block.js ('k') | 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var backgroundPage = ext.backgroundPage.getWindow(); 18 var backgroundPage = ext.backgroundPage.getWindow();
19 var require = backgroundPage.require; 19 var require = backgroundPage.require;
20 20
21 with(require("filterClasses")) 21 with(require("filterClasses"))
22 { 22 {
23 this.Filter = Filter; 23 this.Filter = Filter;
24 this.WhitelistFilter = WhitelistFilter; 24 this.WhitelistFilter = WhitelistFilter;
25 this.InvalidFilter = InvalidFilter;
25 } 26 }
26 with(require("subscriptionClasses")) 27 with(require("subscriptionClasses"))
27 { 28 {
28 this.Subscription = Subscription; 29 this.Subscription = Subscription;
29 this.SpecialSubscription = SpecialSubscription; 30 this.SpecialSubscription = SpecialSubscription;
30 this.DownloadableSubscription = DownloadableSubscription; 31 this.DownloadableSubscription = DownloadableSubscription;
31 } 32 }
32 var FilterStorage = require("filterStorage").FilterStorage; 33 var FilterStorage = require("filterStorage").FilterStorage;
33 var FilterNotifier = require("filterNotifier").FilterNotifier; 34 var FilterNotifier = require("filterNotifier").FilterNotifier;
34 var Prefs = require("prefs").Prefs; 35 var Prefs = require("prefs").Prefs;
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 var filterText = "@@||" + domain + "^$document"; 467 var filterText = "@@||" + domain + "^$document";
467 FilterStorage.addFilter(Filter.fromText(filterText)); 468 FilterStorage.addFilter(Filter.fromText(filterText));
468 } 469 }
469 470
470 // Adds filter text that user typed to the selection box 471 // Adds filter text that user typed to the selection box
471 function addTypedFilter(event) 472 function addTypedFilter(event)
472 { 473 {
473 event.preventDefault(); 474 event.preventDefault();
474 475
475 var filterText = Filter.normalize(document.getElementById("newFilter").value); 476 var filterText = Filter.normalize(document.getElementById("newFilter").value);
477 if (filterText)
478 {
kzar 2014/11/18 16:32:10 Seems like the logic here is duplicated from backg
Sebastian Noack 2014/11/18 17:42:55 The only common code is the call to alert(). Note
479 var filter = Filter.fromText(filterText, true)
480 if (filter instanceof InvalidFilter)
481 {
482 alert(filter.reason);
483 return;
kzar 2014/11/18 16:32:10 IMHO it would be more readable if you omitted the
Sebastian Noack 2014/11/18 17:42:55 Then the code below which clears the field would a
484 }
485
486 FilterStorage.addFilter(filter);
487 }
488
476 document.getElementById("newFilter").value = ""; 489 document.getElementById("newFilter").value = "";
477 if (!filterText)
478 return;
479
480 FilterStorage.addFilter(Filter.fromText(filterText));
481 } 490 }
482 491
483 // Removes currently selected whitelisted domains 492 // Removes currently selected whitelisted domains
484 function removeSelectedExcludedDomain() 493 function removeSelectedExcludedDomain()
485 { 494 {
486 var excludedDomainsBox = document.getElementById("excludedDomainsBox"); 495 var excludedDomainsBox = document.getElementById("excludedDomainsBox");
487 var remove = []; 496 var remove = [];
488 for (var i = 0; i < excludedDomainsBox.length; i++) 497 for (var i = 0; i < excludedDomainsBox.length; i++)
489 if (excludedDomainsBox.options[i].selected) 498 if (excludedDomainsBox.options[i].selected)
490 remove.push(excludedDomainsBox.options[i].value); 499 remove.push(excludedDomainsBox.options[i].value);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 var text = ""; 531 var text = "";
523 for (var i = 0; i < userFiltersBox.length; i++) 532 for (var i = 0; i < userFiltersBox.length; i++)
524 text += userFiltersBox.options[i].value + "\n"; 533 text += userFiltersBox.options[i].value + "\n";
525 document.getElementById("rawFiltersText").value = text; 534 document.getElementById("rawFiltersText").value = text;
526 } 535 }
527 } 536 }
528 537
529 // Imports filters in the raw text box 538 // Imports filters in the raw text box
530 function importRawFiltersText() 539 function importRawFiltersText()
531 { 540 {
532 $("#rawFilters").hide();
533 var filters = document.getElementById("rawFiltersText").value.split("\n"); 541 var filters = document.getElementById("rawFiltersText").value.split("\n");
534 var seenFilter = {__proto__: null}; 542 var seenFilter = {__proto__: null};
543
544 var add = [];
535 for (var i = 0; i < filters.length; i++) 545 for (var i = 0; i < filters.length; i++)
536 { 546 {
537 var text = Filter.normalize(filters[i]); 547 var text = Filter.normalize(filters[i]);
538 if (!text) 548 if (!text)
539 continue; 549 continue;
540 550
541 // Don't import filter list header 551 // Don't import filter list header
542 if (/^\[/.test(text)) 552 if (/^\[/.test(text))
543 continue; 553 continue;
Wladimir Palant 2014/11/19 16:03:11 You've removed that logic. People will occasionall
Sebastian Noack 2014/11/20 12:51:19 When I unified the code into a reusable helper fun
544 554
545 FilterStorage.addFilter(Filter.fromText(text)); 555 var filter = Filter.fromText(text, true);
kzar 2014/11/18 16:32:10 Again seems like this logic is duplicate of above
556 if (filter instanceof InvalidFilter)
557 {
558 alert(filter.reason);
559 return;
560 }
Wladimir Palant 2014/11/18 16:35:03 It would probably make sense to have a filter vali
561
562 add.push(filter);
546 seenFilter[text] = true; 563 seenFilter[text] = true;
547 } 564 }
565 for (var i = 0; i < add.length; i++)
566 FilterStorage.addFilter(add[i]);
548 567
549 var remove = []; 568 var remove = [];
550 for (var i = 0; i < FilterStorage.subscriptions.length; i++) 569 for (var i = 0; i < FilterStorage.subscriptions.length; i++)
551 { 570 {
552 var subscription = FilterStorage.subscriptions[i]; 571 var subscription = FilterStorage.subscriptions[i];
553 if (!(subscription instanceof SpecialSubscription)) 572 if (!(subscription instanceof SpecialSubscription))
554 continue; 573 continue;
555 574
556 for (var j = 0; j < subscription.filters.length; j++) 575 for (var j = 0; j < subscription.filters.length; j++)
557 { 576 {
558 var filter = subscription.filters[j]; 577 var filter = subscription.filters[j];
559 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.t est(filter.text)) 578 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.t est(filter.text))
560 continue; 579 continue;
561 580
562 if (!(filter.text in seenFilter)) 581 if (!(filter.text in seenFilter))
563 remove.push(filter); 582 remove.push(filter);
564 } 583 }
565 } 584 }
566 for (var i = 0; i < remove.length; i++) 585 for (var i = 0; i < remove.length; i++)
567 FilterStorage.removeFilter(remove[i]); 586 FilterStorage.removeFilter(remove[i]);
587
588 $("#rawFilters").hide();
568 } 589 }
569 590
570 // Called when user explicitly requests filter list updates 591 // Called when user explicitly requests filter list updates
571 function updateFilterLists() 592 function updateFilterLists()
572 { 593 {
573 for (var i = 0; i < FilterStorage.subscriptions.length; i++) 594 for (var i = 0; i < FilterStorage.subscriptions.length; i++)
574 { 595 {
575 var subscription = FilterStorage.subscriptions[i]; 596 var subscription = FilterStorage.subscriptions[i];
576 if (subscription instanceof DownloadableSubscription) 597 if (subscription instanceof DownloadableSubscription)
577 Synchronizer.execute(subscription, true, true); 598 Synchronizer.execute(subscription, true, true);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 links[i].href = arguments[i + 1]; 646 links[i].href = arguments[i + 1];
626 links[i].setAttribute("target", "_blank"); 647 links[i].setAttribute("target", "_blank");
627 } 648 }
628 else if (typeof arguments[i + 1] == "function") 649 else if (typeof arguments[i + 1] == "function")
629 { 650 {
630 links[i].href = "javascript:void(0);"; 651 links[i].href = "javascript:void(0);";
631 links[i].addEventListener("click", arguments[i + 1], false); 652 links[i].addEventListener("click", arguments[i + 1], false);
632 } 653 }
633 } 654 }
634 } 655 }
OLDNEW
« block.js ('K') | « block.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld