-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdecrypt.emails.js
More file actions
29 lines (26 loc) · 832 Bytes
/
decrypt.emails.js
File metadata and controls
29 lines (26 loc) · 832 Bytes
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
const selector = 'a[href="/cdn-cgi/l/email-protection"]';
function hexAt(str = '', index = 0) {
const r = str.substring(index, index + 2);
return parseInt(r, 16);
}
function decrypt(ciphertext) {
let output = '';
const key = hexAt(ciphertext, 0);
for (let i = 2; i < ciphertext.length; i += 2) {
const plaintext = hexAt(ciphertext, i) ^ key;
output += String.fromCharCode(plaintext);
}
return decodeURIComponent(escape(output));
}
export default function decode(doc) {
if (typeof jQuery === 'function' && doc instanceof jQuery) {
doc.find(selector).replaceWith(function decryption() {
return decrypt(this.dataset.cfemail);
});
} else {
[...doc.querySelectorAll(selector)].forEach(function decryption(el) {
el.replaceWith(decrypt(el.dataset.cfemail));
});
}
return doc;
}