-
Notifications
You must be signed in to change notification settings - Fork 106
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
zu1k
committed
Sep 14, 2021
1 parent
adb3ccc
commit b9dfca7
Showing
9 changed files
with
254 additions
and
26 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
- name: "奈菲影视去广告" | ||
filter: | ||
url-regex: '(nfmovies)(?!.*?(\.css|\.js|\.jpeg|\.png|\.gif)).*' | ||
action: | ||
modify: | ||
body: | ||
origin: '<head>' | ||
new: '<link rel="stylesheet" href="https://limbopro.com/CSS/nfmovies.css" type="text/css"><script type="text/javascript" src="//limbopro.com/Adguard/nfmovies.js"></script></head>' | ||
|
||
- name: "低端影视去广告" | ||
filter: | ||
url-regex: '^https:?/\/ddrk.me.*' | ||
action: | ||
modify: | ||
body: | ||
origin: '<head>' | ||
new: '<head><link rel="stylesheet" href="https://limbopro.com/CSS/ddrk.css" type="text/css"><script type="text/javascript" src="//limbopro.com/Adguard/ddrk.js"></script>' | ||
|
||
- name: "跳转博客" | ||
filter: | ||
domain: 'none.lgf.im' | ||
action: | ||
redirect: "https://lgf.im/" |
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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::action; | ||
use serde::{Deserialize, Serialize}; | ||
use std::error::Error; | ||
use std::path::Path; | ||
use std::{fs::File, io::BufReader}; | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct Rule { | ||
pub name: String, | ||
pub filter: Filter, | ||
pub action: action::Action, | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
#[serde(rename_all = "kebab-case")] | ||
pub enum Filter { | ||
Domain(String), | ||
DomainKeyword(String), | ||
DomainPrefix(String), | ||
DomainSuffix(String), | ||
UrlRegex(String), | ||
} | ||
|
||
pub fn read_rules_from_file<P: AsRef<Path>>(path: P) -> Result<Vec<Rule>, Box<dyn Error>> { | ||
let file = File::open(path)?; | ||
let reader = BufReader::new(file); | ||
let rules = serde_yaml::from_reader(reader)?; | ||
Ok(rules) | ||
} | ||
|
||
#[test] | ||
fn test_gen_yaml() { | ||
let rules = vec![ | ||
Rule { | ||
name: "demo rule 1".into(), | ||
filter: Filter::Domain("domain.com".into()), | ||
action: action::Action::Modify(action::Modify::new_modify_body( | ||
"origin body", | ||
"new body", | ||
)), | ||
}, | ||
Rule { | ||
name: "demo rule 2".into(), | ||
filter: Filter::UrlRegex(r".*\.domain.com".into()), | ||
action: action::Action::Modify(action::Modify::new_modify_body( | ||
"origin body", | ||
"new body", | ||
)), | ||
}, | ||
]; | ||
|
||
let s = serde_yaml::to_string(&rules).expect("serde yaml failed!"); | ||
println!("{}", s); | ||
|
||
let f = include_str!("../../assets/rules/demo.yaml"); | ||
let rules: Vec<Rule> = serde_yaml::from_str(f).expect("parse failed!"); | ||
println!("{:#?}", rules); | ||
if let Filter::UrlRegex(r) = rules[0].clone().filter { | ||
println!("{}", r) | ||
} | ||
|
||
// match read_rules_from_file("assets/rules/demo.yaml") { | ||
// Ok(rules) => println!("{:#?}", rules), | ||
// Err(err) => panic!("{}", err), | ||
// } | ||
} |
Oops, something went wrong.