From fb021e2cf43da42bfef11ebaa781388f1bb7613f Mon Sep 17 00:00:00 2001 From: V Date: Fri, 14 Aug 2020 23:43:30 +0200 Subject: Initial release (from .xpi) --- content.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ icon.svg | 4 ++++ manifest.json | 21 +++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 content.js create mode 100644 icon.svg create mode 100644 manifest.json diff --git a/content.js b/content.js new file mode 100644 index 0000000..2329ae5 --- /dev/null +++ b/content.js @@ -0,0 +1,52 @@ +// shibboleth. decodes UTF-8 with an unholy combination of specific behaviour +// https://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html +function decodeUtf8(str) { + return decodeURIComponent(escape(str)) +} + +// decodes a string containing HTML entities +function decodeHtml(str) { + let doc = new DOMParser().parseFromString(str, 'text/html') + return doc.documentElement.textContent +} + +// decodes a "protected" "email" +function decode(data) { + const [key, ...encoded] = data.match(/.{2}/g).map(e => parseInt(e, 16)) + let bytes = encoded.map(e => String.fromCharCode(e ^ key)).join("") + + // not sure why the proprietary code decodes entities, but I'm not changing it + return decodeHtml(decodeUtf8(bytes)) +} + +// processes a document fragment for "protected" "emails" +function process(root) { + // mailto links + // format: ... + for (const node of root.querySelectorAll('a')) { + const url = new URL(node.href) + if (url.pathname === '/cdn-cgi/l/email-protection' && url.hash !== '') + node.href = `mailto:${decode(url.hash.slice(1))}` + } + + // everything else Cloudflare thinks is an email + // format: [email protected] + for (const node of root.querySelectorAll('.__cf_email__')) + node.replaceWith(decode(node.getAttribute('data-cfemail'))) + + //