OLD | NEW |
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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 { | 22 { |
23 this.Filter = Filter; | 23 this.Filter = Filter; |
24 this.WhitelistFilter = WhitelistFilter; | 24 this.WhitelistFilter = WhitelistFilter; |
25 } | 25 } |
26 with(require("subscriptionClasses")) | 26 with(require("subscriptionClasses")) |
27 { | 27 { |
28 this.Subscription = Subscription; | 28 this.Subscription = Subscription; |
29 this.SpecialSubscription = SpecialSubscription; | 29 this.SpecialSubscription = SpecialSubscription; |
30 this.DownloadableSubscription = DownloadableSubscription; | 30 this.DownloadableSubscription = DownloadableSubscription; |
31 } | 31 } |
| 32 with(require("filterValidation")) |
| 33 { |
| 34 this.parseFilter = parseFilter; |
| 35 this.parseFilters = parseFilters; |
| 36 } |
32 var FilterStorage = require("filterStorage").FilterStorage; | 37 var FilterStorage = require("filterStorage").FilterStorage; |
33 var FilterNotifier = require("filterNotifier").FilterNotifier; | 38 var FilterNotifier = require("filterNotifier").FilterNotifier; |
34 var Prefs = require("prefs").Prefs; | 39 var Prefs = require("prefs").Prefs; |
35 var Synchronizer = require("synchronizer").Synchronizer; | 40 var Synchronizer = require("synchronizer").Synchronizer; |
36 var Utils = require("utils").Utils; | 41 var Utils = require("utils").Utils; |
37 | 42 |
38 // Loads options from localStorage and sets UI elements accordingly | 43 // Loads options from localStorage and sets UI elements accordingly |
39 function loadOptions() | 44 function loadOptions() |
40 { | 45 { |
41 // Set page title to i18n version of "Adblock Plus Options" | 46 // Set page title to i18n version of "Adblock Plus Options" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 470 |
466 var filterText = "@@||" + domain + "^$document"; | 471 var filterText = "@@||" + domain + "^$document"; |
467 FilterStorage.addFilter(Filter.fromText(filterText)); | 472 FilterStorage.addFilter(Filter.fromText(filterText)); |
468 } | 473 } |
469 | 474 |
470 // Adds filter text that user typed to the selection box | 475 // Adds filter text that user typed to the selection box |
471 function addTypedFilter(event) | 476 function addTypedFilter(event) |
472 { | 477 { |
473 event.preventDefault(); | 478 event.preventDefault(); |
474 | 479 |
475 var filterText = Filter.normalize(document.getElementById("newFilter").value); | 480 var element = document.getElementById("newFilter"); |
476 document.getElementById("newFilter").value = ""; | 481 var filter; |
477 if (!filterText) | 482 |
| 483 try |
| 484 { |
| 485 filter = parseFilter(element.value); |
| 486 } |
| 487 catch (error) |
| 488 { |
| 489 alert(error); |
478 return; | 490 return; |
| 491 } |
479 | 492 |
480 FilterStorage.addFilter(Filter.fromText(filterText)); | 493 if (filter) |
| 494 FilterStorage.addFilter(filter); |
| 495 |
| 496 element.value = ""; |
481 } | 497 } |
482 | 498 |
483 // Removes currently selected whitelisted domains | 499 // Removes currently selected whitelisted domains |
484 function removeSelectedExcludedDomain() | 500 function removeSelectedExcludedDomain() |
485 { | 501 { |
486 var excludedDomainsBox = document.getElementById("excludedDomainsBox"); | 502 var excludedDomainsBox = document.getElementById("excludedDomainsBox"); |
487 var remove = []; | 503 var remove = []; |
488 for (var i = 0; i < excludedDomainsBox.length; i++) | 504 for (var i = 0; i < excludedDomainsBox.length; i++) |
489 if (excludedDomainsBox.options[i].selected) | 505 if (excludedDomainsBox.options[i].selected) |
490 remove.push(excludedDomainsBox.options[i].value); | 506 remove.push(excludedDomainsBox.options[i].value); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 var text = ""; | 538 var text = ""; |
523 for (var i = 0; i < userFiltersBox.length; i++) | 539 for (var i = 0; i < userFiltersBox.length; i++) |
524 text += userFiltersBox.options[i].value + "\n"; | 540 text += userFiltersBox.options[i].value + "\n"; |
525 document.getElementById("rawFiltersText").value = text; | 541 document.getElementById("rawFiltersText").value = text; |
526 } | 542 } |
527 } | 543 } |
528 | 544 |
529 // Imports filters in the raw text box | 545 // Imports filters in the raw text box |
530 function importRawFiltersText() | 546 function importRawFiltersText() |
531 { | 547 { |
532 $("#rawFilters").hide(); | 548 var text = document.getElementById("rawFiltersText").value; |
533 var filters = document.getElementById("rawFiltersText").value.split("\n"); | 549 |
| 550 var add; |
| 551 try |
| 552 { |
| 553 add = parseFilters(text, true); |
| 554 } |
| 555 catch (error) |
| 556 { |
| 557 alert(error); |
| 558 return; |
| 559 } |
| 560 |
534 var seenFilter = {__proto__: null}; | 561 var seenFilter = {__proto__: null}; |
535 for (var i = 0; i < filters.length; i++) | 562 for (var i = 0; i < add.length; i++) |
536 { | 563 { |
537 var text = Filter.normalize(filters[i]); | 564 var filter = add[i]; |
538 if (!text) | 565 FilterStorage.addFilter(filter); |
539 continue; | 566 seenFilter[filter.text] = null; |
540 | |
541 // Don't import filter list header | |
542 if (/^\[/.test(text)) | |
543 continue; | |
544 | |
545 FilterStorage.addFilter(Filter.fromText(text)); | |
546 seenFilter[text] = true; | |
547 } | 567 } |
548 | 568 |
549 var remove = []; | 569 var remove = []; |
550 for (var i = 0; i < FilterStorage.subscriptions.length; i++) | 570 for (var i = 0; i < FilterStorage.subscriptions.length; i++) |
551 { | 571 { |
552 var subscription = FilterStorage.subscriptions[i]; | 572 var subscription = FilterStorage.subscriptions[i]; |
553 if (!(subscription instanceof SpecialSubscription)) | 573 if (!(subscription instanceof SpecialSubscription)) |
554 continue; | 574 continue; |
555 | 575 |
556 for (var j = 0; j < subscription.filters.length; j++) | 576 for (var j = 0; j < subscription.filters.length; j++) |
557 { | 577 { |
558 var filter = subscription.filters[j]; | 578 var filter = subscription.filters[j]; |
559 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.t
est(filter.text)) | 579 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.t
est(filter.text)) |
560 continue; | 580 continue; |
561 | 581 |
562 if (!(filter.text in seenFilter)) | 582 if (!(filter.text in seenFilter)) |
563 remove.push(filter); | 583 remove.push(filter); |
564 } | 584 } |
565 } | 585 } |
| 586 |
566 for (var i = 0; i < remove.length; i++) | 587 for (var i = 0; i < remove.length; i++) |
567 FilterStorage.removeFilter(remove[i]); | 588 FilterStorage.removeFilter(remove[i]); |
| 589 |
| 590 $("#rawFilters").hide(); |
568 } | 591 } |
569 | 592 |
570 // Called when user explicitly requests filter list updates | 593 // Called when user explicitly requests filter list updates |
571 function updateFilterLists() | 594 function updateFilterLists() |
572 { | 595 { |
573 for (var i = 0; i < FilterStorage.subscriptions.length; i++) | 596 for (var i = 0; i < FilterStorage.subscriptions.length; i++) |
574 { | 597 { |
575 var subscription = FilterStorage.subscriptions[i]; | 598 var subscription = FilterStorage.subscriptions[i]; |
576 if (subscription instanceof DownloadableSubscription) | 599 if (subscription instanceof DownloadableSubscription) |
577 Synchronizer.execute(subscription, true, true); | 600 Synchronizer.execute(subscription, true, true); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 links[i].href = arguments[i + 1]; | 648 links[i].href = arguments[i + 1]; |
626 links[i].setAttribute("target", "_blank"); | 649 links[i].setAttribute("target", "_blank"); |
627 } | 650 } |
628 else if (typeof arguments[i + 1] == "function") | 651 else if (typeof arguments[i + 1] == "function") |
629 { | 652 { |
630 links[i].href = "javascript:void(0);"; | 653 links[i].href = "javascript:void(0);"; |
631 links[i].addEventListener("click", arguments[i + 1], false); | 654 links[i].addEventListener("click", arguments[i + 1], false); |
632 } | 655 } |
633 } | 656 } |
634 } | 657 } |
OLD | NEW |