-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembed-script.js
More file actions
29 lines (24 loc) · 765 Bytes
/
Copy pathembed-script.js
File metadata and controls
29 lines (24 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class EmailObfuscator extends HTMLElement {
static observedAttributes = ["obfuscated"];
constructor() {
super();
}
// Called whenever an observed attribute changes
attributeChangedCallback(name, oldValue, newValue) {
if (name === "obfuscated" && newValue) {
this.renderEmail(newValue);
}
}
renderEmail(encodedEmail) {
this.innerHTML = ""; // Clear the current content
// Decode the email from base64
const a = atob(encodedEmail.split("?").reverse().join("")),
b = document.createElement("a");
b.innerText = a;
b.href = "mailto:" + a;
// Append the anchor to this custom element
this.appendChild(b);
}
}
// Define the custom element
customElements.define("obfuscated-email", EmailObfuscator);