Files
RSSHub/lib/routes/sciencedirect/cf-email.ts
T
Tony 1acb805799 style: migrate eslint to oxlint (#21224)
* chore: add oxlint support

* style: apply autofix

* style: apply autofix for toSorted

* style: use alternative api for nsfw-flag jsPlugins

* fix: git diff

* fix: codeql

* test: console.log

* style: update lint workflow to use Checkstyle SARIF converter

* style: remove debug log from extractDateFromURL function

* chore: use oxlint-json-to-sarif

* test: console.log

* test: remove console.log

* test: update cookie data expectation in getCookies test

https://github.com/mccutchen/go-httpbin/pull/235 breaks this

* style: type-aware linting

* style: enable type-aware linting for oxlint
2026-02-28 21:23:11 +08:00

40 lines
1.3 KiB
TypeScript

/* eslint-disable unicorn/prefer-code-point */
const decodeCFEmail = (encoded) => {
const parseHex = (string, position) => Number.parseInt(string.slice(position, position + 2), 16);
let decoded = '';
const key = parseHex(encoded, 0);
for (let position = 2; position < encoded.length; position += 2) {
const byte = parseHex(encoded, position) ^ key;
decoded += String.fromCharCode(byte);
}
return decoded;
};
const encodeCFEmail = (email) => {
const key = Math.floor(Math.random() * 256);
let encoded = ('0' + key.toString(16)).slice(-2);
for (let position = 0; position < email.length; position++) {
const byte = email.charCodeAt(position) ^ key;
encoded += ('0' + byte.toString(16)).slice(-2);
}
return encoded;
};
/**
* The alogrithm is well-explained in https://andrewlock.net/simple-obfuscation-of-email-addresses-using-javascript/
*/
export {
/**
* Returns decoded email address using CloudFlare's email address obfuscation.
* @param {String} encoded - encoded email, (`cfemail` attribute in `__cf_email__` tag)
* @returns decoded email address
*/
decodeCFEmail,
/**
* Returns CloudFlare protected email address.
* @param {String} email - email in plaintext
* @returns obfuscated email
*/
encodeCFEmail,
};