From 9205f4ac0351c7972361579a47c251effe7705b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81rni=20Dagur?= Date: Wed, 8 Apr 2020 20:36:51 -0400 Subject: Add 'hidden_class_id_selectors' function --- src/lib.rs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 35d8519..579e6ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,8 +19,10 @@ use pyo3::exceptions::ValueError as PyValueError; use pyo3::prelude::*; use pyo3::PyErr; +use std::collections::HashSet; use std::fs; use std::io::{Read, Write}; +use std::iter::FromIterator; /// Brave's adblocking library in Python! #[pymodule] @@ -246,18 +248,26 @@ impl Engine { self.engine.tag_exists(tag) } - // pub fn hidden_class_id_selectors( - // &self, - // classes: Vec, - // ids: Vec, - // exceptions: &PySet, - // ) -> PyResult> { - // let mut exception_hashset: HashSet = HashSet::new(); - // for exception in exceptions.iter() { - // let exception_pystr = PyString::from(exception); - // exception_hashset.insert(exception.to_string()); - // } - // Ok(self.engine - // .hidden_class_id_selectors(&classes, &ids, &exception_hashset)) - // } + /// If any of the provided CSS classes or ids could cause a certain generic + /// CSS hide rule (i.e. `{ display: none !important; }`) to be required, this + /// method will return a list of CSS selectors corresponding to rules + /// referencing those classes or ids, provided that the corresponding rules + /// are not excepted. + /// + /// Exceptions should be passed directly from HostnameSpecificResources. + /// + /// ## Note + /// The `exceptions` field will be changed to a set, once a new version of + /// PyO3 is released. + pub fn hidden_class_id_selectors( + &self, + classes: Vec, + ids: Vec, + exceptions: Vec, + ) -> PyResult> { + let exception_hashset: HashSet = HashSet::from_iter(exceptions); + Ok(self + .engine + .hidden_class_id_selectors(&classes, &ids, &exception_hashset)) + } } -- cgit v1.2.3