From 5150b794927ba2ee370fca044ed90f771636828e Mon Sep 17 00:00:00 2001 From: smege1001 Date: Fri, 31 Jul 2020 20:22:16 +0200 Subject: [PATCH 1/2] Delete 'tool/userscript.cf_email_decoder.js' --- tool/userscript.cf_email_decoder.js | 64 ----------------------------- 1 file changed, 64 deletions(-) delete mode 100644 tool/userscript.cf_email_decoder.js diff --git a/tool/userscript.cf_email_decoder.js b/tool/userscript.cf_email_decoder.js deleted file mode 100644 index b4678b83e..000000000 --- a/tool/userscript.cf_email_decoder.js +++ /dev/null @@ -1,64 +0,0 @@ -// ==UserScript== -// @name Decode Cloudflare-encoded email addresses -// @namespace https://codeberg.org/smege1001/cf_email_decoder -// @match *://*/* -// @grant none -// @version 1.1 -// @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__")) { - 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"); - } -} From 2f078b282152e9e510cac807bdc92a97ff448a39 Mon Sep 17 00:00:00 2001 From: smege1001 Date: Fri, 31 Jul 2020 19:46:50 +0100 Subject: [PATCH 2/2] replace the cfemail userscript with a submodule --- .gitmodules | 3 +++ tool/cf_email_decoder | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 tool/cf_email_decoder diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..2524803cd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tool/cf_email_decoder"] + path = tool/cf_email_decoder + url = https://codeberg.org/smege1001/cf_email_decoder.git diff --git a/tool/cf_email_decoder b/tool/cf_email_decoder new file mode 160000 index 000000000..a7fabb183 --- /dev/null +++ b/tool/cf_email_decoder @@ -0,0 +1 @@ +Subproject commit a7fabb1837b55f6b7514d0f7a1587671539033a6