OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of the Adblock Plus extension, |
| 3 * Copyright (C) 2006-2012 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
| 18 var API = (function() |
| 19 { |
| 20 var Filter = require("filterClasses").Filter; |
| 21 var Subscription = require("subscriptionClasses").Subscription; |
| 22 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; |
| 23 var FilterStorage = require("filterStorage").FilterStorage; |
| 24 var defaultMatcher = require("matcher").defaultMatcher; |
| 25 var ElemHide = require("elemHide").ElemHide; |
| 26 var Synchronizer = require("synchronizer").Synchronizer; |
| 27 |
| 28 return { |
| 29 getFilterFromText: function(text) |
| 30 { |
| 31 text = Filter.normalize(text); |
| 32 if (!text) |
| 33 throw "Attempted to create a filter from empty text"; |
| 34 return Filter.fromText(text); |
| 35 }, |
| 36 |
| 37 isListedFilter: function(filter) |
| 38 { |
| 39 return filter.subscriptions.some(function(s) |
| 40 { |
| 41 return (s instanceof SpecialSubscription && !s.disabled); |
| 42 }); |
| 43 }, |
| 44 |
| 45 addFilterToList: function(filter) |
| 46 { |
| 47 FilterStorage.addFilter(filter); |
| 48 }, |
| 49 |
| 50 removeFilterFromList: function(filter) |
| 51 { |
| 52 FilterStorage.removeFilter(filter); |
| 53 }, |
| 54 |
| 55 getListedFilters: function() |
| 56 { |
| 57 var filters = {}; |
| 58 for (var i = 0; i < FilterStorage.subscriptions.length; i++) |
| 59 { |
| 60 var subscription = FilterStorage.subscriptions[i]; |
| 61 if (subscription instanceof SpecialSubscription) |
| 62 { |
| 63 for (var j = 0; j < subscription.filters.length; j++) |
| 64 { |
| 65 var filter = subscription.filters[j]; |
| 66 if (!(filter.text in filters)) |
| 67 filters[filter.text] = filter; |
| 68 } |
| 69 } |
| 70 } |
| 71 return Object.keys(filters).map(function(k) |
| 72 { |
| 73 return filters[k]; |
| 74 }); |
| 75 }, |
| 76 |
| 77 getSubscriptionFromUrl: function(url) |
| 78 { |
| 79 return Subscription.fromURL(url); |
| 80 }, |
| 81 |
| 82 isListedSubscription: function(subscription) |
| 83 { |
| 84 return subscription.url in FilterStorage.knownSubscriptions; |
| 85 }, |
| 86 |
| 87 addSubscriptionToList: function(subscription) |
| 88 { |
| 89 FilterStorage.addSubscription(subscription); |
| 90 |
| 91 // TODO, this currently crashes due to errors reported on a thread |
| 92 //if (!subscription.lastDownload) |
| 93 // Synchronizer.execute(subscription); |
| 94 }, |
| 95 |
| 96 removeSubscriptionFromList: function(subscription) |
| 97 { |
| 98 FilterStorage.removeSubscription(subscription); |
| 99 }, |
| 100 |
| 101 getListedSubscriptions: function() |
| 102 { |
| 103 return FilterStorage.subscriptions.filter(function(s) |
| 104 { |
| 105 return !(s instanceof SpecialSubscription) |
| 106 }); |
| 107 }, |
| 108 |
| 109 checkFilterMatch: function(url, contentType, documentUrl) |
| 110 { |
| 111 // TODO: set thirdParty properly |
| 112 var thirdParty = false; |
| 113 return defaultMatcher.matchesAny(url, contentType, documentUrl, thirdParty
); |
| 114 }, |
| 115 |
| 116 getElementHidingSelectors: function(domain) |
| 117 { |
| 118 return ElemHide.getSelectorsForDomain(domain, false); |
| 119 } |
| 120 }; |
| 121 })(); |
OLD | NEW |