aidoku/helpers/
cfemail.rs1use crate::imports::html::Element;
3
4extern crate alloc;
5use alloc::string::String;
6
7pub fn parse_cfemail<T: AsRef<str>>(data: T) -> String {
18 let data = data.as_ref();
19 if let Ok(key) = u32::from_str_radix(&data[0..2], 16) {
20 let mut email = String::with_capacity(data.len() / 2 - 1);
21 let mut n = 2;
22
23 while n < data.len() {
24 if let Ok(chrcode) = u32::from_str_radix(&data[n..n + 2], 16) {
25 let chrcode = chrcode ^ key;
26 email.push(char::from_u32(chrcode).unwrap_or_default());
27 }
28 n += 2;
29 }
30 email
31 } else {
32 "[email protected]".into()
33 }
34}
35
36pub fn decode_cfemail(html: &Element) {
38 let Some(elements) = html.select(".__cf_email__") else {
39 return;
40 };
41 for mut elem in elements {
42 let email = parse_cfemail(elem.attr("data-cfemail").unwrap_or_default());
43 elem.set_text(email).ok();
44 }
45}