diff --git a/dist/mailgo.js b/dist/mailgo.js index 9a30981..4715f5c 100644 --- a/dist/mailgo.js +++ b/dist/mailgo.js @@ -1,11 +1,12 @@ -const version = "0.2.6"; +const VERSION = "0.2.6"; +const MAILTO = "mailto:"; mailgoInit = () => { const styleSheet = document.createElement("link"); styleSheet.rel = "stylesheet"; styleSheet.type = "text/css"; styleSheet.href = - "https://unpkg.com/mailgo@" + version + "/dist/mailgo.min.css"; + "https://unpkg.com/mailgo@" + VERSION + "/dist/mailgo.min.css"; document.head.appendChild(styleSheet); // all mailgos in the document @@ -23,10 +24,10 @@ mailgoInit = () => { bodyMail = ""; // mailgo all the element with href=^"mailto:" - if (mailgo.href && mailgo.href.includes("mailto:")) { + if (mailgo.href && mailgo.href.startsWith(MAILTO)) { mail = mailgo.href .split("?")[0] - .split("mailto:")[1] + .split(MAILTO)[1] .trim(); mailtoHref = mailgo.href; @@ -45,7 +46,7 @@ mailgoInit = () => { mailgo.getAttribute("data-address") + "@" + mailgo.getAttribute("data-domain"); - mailtoHref = "mailto:" + mail; + mailtoHref = MAILTO + mail; url = new URL(mailtoHref); } @@ -265,7 +266,7 @@ copyToClipboard = str => { }; // decrypt email -mailToEncoded = encoded => (window.location.href = "mailto:" + atob(encoded)); +mailToEncoded = encoded => (window.location.href = MAILTO + atob(encoded)); // encrypt email encryptEmail = email => btoa(email); diff --git a/dist/mailgo.min.js b/dist/mailgo.min.js index 46f9ce2..241b519 100644 --- a/dist/mailgo.min.js +++ b/dist/mailgo.min.js @@ -1 +1 @@ -const version="0.2.6";mailgoInit=(()=>{const e=document.createElement("link");e.rel="stylesheet",e.type="text/css",e.href="https://unpkg.com/mailgo@0.2.6/dist/mailgo.min.css",document.head.appendChild(e),document.querySelectorAll('a[href^="mailto:"]:not(.no-mailgo), a[href="#mailgo"], a.mailgo').forEach((e,t)=>{let a="",l="",d="",n="",o="",c="";if(e.href&&e.href.includes("mailto:")){a=e.href.split("?")[0].split("mailto:")[1].trim(),l=e.href,url=new URL(l);let t=new URLSearchParams(url.search);d=t.get("cc"),n=t.get("bcc"),o=t.get("subject"),c=t.get("body")}else l="mailto:"+(a=e.getAttribute("data-address")+"@"+e.getAttribute("data-domain")),url=new URL(l);if(!validateEmail(a))return;let i=document.createElement("div");i.classList.add("mailgo-modal"),i.setAttribute("data-index",t);let m=document.createElement("div");m.className="mailgo-modal-background",i.appendChild(m);let p=document.createElement("div");p.className="mailgo-modal-content",i.appendChild(p);let s=document.createElement("strong");s.className="mailgo-title";let r=document.createTextNode(a);s.appendChild(r),p.appendChild(s);let u=document.createElement("div");if(u.className="mailgo-details",d&&""!=d){let e=document.createElement("p"),t=document.createElement("span");t.className="mailgo-weight-500";let a=document.createTextNode("cc");t.appendChild(a);let l=document.createTextNode(": "+d);e.appendChild(t),e.appendChild(l),u.appendChild(e)}if(n&&""!=n){let e=document.createElement("p"),t=document.createElement("span");t.className="mailgo-weight-500";let a=document.createTextNode("bcc");t.appendChild(a);let l=document.createTextNode(": "+n);e.appendChild(t),e.appendChild(l),u.appendChild(e)}if(o&&""!=o){let e=document.createElement("p"),t=document.createElement("span");t.className="mailgo-weight-500";let a=document.createTextNode("cc");t.appendChild(a);let l=document.createTextNode(": "+o);e.appendChild(t),e.appendChild(l),u.appendChild(e)}if(c&&""!=c){let e=document.createElement("p"),t=document.createElement("span");t.className="mailgo-weight-500";let a=document.createTextNode("cc");t.appendChild(a);let l=document.createTextNode(": "+c);e.appendChild(t),e.appendChild(l),u.appendChild(e)}p.appendChild(u);let h=document.createElement("a");h.href="https://mail.google.com/mail?extsrc=mailto&url="+l,h.classList.add("mailgo-open"),h.classList.add("gmail");let g=document.createTextNode("open in ");h.appendChild(g);let C=document.createElement("span");C.className="mailgo-weight-500";let E=document.createTextNode("Gmail");C.appendChild(E),h.appendChild(C),p.appendChild(h);let N=document.createElement("a");N.href="https://outlook.office.com/owa/?rru=compose&to="+a+url.search,N.classList.add("mailgo-open"),N.classList.add("outlook");let f=document.createTextNode("open in ");N.appendChild(f);let x=document.createElement("span");x.className="mailgo-weight-500";let T=document.createTextNode("Outlook");x.appendChild(T),N.appendChild(x),p.appendChild(N);let L=document.createElement("a");L.href="#mailgo-open";let b=encryptEmail(a);L.addEventListener("click",()=>{mailToEncoded(b)},!1),L.classList.add("mailgo-open"),L.classList.add("mailgo-weight-500");let v=document.createTextNode("open");L.appendChild(v),p.appendChild(L);let y=document.createElement("a");y.href="#mailgo-copy",y.classList.add("mailgo-copy"),y.classList.add("mailgo-weight-500");let w=document.createTextNode("copy");y.appendChild(w),y.addEventListener("click",e=>{copyToClipboard(a),y.innerHTML="copied",setTimeout(()=>{y.innerHTML="copy"},999)},!1),p.appendChild(y);let k=document.createElement("a");k.href="https://mailgo.js.org",k.className="mailgo-by",k.target="_blank";let A=document.createTextNode("mailgo.js.org");k.appendChild(A),p.appendChild(k),e.parentNode.insertBefore(i,e.nextSibling),e.addEventListener("click",t=>{t.preventDefault(),e.nextElementSibling.classList.add("is-active")},!1),m.addEventListener("click",t=>{e.nextElementSibling.classList.remove("is-active")},!1)})}),document.addEventListener("DOMContentLoaded",mailgoInit,!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 a=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),a&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(a))}),mailToEncoded=(e=>window.location.href="mailto:"+atob(e)),encryptEmail=(e=>btoa(e)); \ No newline at end of file +const VERSION="0.2.6",MAILTO="mailto:";mailgoInit=(()=>{const e=document.createElement("link");e.rel="stylesheet",e.type="text/css",e.href="https://unpkg.com/mailgo@0.2.6/dist/mailgo.min.css",document.head.appendChild(e),document.querySelectorAll('a[href^="mailto:"]:not(.no-mailgo), a[href="#mailgo"], a.mailgo').forEach((e,t)=>{let a="",l="",d="",n="",o="",c="";if(e.href&&e.href.startsWith(MAILTO)){a=e.href.split("?")[0].split(MAILTO)[1].trim(),l=e.href,url=new URL(l);let t=new URLSearchParams(url.search);d=t.get("cc"),n=t.get("bcc"),o=t.get("subject"),c=t.get("body")}else a=e.getAttribute("data-address")+"@"+e.getAttribute("data-domain"),l=MAILTO+a,url=new URL(l);if(!validateEmail(a))return;let i=document.createElement("div");i.classList.add("mailgo-modal"),i.setAttribute("data-index",t);let m=document.createElement("div");m.className="mailgo-modal-background",i.appendChild(m);let p=document.createElement("div");p.className="mailgo-modal-content",i.appendChild(p);let s=document.createElement("strong");s.className="mailgo-title";let r=document.createTextNode(a);s.appendChild(r),p.appendChild(s);let u=document.createElement("div");if(u.className="mailgo-details",d&&""!=d){let e=document.createElement("p"),t=document.createElement("span");t.className="mailgo-weight-500";let a=document.createTextNode("cc");t.appendChild(a);let l=document.createTextNode(": "+d);e.appendChild(t),e.appendChild(l),u.appendChild(e)}if(n&&""!=n){let e=document.createElement("p"),t=document.createElement("span");t.className="mailgo-weight-500";let a=document.createTextNode("bcc");t.appendChild(a);let l=document.createTextNode(": "+n);e.appendChild(t),e.appendChild(l),u.appendChild(e)}if(o&&""!=o){let e=document.createElement("p"),t=document.createElement("span");t.className="mailgo-weight-500";let a=document.createTextNode("cc");t.appendChild(a);let l=document.createTextNode(": "+o);e.appendChild(t),e.appendChild(l),u.appendChild(e)}if(c&&""!=c){let e=document.createElement("p"),t=document.createElement("span");t.className="mailgo-weight-500";let a=document.createTextNode("cc");t.appendChild(a);let l=document.createTextNode(": "+c);e.appendChild(t),e.appendChild(l),u.appendChild(e)}p.appendChild(u);let h=document.createElement("a");h.href="https://mail.google.com/mail?extsrc=mailto&url="+l,h.classList.add("mailgo-open"),h.classList.add("gmail");let g=document.createTextNode("open in ");h.appendChild(g);let C=document.createElement("span");C.className="mailgo-weight-500";let E=document.createTextNode("Gmail");C.appendChild(E),h.appendChild(C),p.appendChild(h);let N=document.createElement("a");N.href="https://outlook.office.com/owa/?rru=compose&to="+a+url.search,N.classList.add("mailgo-open"),N.classList.add("outlook");let T=document.createTextNode("open in ");N.appendChild(T);let L=document.createElement("span");L.className="mailgo-weight-500";let f=document.createTextNode("Outlook");L.appendChild(f),N.appendChild(L),p.appendChild(N);let x=document.createElement("a");x.href="#mailgo-open";let b=encryptEmail(a);x.addEventListener("click",()=>{mailToEncoded(b)},!1),x.classList.add("mailgo-open"),x.classList.add("mailgo-weight-500");let y=document.createTextNode("open");x.appendChild(y),p.appendChild(x);let v=document.createElement("a");v.href="#mailgo-copy",v.classList.add("mailgo-copy"),v.classList.add("mailgo-weight-500");let w=document.createTextNode("copy");v.appendChild(w),v.addEventListener("click",e=>{copyToClipboard(a),v.innerHTML="copied",setTimeout(()=>{v.innerHTML="copy"},999)},!1),p.appendChild(v);let A=document.createElement("a");A.href="https://mailgo.js.org",A.className="mailgo-by",A.target="_blank";let k=document.createTextNode("mailgo.js.org");A.appendChild(k),p.appendChild(A),e.parentNode.insertBefore(i,e.nextSibling),e.addEventListener("click",t=>{t.preventDefault(),e.nextElementSibling.classList.add("is-active")},!1),m.addEventListener("click",t=>{e.nextElementSibling.classList.remove("is-active")},!1)})}),document.addEventListener("DOMContentLoaded",mailgoInit,!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 a=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),a&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(a))}),mailToEncoded=(e=>window.location.href=MAILTO+atob(e)),encryptEmail=(e=>btoa(e)); \ No newline at end of file