Skip to content

Commit 371a986

Browse files
author
Sergey Bargamon
committed
custom string for your_mom mode
1 parent 560b7c4 commit 371a986

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ In 0.4.0, we introduced the toml config. Clink will create a "clink.toml" file i
1111
# You can find detail description of modes bellow
1212
# one of: remove, your_mom, evil
1313
mode = 'remove'
14+
# text for your_mom mode
15+
your_mom = 'your_mom'
1416
# How often Clink will check clipboard in milliseconds
1517
sleep_duration = 150
1618
# which GET params Clink should update

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::time::Duration;
1515
#[derive(Serialize, Deserialize, Debug)]
1616
pub struct ClinkConfig {
1717
mode: Mode,
18+
your_mom: String,
1819
sleep_duration: u64,
1920
params: Vec<String>,
2021
}
@@ -23,6 +24,7 @@ impl ::std::default::Default for ClinkConfig {
2324
fn default() -> Self {
2425
Self {
2526
mode: Mode::Remove,
27+
your_mom: "your_mom".to_string(),
2628
params: get_default_params(),
2729
sleep_duration: 150,
2830
}

src/utils.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mod find_and_replace {
1717
"https://test.test/?fbclid=dsadsa&utm_source=fafa&utm_campaign=fafas&utm_medium=adsa",
1818
&ClinkConfig {
1919
mode: Mode::Remove,
20+
your_mom: "your_mom".to_string(),
2021
sleep_duration: 150,
2122
params: get_default_params(),
2223
}
@@ -28,6 +29,7 @@ mod find_and_replace {
2829
"https://test.test/?fbclid=dsadsa&utm_source=fafa&utm_campaign=fafas&utm_medium=adsa",
2930
&ClinkConfig {
3031
mode: Mode::YourMom,
32+
your_mom: "your_mom".to_string(),
3133
sleep_duration: 150,
3234
params: get_default_params()
3335
}
@@ -39,6 +41,7 @@ mod find_and_replace {
3941
"https://test.test/?fbclid=IwAR3l6qn8TzOT254dIa7jBAM1dG3OHn3f8ZoRGsADTmqG1Zfmmko-oRhE8Qs&utm_source=IwAR3l6qn8TzOT254dIa7jBAM1dG3OHn3f8ZoRGsADTmqG1Zfmmko-oRhE8Qs&utm_campaign=IwAR3l6qn8TzOT254dIa7jBAM1dG3OHn3f8ZoRGsADTmqG1Zfmmko-oRhE8Qs&utm_medium=IwAR3l6qn8TzOT254dIa7jBAM1dG3OHn3f8ZoRGsADTmqG1Zfmmko-oRhE8Qs",
4042
&ClinkConfig {
4143
mode: Mode::Evil,
44+
your_mom: "your_mom".to_string(),
4245
sleep_duration: 150,
4346
params: get_default_params()
4447
}
@@ -53,6 +56,7 @@ mod find_and_replace {
5356
"https://test.test/?abc=abc",
5457
&ClinkConfig {
5558
mode: Mode::Remove,
59+
your_mom: "your_mom".to_string(),
5660
sleep_duration: 150,
5761
params: get_default_params()
5862
}
@@ -64,6 +68,7 @@ mod find_and_replace {
6468
"https://test.test/?abc=abc",
6569
&ClinkConfig {
6670
mode: Mode::YourMom,
71+
your_mom: "your_mom".to_string(),
6772
sleep_duration: 150,
6873
params: get_default_params()
6974
}
@@ -78,6 +83,7 @@ mod find_and_replace {
7883
"https://test.test/?abc=abc&fbclid=flksj",
7984
&ClinkConfig {
8085
mode: Mode::Remove,
86+
your_mom: "your_mom".to_string(),
8187
sleep_duration: 150,
8288
params: get_default_params()
8389
}
@@ -89,6 +95,7 @@ mod find_and_replace {
8995
"https://test.test/?abc=abc&fbclid=flksj",
9096
&ClinkConfig {
9197
mode: Mode::YourMom,
98+
your_mom: "your_mom".to_string(),
9299
sleep_duration: 150,
93100
params: get_default_params()
94101
}
@@ -103,6 +110,7 @@ mod find_and_replace {
103110
"https://test.test/?abc=abc&fbclid=flksj\nhttps://test.test/?abc=abc&fbclid=flksj",
104111
&ClinkConfig {
105112
mode: Mode::Remove,
113+
your_mom: "your_mom".to_string(),
106114
sleep_duration: 150,
107115
params: get_default_params()
108116
}
@@ -114,6 +122,7 @@ mod find_and_replace {
114122
"https://test.test/?abc=abc&fbclid=flksj\nhttps://test.test/?abc=abc&fbclid=flksj",
115123
&ClinkConfig {
116124
mode: Mode::YourMom,
125+
your_mom: "your_mom".to_string(),
117126
sleep_duration: 150,
118127
params: get_default_params()
119128
}
@@ -128,6 +137,7 @@ mod find_and_replace {
128137
"some text here https://test.test/?abc=abc&fbclid=flksj here \nand herehttps://test.test/?abc=abc&fbclid=flksj",
129138
& ClinkConfig {
130139
mode: Mode::Remove,
140+
your_mom: "your_mom".to_string(),
131141
sleep_duration: 150,
132142
params: get_default_params()
133143
}
@@ -139,13 +149,45 @@ mod find_and_replace {
139149
"some text here https://test.test/?abc=abc&fbclid=flksj here \nand herehttps://test.test/?abc=abc&fbclid=flksj",
140150
&ClinkConfig {
141151
mode: Mode::YourMom,
152+
your_mom: "your_mom".to_string(),
142153
sleep_duration: 150,
143154
params: get_default_params()
144155
}
145156
),
146157
"some text here https://test.test/?abc=abc&fbclid=your_mom here \nand herehttps://test.test/?abc=abc&fbclid=your_mom"
147158
);
148159
}
160+
#[test]
161+
fn custom_text_for_your_mom_mode() {
162+
assert_eq!(
163+
find_and_replace(
164+
"https://test.test/?fbclid=dsadsa&utm_source=fafa&utm_campaign=fafas&utm_medium=adsa",
165+
&ClinkConfig {
166+
mode: Mode::YourMom,
167+
your_mom: "foo".to_string(),
168+
sleep_duration: 150,
169+
params: get_default_params()
170+
}
171+
),
172+
"https://test.test/?fbclid=foo&utm_source=foo&utm_campaign=foo&utm_medium=foo"
173+
);
174+
}
175+
176+
#[test]
177+
fn custom_params() {
178+
assert_eq!(
179+
find_and_replace(
180+
"https://test.test/?foo=dsadsa",
181+
&ClinkConfig {
182+
mode: Mode::YourMom,
183+
your_mom: "your_mom".to_string(),
184+
sleep_duration: 150,
185+
params: vec!["foo".to_string()]
186+
}
187+
),
188+
"https://test.test/?foo=your_mom"
189+
);
190+
}
149191
}
150192

151193
pub fn find_and_replace(str: &str, config: &ClinkConfig) -> String {
@@ -184,7 +226,7 @@ fn process_query(
184226
Mode::YourMom => query
185227
.map(|p| {
186228
if is_hit(&p.0, &index) {
187-
(p.0.to_string(), "your_mom".to_string())
229+
(p.0.to_string(), config.your_mom.clone())
188230
} else {
189231
(p.0.to_string(), p.1.to_string())
190232
}

0 commit comments

Comments
 (0)