Skip to content

Instantly share code, notes, and snippets.

@devsnek
Last active March 1, 2019 23:54
Show Gist options
  • Save devsnek/df9b6213dc75d5708218b96a1285141b to your computer and use it in GitHub Desktop.
Save devsnek/df9b6213dc75d5708218b96a1285141b to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
'use strict';
/**
* Usage:
* `require('./cloudflare_email_scrape')('d1bcb491b6a4a2ffb9bea2a5')`
* `curl -s https://gus.host | ./cloudflare_email_scrape.js`
* `./cloudflare_email_scrape d1bcb491b6a4a2ffb9bea2a5 ...`
*/
function parseHash(hash) {
const mask = parseInt(hash.substr(0, 2), 16);
let final = '';
for (let i = 2; i < hash.length && hash.charAt(i) !== 'X'; i += 2) {
final += String.fromCharCode(parseInt(hash.substr(i, 2), 16) ^ mask);
}
return final;
}
const RE = /data-cfemail="(.+?)"/g;
if (require.main === module) {
if (process.argv.length > 2) {
process.stdout.write(JSON.stringify(process.argv.slice(2).map((h) => parseHash(h))));
} else {
let body = '';
process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
body += chunk;
}
});
process.stdin.on('end', () => {
const emails = [];
let match;
while (true) {
match = RE.exec(body);
if (!match) {
break;
}
emails.push(parseHash(match[1]));
}
process.stdout.write(JSON.stringify(emails, null, 2));
});
}
}
module.exports = parseHash;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment