chromiumoxide/handler/blockers/
mod.rspub mod adblock_patterns;
pub mod intercept_manager;
pub mod scripts;
pub mod xhr;
#[derive(Default, Debug)]
pub struct TrieNode {
pub children: hashbrown::HashMap<char, TrieNode>,
pub is_end_of_word: bool,
}
#[derive(Debug)]
pub struct Trie {
pub root: TrieNode,
}
impl Trie {
pub fn new() -> Self {
Trie {
root: TrieNode::default(),
}
}
pub fn insert(&mut self, word: &str) {
let mut node = &mut self.root;
for ch in word.chars() {
node = node.children.entry(ch).or_insert_with(TrieNode::default);
}
node.is_end_of_word = true;
}
#[inline]
pub fn contains_prefix(&self, text: &str) -> bool {
let mut node = &self.root;
for ch in text.chars() {
if let Some(next_node) = node.children.get(&ch) {
node = next_node;
if node.is_end_of_word {
return true;
}
} else {
break;
}
}
false
}
}
pub(crate) fn ignore_script_embedded(url: &str) -> bool {
crate::handler::blockers::scripts::URL_IGNORE_EMBEDED_TRIE.contains_prefix(url)
}
pub(crate) fn ignore_script_xhr(url: &str) -> bool {
crate::handler::blockers::xhr::URL_IGNORE_XHR_TRIE.contains_prefix(url)
}
pub(crate) fn ignore_script_xhr_media(url: &str) -> bool {
crate::handler::blockers::xhr::URL_IGNORE_XHR_MEDIA_TRIE.contains_prefix(url)
}