From 6ba324659804d26027d3227ddcb0a2092952bf5f Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Sat, 10 Oct 2020 13:47:31 -0400 Subject: [PATCH] Fix all the "[email protected]" instances I somehow thought there were only two, but in fact there are a lot. --- lib/convert.js | 17 +++++++++++++++++ lib/substitutions.json | 10 ---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/convert.js b/lib/convert.js index 07c4919..29c49f8 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -122,6 +122,12 @@ function getBodyXML(chapter, contentEl) { } }); + // In Ward, CloudFlare email protection obfuscates the email addresses: + // https://usamaejaz.com/cloudflare-email-decoding/ + for (const emailEl of contentEl.querySelectorAll("[data-cfemail]")) { + const decoded = decodeCloudFlareEmail(emailEl.dataset.cfemail); + emailEl.replaceWith(contentEl.ownerDocument.createTextNode(decoded)); + } // Synthesize a tag to serialize const bodyEl = contentEl.ownerDocument.createElement("body"); @@ -393,3 +399,14 @@ function isEmptyOrGarbage(el) { function escapeRegExp(str) { return str.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&"); } + +function decodeCloudFlareEmail(hash) { + let email = ""; + const xorWithThis = parseInt(hash.substring(0, 2), 16); + for (let i = 2; i < hash.length; i += 2) { + const charCode = parseInt(hash.substring(i, i + 2), 16) ^ xorWithThis; + email += String.fromCharCode(charCode); + } + + return email; +} diff --git a/lib/substitutions.json b/lib/substitutions.json index b45d7cf..42e7f68 100644 --- a/lib/substitutions.json +++ b/lib/substitutions.json @@ -4121,16 +4121,6 @@ "before": "

Ward is the second work in the Parahumans series, and reading Worm first is strongly recommended. A lot of this won’t make sense otherwise and if you do find yourself a fan of the universe, the spoilers in Ward will affect the reading of the other work.

\n

Ward is not recommended for young or sensitive readers.

\n
", "after": "", "_comment": "This is out of place in an eBook." - }, - { - "before": "[email protected]", - "after": "Deferent.I@Mail", - "_comment": "These protected emails occur only twice in the entire book so we just hard-code it here instead of using techniques like https://usamaejaz.com/cloudflare-email-decoding/" - }, - { - "before": "[email protected]", - "after": "Deferent.I@Mail", - "_comment": "These protected emails occur only twice in the entire book so we just hard-code it here instead of using techniques like https://usamaejaz.com/cloudflare-email-decoding/" } ], "https://www.parahumans.net/2017/11/21/daybreak-1-4/": [