aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsmege1001 <smege1001@aaathats3as.com>2020-08-04 03:37:43 +0100
committersmege1001 <smege1001@aaathats3as.com>2020-08-04 03:37:43 +0100
commita729590ff013edda3f1c0b4c99c7c8dcf36b8717 (patch)
treeca341381451394ef2482eeec4c3e7d851f084e95
parentf6d4fe7e71d05296ba8bb4613853b61369a2fc31 (diff)
downloadcloudflare-tor-a729590ff013edda3f1c0b4c99c7c8dcf36b8717.tar.lz
cloudflare-tor-a729590ff013edda3f1c0b4c99c7c8dcf36b8717.tar.xz
cloudflare-tor-a729590ff013edda3f1c0b4c99c7c8dcf36b8717.zip
not the 1000th commit
m---------tool/cf_email_decoder6
-rw-r--r--tool/cfemail.user.js64
2 files changed, 64 insertions, 6 deletions
diff --git a/tool/cf_email_decoder b/tool/cf_email_decoder
deleted file mode 160000
-Subproject a7fabb1837b55f6b7514d0f7a1587671539033a
diff --git a/tool/cfemail.user.js b/tool/cfemail.user.js
new file mode 100644
index 00000000..673f898f
--- /dev/null
+++ b/tool/cfemail.user.js
@@ -0,0 +1,64 @@
+// ==UserScript==
+// @name Decode Cloudflare-encoded email addresses
+// @namespace https://codeberg.org/smege1001/cf_email_decoder
+// @match *://*/*
+// @grant none
+// @version 1.2.2
+// @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];
+ var decodedEmail = decodeEmail(hash);
+
+ link.href = "mailto:" + decodedEmail; //replace the stupid email protection with just a mailto link
+
+ if (link.getElementsByClassName("__cf_email__").length > 0) {
+ var linkChild = link.getElementsByClassName("__cf_email__")[0];
+ linkChild.innerText = decodedEmail;
+
+ linkChild.removeAttribute("data-cfemail");
+ linkChild.classList.remove("__cf_email__");
+
+ if (linkChild.getAttribute("class") == "") linkChild.removeAttribute("class");
+ }
+ } 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");
+ }
+}