diff options
author | Corona <corona@noreply.codeberg.org> | 2020-07-31 01:30:52 +0200 |
---|---|---|
committer | Corona <corona@noreply.codeberg.org> | 2020-07-31 01:30:52 +0200 |
commit | 069b41e669c42d09e2ecdf385ad981b9f4c246bb (patch) | |
tree | e0f0b7eaca8e022be136a224e4840e0a87f1eb81 /tool/userscript.cf_email_decoder.js | |
parent | ad5a95bb42d7f9369a5aafbe11510f542b861a6f (diff) | |
parent | 77f221130e5e87d72683e624ae4f8494515c321c (diff) | |
download | cloudflare-tor-069b41e669c42d09e2ecdf385ad981b9f4c246bb.tar.lz cloudflare-tor-069b41e669c42d09e2ecdf385ad981b9f4c246bb.tar.xz cloudflare-tor-069b41e669c42d09e2ecdf385ad981b9f4c246bb.zip |
PR 60
Diffstat (limited to 'tool/userscript.cf_email_decoder.js')
-rw-r--r-- | tool/userscript.cf_email_decoder.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tool/userscript.cf_email_decoder.js b/tool/userscript.cf_email_decoder.js new file mode 100644 index 00000000..da90432d --- /dev/null +++ b/tool/userscript.cf_email_decoder.js @@ -0,0 +1,52 @@ +// ==UserScript== +// @name Decode Cloudflare-encoded email addresses +// @original https://codeberg.org/smege1001/cf_email_decoder +// @match *://*/* +// @grant none +// @version 1.0 +// @author smege1001 +// ==/UserScript== + +/** +* @license CC0-1.0 +**/ + +const emailprotectionURLHashRegex = /\/cdn-cgi\/l\/email-protection#([aA0-fF9]*)/; +const emailprotectionURLNoHashRegex = /\/cdn-cgi\/l\/email-protection/; //hash is stored on data-cfemail + +function decodeEmail(hash) { //cloudflare email address decoder + var hashArray = []; //split the hash into bytes + for (var hAIndex = 0; hAIndex < hash.length; hAIndex += 2) { + hashArray.push(parseInt(hash.substring(hAIndex, hAIndex + 2), 16)); + } + + var decoded = ""; + var key = hashArray[0]; //get the decode key + + for (var index = 1; index < hashArray.length; index++) { + decoded += String.fromCharCode(hashArray[index] ^ key); + } + return decoded; +} + +var links = document.querySelectorAll("a"); //get all the links + +for (var linksIndex = 0; linksIndex < links.length; linksIndex++) { + var link = links[linksIndex]; + if (emailprotectionURLHashRegex.test(link.href)) { + var hash = link.href.match(emailprotectionURLHashRegex)[1]; + link.href = "mailto:" + decodeEmail(hash); //replace the stupid email protection with just a mailto link + } else if (emailprotectionURLNoHashRegex.test(link.href) && link.hasAttribute("data-cfemail")) { + var hash = link.getAttribute("data-cfemail"); + var decodedEmail = decodeEmail(hash); + + link.href = "mailto:" + decodedEmail; + link.innerText = decodedEmail; //the inner text is just [email protected] + + //remove the useless attributes + link.removeAttribute("data-cfemail"); + link.classList.remove("__cf_email__"); + + if (link.getAttribute("class") == "") link.removeAttribute("class"); + } +} |