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

Unified Diff: lib/cssRules.js

Issue 29324599: Issue 2392/2393 - Created container for CSS property filters (Closed)
Patch Set: Rebased and addressed comments Created Nov. 25, 2015, 11:12 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/cssRules.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/cssRules.js
@@ -0,0 +1,76 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2015 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @fileOverview CSS property filtering implementation.
+ */
+
+let {ElemHide} = require("elemHide");
+let {Filter} = require("filterClasses");
+
+let filters = Object.create(null);
+
+/**
+ * CSS rules component
+ * @class
+ */
+let CSSRules = exports.CSSRules =
+{
+ /**
+ * Removes all known filters
+ */
+ clear: function()
+ {
+ filters = Object.create(null);
+ },
+
+ /**
+ * Add a new CSS property filter
+ * @param {CSSPropertyFilter} filter
+ */
+ add: function(filter)
+ {
+ filters[filter.text] = true;
+ },
+
+ /**
+ * Removes a CSS property filter
+ * @param {CSSPropertyFilter} filter
+ */
+ remove: function(filter)
+ {
+ delete filters[filter.text];
+ },
+
+ /**
+ * Returns a list of all rules active on a particular domain
+ * @param {String} domain
+ * @return {Array.<CSSPropertyFilter>}
Wladimir Palant 2015/11/26 12:52:46 Nit: We usually use CSSPropertyFilter[] which is s
Thomas Greiner 2015/11/30 13:51:16 Done. Will include that change in the commit.
+ */
+ getRulesForDomain: function(domain)
+ {
+ let result = [];
+ let keys = Object.getOwnPropertyNames(filters);
+ for (let key of keys)
+ {
+ let filter = Filter.fromText(key);
+ if (filter.isActiveOnDomain(domain) && !ElemHide.getException(filter, domain))
+ result.push(filter);
+ }
+ return result;
+ }
+};
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld