-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
427 additions
and
173 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "spider" | ||
version = "2.21.13" | ||
version = "2.21.15" | ||
authors = [ | ||
"j-mendez <[email protected]>" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "spider_chrome" | ||
version = "2.21.13" | ||
version = "2.21.15" | ||
rust-version = "1.70" | ||
authors = [ | ||
"j-mendez <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
spider_chrome/src/handler/blockers/intercept_manager.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/// Custom network intercept types to expect on a domain | ||
#[derive(Debug, Default, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq)] | ||
pub enum NetworkInterceptManager { | ||
/// tiktok.com | ||
TikTok, | ||
/// facebook.com | ||
Facebook, | ||
/// amazon.com | ||
Amazon, | ||
/// x.com | ||
X, | ||
/// LinkedIn, | ||
LinkedIn, | ||
/// netflix.com | ||
Netflix, | ||
/// medium.com | ||
Medium, | ||
/// upwork.com, | ||
Upwork, | ||
/// glassdoor.com | ||
Glassdoor, | ||
/// ebay.com | ||
Ebay, | ||
/// nytimes.com | ||
Nytimes, | ||
/// wikipedia.com | ||
Wikipedia, | ||
#[default] | ||
/// Unknown | ||
Unknown, | ||
} | ||
|
||
lazy_static::lazy_static! { | ||
/// Top tier list of the most common websites visited. | ||
pub static ref TOP_TIER_LIST: [(&'static str, NetworkInterceptManager); 21] = [ | ||
("https://www.tiktok.com", NetworkInterceptManager::TikTok), | ||
("https://tiktok.com", NetworkInterceptManager::TikTok), | ||
("https://www.amazon.", NetworkInterceptManager::Amazon), | ||
("https://amazon.", NetworkInterceptManager::Amazon), | ||
("https://www.x.com", NetworkInterceptManager::X), | ||
("https://x.com", NetworkInterceptManager::X), | ||
("https://www.netflix.com", NetworkInterceptManager::Netflix), | ||
("https://netflix.com", NetworkInterceptManager::Netflix), | ||
( | ||
"https://www.linkedin.com", | ||
NetworkInterceptManager::LinkedIn | ||
), | ||
("https://linkedin.com", NetworkInterceptManager::LinkedIn), | ||
("https://www.upwork.com", NetworkInterceptManager::Upwork), | ||
("https://upwork.com", NetworkInterceptManager::Upwork), | ||
("https://www.glassdoor.", NetworkInterceptManager::Glassdoor), | ||
("https://glassdoor.", NetworkInterceptManager::Glassdoor), | ||
("https://www.medium.com", NetworkInterceptManager::Medium), | ||
("https://medium.com", NetworkInterceptManager::Medium), | ||
("https://www.ebay.", NetworkInterceptManager::Ebay), | ||
("https://ebay.", NetworkInterceptManager::Ebay), | ||
("https://www.nytimes.com", NetworkInterceptManager::Nytimes), | ||
("https://nytimes.com", NetworkInterceptManager::Nytimes), | ||
("wikipedia.org", NetworkInterceptManager::Wikipedia), | ||
]; | ||
} | ||
|
||
/// The find type is own. | ||
#[derive(Default, Debug, Clone, Hash, PartialEq, Eq)] | ||
enum FindType { | ||
#[default] | ||
/// Starts with. | ||
StartsWith, | ||
/// Contains. | ||
Contains, | ||
} | ||
|
||
impl NetworkInterceptManager { | ||
/// a custom intercept handle. | ||
pub fn new(url: &str) -> NetworkInterceptManager { | ||
TOP_TIER_LIST | ||
.iter() | ||
.find(|&(pattern, nm)| { | ||
if nm.get_pattern() == FindType::StartsWith { | ||
url.starts_with(pattern) | ||
} else { | ||
url.contains(pattern) | ||
} | ||
}) | ||
.map(|&(_, manager_type)| manager_type) | ||
.unwrap_or(NetworkInterceptManager::Unknown) | ||
} | ||
/// Setup the intercept handle | ||
pub fn setup(&mut self, url: &str) -> Self { | ||
NetworkInterceptManager::new(url) | ||
} | ||
|
||
/// determine the pattern to use. | ||
fn get_pattern(&self) -> FindType { | ||
match self { | ||
NetworkInterceptManager::Wikipedia => FindType::Contains, | ||
_ => FindType::StartsWith, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.