-
Notifications
You must be signed in to change notification settings - Fork 116
/
generate-dat.rs
35 lines (30 loc) · 1022 Bytes
/
generate-dat.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use adblock::{
Engine,
request::Request,
};
use std::fs::File;
use std::io::prelude::*;
fn main() {
// Rules we want to serialize
let rules = vec![
String::from("||platform.twitter.com/$tag=twitter-embeds"),
String::from("@@||platform.twitter.com/$tag=twitter-embeds"),
];
// Serialize
let mut engine = Engine::from_rules_debug(&rules, Default::default());
engine.use_tags(&["twitter-embeds"]);
let request = Request::new(
"https://platform.twitter.com/widgets.js",
"https://fmarier.github.io/brave-testing/social-widgets.html",
"script"
).unwrap();
assert!(engine
.check_network_request(&request)
.exception
.is_some());
let serialized = engine.serialize_raw().expect("Could not serialize!");
// Write to file
let mut file = File::create("engine.dat").expect("Could not create serialization file");
file.write_all(&serialized)
.expect("Could not output serialized engine to file");
}