diff --git a/dist/mailgo.js b/dist/mailgo.js
index 2ca64fc..a1a7581 100644
--- a/dist/mailgo.js
+++ b/dist/mailgo.js
@@ -218,21 +218,21 @@ mailgoRender = mailgo => {
// validate the email address
if (!validateEmail(mail)) return;
- titleEl = document.getElementById("mailgo-title");
- detailsEl = document.getElementById("mailgo-details");
- ccEl = document.getElementById("mailgo-cc");
- ccValueEl = document.getElementById("mailgo-cc-value");
- bccEl = document.getElementById("mailgo-bcc");
- bccValueEl = document.getElementById("mailgo-bcc-value");
- subjectEl = document.getElementById("mailgo-subject");
- subjectValueEl = document.getElementById("mailgo-subject-value");
- bodyEl = document.getElementById("mailgo-body");
- bodyValueEl = document.getElementById("mailgo-body-value");
+ titleEl = getE("mailgo-title");
+ detailsEl = getE("mailgo-details");
+ ccEl = getE("mailgo-cc");
+ ccValueEl = getE("mailgo-cc-value");
+ bccEl = getE("mailgo-bcc");
+ bccValueEl = getE("mailgo-bcc-value");
+ subjectEl = getE("mailgo-subject");
+ subjectValueEl = getE("mailgo-subject-value");
+ bodyEl = getE("mailgo-body");
+ bodyValueEl = getE("mailgo-body-value");
- gmailButton = document.getElementById("mailgo-gmail");
- outlookButton = document.getElementById("mailgo-outlook");
- openButton = document.getElementById("mailgo-open");
- copyButton = document.getElementById("mailgo-copy");
+ gmailButton = getE("mailgo-gmail");
+ outlookButton = getE("mailgo-outlook");
+ openButton = getE("mailgo-open");
+ copyButton = getE("mailgo-copy");
titleEl.textContent = mail;
@@ -285,7 +285,7 @@ mailgoCheckRender = event => {
console.log(e);
// check if the id=mailgo exists in the body
- if (!document.body.contains(document.getElementById("mailgo"))) return;
+ if (!document.body.contains(getE("mailgo"))) return;
if (
// first case: it is an element with "mailto:..." in href and no no-mailgo in classList
@@ -293,7 +293,8 @@ mailgoCheckRender = event => {
e.href.toLowerCase().startsWith(MAILTO) &&
!e.classList.contains("no-mailgo")) ||
// second case: the href=#mailgo
- (e.href && e.href.toLowerCase() == "#mailgo") ||
+ // TODO FIX here
+ (e.href && e.href.toLowerCase() === "#mailgo") ||
//third case: the classList contains mailgo
e.classList.contains("mailgo")
) {
@@ -339,13 +340,16 @@ copyToClipboard = str => {
};
// show the modal
-showMailgo = () => (document.getElementById("mailgo").style.display = "flex");
+showMailgo = () => (getE("mailgo").style.display = "flex");
// hide the modal
-hideMailgo = () => (document.getElementById("mailgo").style.display = "none");
+hideMailgo = () => (getE("mailgo").style.display = "none");
// decrypt email
mailToEncoded = encoded => (window.location.href = MAILTO + atob(encoded));
// encode email
encodeEmail = email => btoa(email);
+
+// getE shorthand
+getE = id => document.getElementById(id);
diff --git a/dist/mailgo.min.js b/dist/mailgo.min.js
index c0a03d5..088a55a 100644
--- a/dist/mailgo.min.js
+++ b/dist/mailgo.min.js
@@ -1 +1 @@
-const VERSION="0.3.0",MAILTO="mailto:",styleSheet=document.createElement("link");styleSheet.rel="stylesheet",styleSheet.type="text/css",styleSheet.href="https://unpkg.com/mailgo@0.3.0/dist/mailgo.min.css",document.head.appendChild(styleSheet),mailgoInit=(()=>{let e=document.createElement("div");e.id="mailgo",e.classList.add("mailgo-modal"),e.style.display="none";let t=document.createElement("div");t.className="mailgo-modal-background",e.appendChild(t);let l=document.createElement("div");l.className="mailgo-modal-content",e.appendChild(l);let o=document.createElement("strong");o.id="mailgo-title",o.className="mailgo-title",l.appendChild(o);let a=document.createElement("div");a.id="mailgo-details",a.className="mailgo-details";let d=document.createElement("p");d.id="mailgo-cc";let n=document.createElement("span");n.className="mailgo-weight-500";let c=document.createTextNode("cc ");n.appendChild(c);let i=document.createElement("span");i.id="mailgo-cc-value",d.appendChild(n),d.appendChild(i),a.appendChild(d);let m=document.createElement("p");m.id="mailgo-bcc";let s=document.createElement("span");s.className="mailgo-weight-500";let p=document.createTextNode("bcc ");s.appendChild(p);let u=document.createElement("span");u.id="mailgo-bcc-value",m.appendChild(s),m.appendChild(u),a.appendChild(m);let g=document.createElement("p");g.id="mailgo-subject";let r=document.createElement("span");r.className="mailgo-weight-500";let h=document.createTextNode("subject");r.appendChild(h);let E=document.createElement("span");E.id="mailgo-subject-value",g.appendChild(r),g.appendChild(E),a.appendChild(g);let y=document.createElement("p");y.id="mailgo-body";let C=document.createElement("span");C.className="mailgo-weight-500";let b=document.createTextNode("body ");C.appendChild(b);let I=document.createElement("span");I.id="mailgo-body-value",y.appendChild(C),y.appendChild(I),a.appendChild(y),l.appendChild(a);let L=document.createElement("a");L.id="mailgo-gmail",L.classList.add("mailgo-open"),L.classList.add("gmail");let B=document.createTextNode("open in ");L.appendChild(B);let v=document.createElement("span");v.className="mailgo-weight-500";let x=document.createTextNode("Gmail");v.appendChild(x),L.appendChild(v),l.appendChild(L);let N=document.createElement("a");N.id="mailgo-outlook",N.classList.add("mailgo-open"),N.classList.add("outlook");let f=document.createTextNode("open in ");N.appendChild(f);let T=document.createElement("span");T.className="mailgo-weight-500";let w=document.createTextNode("Outlook");T.appendChild(w),N.appendChild(T),l.appendChild(N);let k=document.createElement("a");k.id="mailgo-open",k.href="#mailgo-open",k.classList.add("mailgo-open"),k.classList.add("mailgo-weight-500");let R=document.createTextNode("open");k.appendChild(R),l.appendChild(k);let A=document.createElement("a");A.id="mailgo-copy",A.href="#mailgo-copy",A.classList.add("mailgo-copy"),A.classList.add("mailgo-weight-500");let j=document.createTextNode("copy");A.appendChild(j),l.appendChild(A);let M=document.createElement("a");M.href="https://mailgo.js.org",M.className="mailgo-by",M.target="_blank";let S=document.createTextNode("mailgo.js.org");M.appendChild(S),l.appendChild(M),document.body.appendChild(e),mailgo.addEventListener("keydown",e=>{27===e.keyCode&&hideMailgo()},!1),t.addEventListener("click",e=>{hideMailgo()},!1)}),mailgoRender=(e=>{let t="",l="",o="",a="",d="",n="";if(e.href&&e.href.toLowerCase().startsWith(MAILTO)){t=decodeURIComponent(e.href.split("?")[0].split(MAILTO)[1].trim()),l=e.href,url=new URL(l);let c=new URLSearchParams(url.search);o=c.get("cc"),a=c.get("bcc"),d=c.get("subject"),n=c.get("body")}else t=e.getAttribute("data-address")+"@"+e.getAttribute("data-domain"),l=MAILTO+encodeURIComponent(t),url=new URL(l);if(!validateEmail(t))return;titleEl=document.getElementById("mailgo-title"),detailsEl=document.getElementById("mailgo-details"),ccEl=document.getElementById("mailgo-cc"),ccValueEl=document.getElementById("mailgo-cc-value"),bccEl=document.getElementById("mailgo-bcc"),bccValueEl=document.getElementById("mailgo-bcc-value"),subjectEl=document.getElementById("mailgo-subject"),subjectValueEl=document.getElementById("mailgo-subject-value"),bodyEl=document.getElementById("mailgo-body"),bodyValueEl=document.getElementById("mailgo-body-value"),gmailButton=document.getElementById("mailgo-gmail"),outlookButton=document.getElementById("mailgo-outlook"),openButton=document.getElementById("mailgo-open"),copyButton=document.getElementById("mailgo-copy"),titleEl.textContent=t,o?ccValueEl.textContent=o:ccEl.style.display="none",a?bccValueEl.textContent=a:bccEl.style.display="none",d?subjectValueEl.textContent=d:subjectEl.style.display="none",n?bodyValueEl.textContent=n:bodyEl.style.display="none",gmailButton.href="https://mail.google.com/mail?extsrc=mailto&url="+encodeURIComponent(l),outlookButton.href="https://outlook.office.com/owa/?rru=compose&to="+encodeURIComponent(t)+url.search.replace(/^[$]/,"&");let c=encodeEmail(t);openButton.addEventListener("click",()=>{mailToEncoded(c)},!1),copyButton.addEventListener("click",e=>{copyToClipboard(t),copyButton.textContent="copied",setTimeout(()=>{copyButton.textContent="copy"},999)},!1),showMailgo()}),mailgoCheckRender=(e=>{let t=e.target;console.log(t),document.body.contains(document.getElementById("mailgo"))&&(t.href&&t.href.toLowerCase().startsWith(MAILTO)&&!t.classList.contains("no-mailgo")||t.href&&"#mailgo"==t.href.toLowerCase()||t.classList.contains("mailgo"))&&(e.preventDefault(),mailgoRender(t))}),document.addEventListener("DOMContentLoaded",mailgoInit,!1),document.addEventListener("click",mailgoCheckRender,!1),validateEmail=(e=>{return/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)}),copyToClipboard=(e=>{const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t);const l=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),l&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(l))}),showMailgo=(()=>document.getElementById("mailgo").style.display="flex"),hideMailgo=(()=>document.getElementById("mailgo").style.display="none"),mailToEncoded=(e=>window.location.href=MAILTO+atob(e)),encodeEmail=(e=>btoa(e));
\ No newline at end of file
+const VERSION="0.3.0",MAILTO="mailto:",styleSheet=document.createElement("link");styleSheet.rel="stylesheet",styleSheet.type="text/css",styleSheet.href="https://unpkg.com/mailgo@0.3.0/dist/mailgo.min.css",document.head.appendChild(styleSheet),mailgoInit=(()=>{let e=document.createElement("div");e.id="mailgo",e.classList.add("mailgo-modal"),e.style.display="none";let t=document.createElement("div");t.className="mailgo-modal-background",e.appendChild(t);let l=document.createElement("div");l.className="mailgo-modal-content",e.appendChild(l);let a=document.createElement("strong");a.id="mailgo-title",a.className="mailgo-title",l.appendChild(a);let o=document.createElement("div");o.id="mailgo-details",o.className="mailgo-details";let d=document.createElement("p");d.id="mailgo-cc";let n=document.createElement("span");n.className="mailgo-weight-500";let i=document.createTextNode("cc ");n.appendChild(i);let c=document.createElement("span");c.id="mailgo-cc-value",d.appendChild(n),d.appendChild(c),o.appendChild(d);let m=document.createElement("p");m.id="mailgo-bcc";let s=document.createElement("span");s.className="mailgo-weight-500";let p=document.createTextNode("bcc ");s.appendChild(p);let g=document.createElement("span");g.id="mailgo-bcc-value",m.appendChild(s),m.appendChild(g),o.appendChild(m);let u=document.createElement("p");u.id="mailgo-subject";let r=document.createElement("span");r.className="mailgo-weight-500";let h=document.createTextNode("subject");r.appendChild(h);let E=document.createElement("span");E.id="mailgo-subject-value",u.appendChild(r),u.appendChild(E),o.appendChild(u);let C=document.createElement("p");C.id="mailgo-body";let y=document.createElement("span");y.className="mailgo-weight-500";let b=document.createTextNode("body ");y.appendChild(b);let L=document.createElement("span");L.id="mailgo-body-value",C.appendChild(y),C.appendChild(L),o.appendChild(C),l.appendChild(o);let v=document.createElement("a");v.id="mailgo-gmail",v.classList.add("mailgo-open"),v.classList.add("gmail");let x=document.createTextNode("open in ");v.appendChild(x);let N=document.createElement("span");N.className="mailgo-weight-500";let f=document.createTextNode("Gmail");N.appendChild(f),v.appendChild(N),l.appendChild(v);let T=document.createElement("a");T.id="mailgo-outlook",T.classList.add("mailgo-open"),T.classList.add("outlook");let w=document.createTextNode("open in ");T.appendChild(w);let k=document.createElement("span");k.className="mailgo-weight-500";let R=document.createTextNode("Outlook");k.appendChild(R),T.appendChild(k),l.appendChild(T);let I=document.createElement("a");I.id="mailgo-open",I.href="#mailgo-open",I.classList.add("mailgo-open"),I.classList.add("mailgo-weight-500");let A=document.createTextNode("open");I.appendChild(A),l.appendChild(I);let j=document.createElement("a");j.id="mailgo-copy",j.href="#mailgo-copy",j.classList.add("mailgo-copy"),j.classList.add("mailgo-weight-500");let M=document.createTextNode("copy");j.appendChild(M),l.appendChild(j);let B=document.createElement("a");B.href="https://mailgo.js.org",B.className="mailgo-by",B.target="_blank";let S=document.createTextNode("mailgo.js.org");B.appendChild(S),l.appendChild(B),document.body.appendChild(e),mailgo.addEventListener("keydown",e=>{27===e.keyCode&&hideMailgo()},!1),t.addEventListener("click",e=>{hideMailgo()},!1)}),mailgoRender=(e=>{let t="",l="",a="",o="",d="",n="";if(e.href&&e.href.toLowerCase().startsWith(MAILTO)){t=decodeURIComponent(e.href.split("?")[0].split(MAILTO)[1].trim()),l=e.href,url=new URL(l);let i=new URLSearchParams(url.search);a=i.get("cc"),o=i.get("bcc"),d=i.get("subject"),n=i.get("body")}else t=e.getAttribute("data-address")+"@"+e.getAttribute("data-domain"),l=MAILTO+encodeURIComponent(t),url=new URL(l);if(!validateEmail(t))return;titleEl=getE("mailgo-title"),detailsEl=getE("mailgo-details"),ccEl=getE("mailgo-cc"),ccValueEl=getE("mailgo-cc-value"),bccEl=getE("mailgo-bcc"),bccValueEl=getE("mailgo-bcc-value"),subjectEl=getE("mailgo-subject"),subjectValueEl=getE("mailgo-subject-value"),bodyEl=getE("mailgo-body"),bodyValueEl=getE("mailgo-body-value"),gmailButton=getE("mailgo-gmail"),outlookButton=getE("mailgo-outlook"),openButton=getE("mailgo-open"),copyButton=getE("mailgo-copy"),titleEl.textContent=t,a?ccValueEl.textContent=a:ccEl.style.display="none",o?bccValueEl.textContent=o:bccEl.style.display="none",d?subjectValueEl.textContent=d:subjectEl.style.display="none",n?bodyValueEl.textContent=n:bodyEl.style.display="none",gmailButton.href="https://mail.google.com/mail?extsrc=mailto&url="+encodeURIComponent(l),outlookButton.href="https://outlook.office.com/owa/?rru=compose&to="+encodeURIComponent(t)+url.search.replace(/^[$]/,"&");let i=encodeEmail(t);openButton.addEventListener("click",()=>{mailToEncoded(i)},!1),copyButton.addEventListener("click",e=>{copyToClipboard(t),copyButton.textContent="copied",setTimeout(()=>{copyButton.textContent="copy"},999)},!1),showMailgo()}),mailgoCheckRender=(e=>{let t=e.target;console.log(t),document.body.contains(getE("mailgo"))&&(t.href&&t.href.toLowerCase().startsWith(MAILTO)&&!t.classList.contains("no-mailgo")||t.href&&"#mailgo"===t.href.toLowerCase()||t.classList.contains("mailgo"))&&(e.preventDefault(),mailgoRender(t))}),document.addEventListener("DOMContentLoaded",mailgoInit,!1),document.addEventListener("click",mailgoCheckRender,!1),validateEmail=(e=>{return/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)}),copyToClipboard=(e=>{const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t);const l=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),l&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(l))}),showMailgo=(()=>getE("mailgo").style.display="flex"),hideMailgo=(()=>getE("mailgo").style.display="none"),mailToEncoded=(e=>window.location.href=MAILTO+atob(e)),encodeEmail=(e=>btoa(e)),getE=(e=>document.getElementById(e));
\ No newline at end of file
diff --git a/src/mailgo.js b/src/mailgo.js
index 9a874cd..f717f04 100644
--- a/src/mailgo.js
+++ b/src/mailgo.js
@@ -218,21 +218,21 @@ mailgoRender = mailgo => {
// validate the email address
if (!validateEmail(mail)) return;
- titleEl = document.getElementById("mailgo-title");
- detailsEl = document.getElementById("mailgo-details");
- ccEl = document.getElementById("mailgo-cc");
- ccValueEl = document.getElementById("mailgo-cc-value");
- bccEl = document.getElementById("mailgo-bcc");
- bccValueEl = document.getElementById("mailgo-bcc-value");
- subjectEl = document.getElementById("mailgo-subject");
- subjectValueEl = document.getElementById("mailgo-subject-value");
- bodyEl = document.getElementById("mailgo-body");
- bodyValueEl = document.getElementById("mailgo-body-value");
+ titleEl = getE("mailgo-title");
+ detailsEl = getE("mailgo-details");
+ ccEl = getE("mailgo-cc");
+ ccValueEl = getE("mailgo-cc-value");
+ bccEl = getE("mailgo-bcc");
+ bccValueEl = getE("mailgo-bcc-value");
+ subjectEl = getE("mailgo-subject");
+ subjectValueEl = getE("mailgo-subject-value");
+ bodyEl = getE("mailgo-body");
+ bodyValueEl = getE("mailgo-body-value");
- gmailButton = document.getElementById("mailgo-gmail");
- outlookButton = document.getElementById("mailgo-outlook");
- openButton = document.getElementById("mailgo-open");
- copyButton = document.getElementById("mailgo-copy");
+ gmailButton = getE("mailgo-gmail");
+ outlookButton = getE("mailgo-outlook");
+ openButton = getE("mailgo-open");
+ copyButton = getE("mailgo-copy");
titleEl.textContent = mail;
@@ -285,7 +285,7 @@ mailgoCheckRender = event => {
console.log(e);
// check if the id=mailgo exists in the body
- if (!document.body.contains(document.getElementById("mailgo"))) return;
+ if (!document.body.contains(getE("mailgo"))) return;
if (
// first case: it is an element with "mailto:..." in href and no no-mailgo in classList
@@ -340,13 +340,16 @@ copyToClipboard = str => {
};
// show the modal
-showMailgo = () => (document.getElementById("mailgo").style.display = "flex");
+showMailgo = () => (getE("mailgo").style.display = "flex");
// hide the modal
-hideMailgo = () => (document.getElementById("mailgo").style.display = "none");
+hideMailgo = () => (getE("mailgo").style.display = "none");
// decrypt email
mailToEncoded = encoded => (window.location.href = MAILTO + atob(encoded));
// encode email
encodeEmail = email => btoa(email);
+
+// getE shorthand
+getE = id => document.getElementById(id);