diff --git a/README.md b/README.md index 0b4da7f..4915fc3 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,6 @@ mailgo will substitute all the `mailto:` links with the **mailgo modal**, in les add at the end of the `` -``` - -... - - -``` - -or - ``` ... @@ -33,21 +24,12 @@ or ``` -or download the script here and - -``` - -... - - -``` - you can also import mailgo in `` using `defer` ``` ... - + ``` diff --git a/src/mailgo.js b/src/mailgo.js index 1c5295f..2285cd8 100644 --- a/src/mailgo.js +++ b/src/mailgo.js @@ -156,7 +156,17 @@ mailgoInit = () => { // open default let open = document.createElement("a"); - open.href = mailtoHref; + + open.href = "#mailgo-open"; + let encEmail = encryptEmail(mail); + open.addEventListener( + "click", + () => { + mailToEncoded(encEmail); + }, + false + ); + open.classList.add("mailgo-open"); open.classList.add("mailgo-weight-500"); let openContent = document.createTextNode("open"); @@ -248,3 +258,14 @@ copyToClipboard = str => { document.getSelection().addRange(selected); } }; + +// decrypt email +function mailToEncoded(encoded) { + var address = atob(encoded); + window.location.href = "mailto:" + address; +} + +// encrypt email +function encryptEmail(email) { + return btoa(email); +}