Skip to content

Commit 4ea894a

Browse files
authored
Update jep.js
1 parent 17d4be7 commit 4ea894a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

jep.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
/* jep.js - JavaScript Email Protection (JEP) */
2-
31
function jep_link(domain, user) {
4-
// Create email string
5-
let email = `${user}@${domain}`;
6-
7-
// Obfuscate each character using HTML entity codes
8-
let encodedEmail = "";
9-
let encode = str => [...str].map(c => `&#${c.charCodeAt(0)};`).join('');
2+
const email = `${user}@${domain}`;
3+
const mailto = `mailto:${email}`;
4+
5+
const encode = str => [...str].map(c => `&#${c.charCodeAt(0)};`).join('');
6+
7+
const a = document.createElement("a");
8+
a.setAttribute("href", encode(mailto));
9+
a.innerHTML = encode(email);
1010

11-
// Insert the obfuscated email link into the DOM
12-
document.write(`<a href="${encode(mailto)}">${encode(email)}</a>`);
11+
// Append to a target container (like the calling script's parent)
12+
const scriptEl = document.currentScript;
13+
scriptEl.parentNode.insertBefore(a, scriptEl.nextSibling);
1314
}

0 commit comments

Comments
 (0)