// 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) { const doc = new DOMParser().parseFromString(str, 'text/html') return doc.documentElement.textContent } // decodes an obfuscated e-mail function decode(data) { const [key, ...encoded] = data.match(/.{2}/g).map(e => parseInt(e, 16)) const 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 obfuscated e-mails function process(root) { // mailto links // format: ... for (const node of root.querySelectorAll('a')) { try { const url = new URL(node.href) if (url.pathname === '/cdn-cgi/l/email-protection' && url.hash !== '') node.href = `mailto:${decode(url.hash.slice(1))}` } catch { // either there wasn't an href, or it wasn't a valid URL } } // everything else Cloudflare thinks is an e-mail // format: [email protected] for (const node of root.querySelectorAll('.__cf_email__')) node.replaceWith(decode(node.getAttribute('data-cfemail'))) //