diff --git a/dist/mailgo.min.css b/dist/mailgo.min.css index 1642c68..8d829bb 100644 --- a/dist/mailgo.min.css +++ b/dist/mailgo.min.css @@ -1 +1 @@ -.mailgo-modal{position:fixed;top:0;right:0;bottom:0;left:0;justify-content:center;align-items:center;flex-direction:column;overflow:hidden;font-size:15px;z-index:10000}.mailgo-modal a,.mailgo-modal p,.mailgo-modal span,.mailgo-modal strong{margin:0;padding:0;font-size:100%;line-height:1;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"}.mailgo-modal strong{font-weight:700}.mailgo-modal .mailgo-modal-background{position:absolute;z-index:10001;top:0;right:0;bottom:0;left:0;background-color:rgba(32,35,42,.75);opacity:.8}.mailgo-modal .mailgo-modal-content{position:relative;z-index:10002;box-sizing:content-box;text-align:center;min-width:200px;max-width:240px;background-color:#fff;opacity:.97;border-radius:5px;box-shadow:0 3px 8px 0 rgba(32,35,42,.12);color:#4a4a4a;display:block;overflow:auto;padding:20px}.mailgo-modal .mailgo-modal-content:hover{opacity:1;box-shadow:0 18px 30px 0 rgba(32,35,42,.23)}.mailgo-modal .mailgo-modal-content .mailgo-title{display:block;margin-bottom:5px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.mailgo-modal .mailgo-modal-content .mailgo-details{margin-bottom:10px}.mailgo-modal .mailgo-modal-content .mailgo-details p{font-size:12px;margin-top:3px;margin-bottom:3px}.mailgo-modal .mailgo-modal-content a{display:block;padding:10px;color:#4a4a4a;border-radius:5px;text-decoration:none}.mailgo-modal .mailgo-modal-content a.mailgo-gmail{color:#d44638}.mailgo-modal .mailgo-modal-content a.mailgo-outlook{color:#0072c6}.mailgo-modal .mailgo-modal-content a.mailgo-wa{color:#00bfa5}.mailgo-modal .mailgo-modal-content a.mailgo-telegram{color:#08c}.mailgo-modal .mailgo-modal-content a.mailgo-copy{padding:16px 10px;font-size:16px}.mailgo-modal .mailgo-modal-content a.mailgo-copy:hover,.mailgo-modal .mailgo-modal-content a.mailgo-default:hover{background-color:rgba(0,0,0,.08);color:#4a4a4a}.mailgo-modal .mailgo-modal-content a.mailgo-gmail:hover{background-color:rgba(212,70,56,.08);color:#d44638}.mailgo-modal .mailgo-modal-content a.mailgo-outlook:hover{background-color:rgba(0,114,198,.08);color:#0072c6}.mailgo-modal .mailgo-modal-content a.mailgo-wa:hover{background-color:rgba(0,114,198,.08);color:#00bfa5}.mailgo-modal .mailgo-modal-content a.mailgo-telegram:hover{background-color:rgba(0,114,198,.08);color:#08c}.mailgo-modal .mailgo-modal-content a.mailgo-by{display:block;font-size:8px;margin-top:1rem;padding:0;color:#4a4a4a;opacity:.5}.mailgo-modal .mailgo-modal-content a.mailgo-by:hover{opacity:1}.mailgo-modal .mailgo-modal-content .mailgo-weight-500{font-weight:500} \ No newline at end of file +.mailgo-modal{position:fixed;top:0;right:0;bottom:0;left:0;justify-content:center;align-items:center;flex-direction:column;overflow:hidden;font-size:15px;z-index:10000}.mailgo-modal a,.mailgo-modal p,.mailgo-modal span,.mailgo-modal strong{margin:0;padding:0;font-size:100%;line-height:1;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"}.mailgo-modal strong{font-weight:700}.mailgo-modal .mailgo-modal-background{position:absolute;z-index:10001;top:0;right:0;bottom:0;left:0;background-color:rgba(32,35,42,.75);opacity:.8}.mailgo-modal .mailgo-modal-content{position:relative;z-index:10002;box-sizing:content-box;text-align:center;min-width:200px;max-width:240px;background-color:#fff;opacity:.97;border-radius:5px;box-shadow:0 3px 8px 0 rgba(32,35,42,.12);color:#4a4a4a;display:block;overflow:auto;padding:20px}.mailgo-modal .mailgo-modal-content:hover{opacity:1;box-shadow:0 18px 30px 0 rgba(32,35,42,.23)}.mailgo-modal .mailgo-modal-content .mailgo-title{display:block;margin-bottom:5px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.mailgo-modal .mailgo-modal-content .mailgo-details{margin-bottom:10px}.mailgo-modal .mailgo-modal-content .mailgo-details p{font-size:12px;margin-top:3px;margin-bottom:3px}.mailgo-modal .mailgo-modal-content a{display:block;padding:10px;color:#4a4a4a;border-radius:5px;text-decoration:none}.mailgo-modal .mailgo-modal-content a.mailgo-gmail{color:#d44638}.mailgo-modal .mailgo-modal-content a.mailgo-outlook{color:#0072c6}.mailgo-modal .mailgo-modal-content a.mailgo-wa{color:#00bfa5}.mailgo-modal .mailgo-modal-content a.mailgo-telegram{color:#08c}.mailgo-modal .mailgo-modal-content a.mailgo-copy{padding:16px 10px;font-size:16px}.mailgo-modal .mailgo-modal-content a.mailgo-copy:hover,.mailgo-modal .mailgo-modal-content a.mailgo-default:hover{background-color:rgba(0,0,0,.08);color:#4a4a4a}.mailgo-modal .mailgo-modal-content a.mailgo-gmail:hover{background-color:rgba(212,70,56,.08);color:#d44638}.mailgo-modal .mailgo-modal-content a.mailgo-outlook:hover{background-color:rgba(0,114,198,.08);color:#0072c6}.mailgo-modal .mailgo-modal-content a.mailgo-telegram:hover{background-color:rgba(0,114,198,.08);color:#08c}.mailgo-modal .mailgo-modal-content a.mailgo-wa:hover{background-color:rgba(0,191,165,.08);color:#00bfa5}.mailgo-modal .mailgo-modal-content a.mailgo-by{display:block;font-size:8px;margin-top:1rem;padding:0;color:#4a4a4a;opacity:.5}.mailgo-modal .mailgo-modal-content a.mailgo-by:hover{opacity:1}.mailgo-modal .mailgo-modal-content .mailgo-weight-500{font-weight:500} \ No newline at end of file diff --git a/dist/mailgo.min.js b/dist/mailgo.min.js index b29f086..015ab3b 100644 --- a/dist/mailgo.min.js +++ b/dist/mailgo.min.js @@ -1 +1 @@ -"use strict";var V="0.6.10",MAILTO="mailto:",TEL="tel:",CALLTO="callto:",mailgoCSS=document.createElement("style");mailgoCSS.id="mailgo-style",mailgoCSS.type="text/css";var mailgoCSSContent=document.createTextNode('.mailgo-modal{position:fixed;top:0;right:0;bottom:0;left:0;justify-content:center;align-items:center;flex-direction:column;overflow:hidden;font-size:15px;z-index:10000}.mailgo-modal a,.mailgo-modal p,.mailgo-modal span,.mailgo-modal strong{margin:0;padding:0;font-size:100%;line-height:1;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"}.mailgo-modal strong{font-weight:700}.mailgo-modal .mailgo-modal-background{position:absolute;z-index:10001;top:0;right:0;bottom:0;left:0;background-color:rgba(32,35,42,.75);opacity:.8}.mailgo-modal .mailgo-modal-content{position:relative;z-index:10002;box-sizing:content-box;text-align:center;min-width:200px;max-width:240px;background-color:#fff;opacity:.97;border-radius:5px;box-shadow:0 3px 8px 0 rgba(32,35,42,.12);color:#4a4a4a;display:block;overflow:auto;padding:20px}.mailgo-modal .mailgo-modal-content:hover{opacity:1;box-shadow:0 18px 30px 0 rgba(32,35,42,.23)}.mailgo-modal .mailgo-modal-content .mailgo-title{display:block;margin-bottom:5px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.mailgo-modal .mailgo-modal-content .mailgo-details{margin-bottom:10px}.mailgo-modal .mailgo-modal-content .mailgo-details p{font-size:12px;margin-top:3px;margin-bottom:3px}.mailgo-modal .mailgo-modal-content a{display:block;padding:10px;color:#4a4a4a;border-radius:5px;text-decoration:none}.mailgo-modal .mailgo-modal-content a.mailgo-gmail{color:#d44638}.mailgo-modal .mailgo-modal-content a.mailgo-outlook{color:#0072c6}.mailgo-modal .mailgo-modal-content a.mailgo-wa{color:#00bfa5}.mailgo-modal .mailgo-modal-content a.mailgo-telegram{color:#08c}.mailgo-modal .mailgo-modal-content a.mailgo-copy{padding:16px 10px;font-size:16px}.mailgo-modal .mailgo-modal-content a.mailgo-copy:hover,.mailgo-modal .mailgo-modal-content a.mailgo-default:hover{background-color:rgba(0,0,0,.08);color:#4a4a4a}.mailgo-modal .mailgo-modal-content a.mailgo-gmail:hover{background-color:rgba(212,70,56,.08);color:#d44638}.mailgo-modal .mailgo-modal-content a.mailgo-outlook:hover{background-color:rgba(0,114,198,.08);color:#0072c6}.mailgo-modal .mailgo-modal-content a.mailgo-wa:hover{background-color:rgba(0,114,198,.08);color:#00bfa5}.mailgo-modal .mailgo-modal-content a.mailgo-telegram:hover{background-color:rgba(0,114,198,.08);color:#08c}.mailgo-modal .mailgo-modal-content a.mailgo-by{display:block;font-size:8px;margin-top:1rem;padding:0;color:#4a4a4a;opacity:.5}.mailgo-modal .mailgo-modal-content a.mailgo-by:hover{opacity:1}.mailgo-modal .mailgo-modal-content .mailgo-weight-500{font-weight:500}');mailgoCSS.appendChild(mailgoCSSContent),document.head.appendChild(mailgoCSS);var mailgoInit=function(){var e=document.createElement("div");e.style.display="none",e.id="mailgo",e.classList.add("mailgo-modal");var a=document.createElement("div");a.className="mailgo-modal-background",e.appendChild(a);var o=document.createElement("div");o.className="mailgo-modal-content",e.appendChild(o);var t=document.createElement("strong");t.id="mailgo-title",t.className="mailgo-title",o.appendChild(t);var l=document.createElement("div");l.id="mailgo-details",l.className="mailgo-details";var i=document.createElement("p");i.id="mailgo-cc";var n=document.createElement("span");n.className="mailgo-weight-500";var d=document.createTextNode("cc ");n.appendChild(d);var m=document.createElement("span");m.id="mailgo-cc-value",i.appendChild(n),i.appendChild(m),l.appendChild(i);var c=document.createElement("p");c.id="mailgo-bcc";var r=document.createElement("span");r.className="mailgo-weight-500";var g=document.createTextNode("bcc ");r.appendChild(g);var s=document.createElement("span");s.id="mailgo-bcc-value",c.appendChild(r),c.appendChild(s),l.appendChild(c);var p=document.createElement("p");p.id="mailgo-subject";var u=document.createElement("span");u.className="mailgo-weight-500";var h=document.createTextNode("subject ");u.appendChild(h);var v=document.createElement("span");v.id="mailgo-subject-value",p.appendChild(u),p.appendChild(v),l.appendChild(p);var f=document.createElement("p");f.id="mailgo-body";var b=document.createElement("span");b.className="mailgo-weight-500";var C=document.createTextNode("body ");b.appendChild(C);var E=document.createElement("span");E.id="mailgo-body-value",f.appendChild(b),f.appendChild(E),l.appendChild(f),o.appendChild(l);var y=document.createElement("a");y.id="mailgo-gmail",y.href="#mailgo-gmail",y.classList.add("mailgo-open"),y.classList.add("mailgo-gmail");var L=document.createTextNode("open in ");y.appendChild(L);var w=document.createElement("span");w.className="mailgo-weight-500";var x=document.createTextNode("Gmail");w.appendChild(x),y.appendChild(w),o.appendChild(y);var T=document.createElement("a");T.id="mailgo-outlook",T.href="#mailgo-outlook",T.classList.add("mailgo-open"),T.classList.add("mailgo-outlook");var k=document.createTextNode("open in ");T.appendChild(k);var N=document.createElement("span");N.className="mailgo-weight-500";var A=document.createTextNode("Outlook");N.appendChild(A),T.appendChild(N),o.appendChild(T);var M=document.createElement("a");M.id="mailgo-open",M.href="#mailgo-open",M.classList.add("mailgo-open"),M.classList.add("mailgo-default");var S=document.createElement("span");S.className="mailgo-weight-500";var I=document.createTextNode("open");S.appendChild(I);var R=document.createTextNode(" default");M.appendChild(S),M.appendChild(R),o.appendChild(M);var j=document.createElement("a");j.id="mailgo-copy",j.href="#mailgo-copy",j.classList.add("mailgo-copy"),j.classList.add("mailgo-weight-500");var O=document.createTextNode("copy");j.appendChild(O),o.appendChild(j);var U=document.createElement("a");U.href="https://mailgo.js.org?ref=mailgo-modal",U.className="mailgo-by",U.target="_blank",U.rel="noopener noreferrer";var z=document.createTextNode("mailgo.js.org");U.appendChild(z),o.appendChild(U),document.body.appendChild(e),a.addEventListener("click",hideMailgo)},mailgoTelInit=function(){var e=document.createElement("div");e.style.display="none",e.id="mailgo-tel",e.classList.add("mailgo-modal");var a=document.createElement("div");a.className="mailgo-modal-background",e.appendChild(a);var o=document.createElement("div");o.className="mailgo-modal-content",e.appendChild(o);var t=document.createElement("strong");t.id="mailgo-tel-title",t.className="mailgo-title",o.appendChild(t);var l=document.createElement("a");l.id="mailgo-telegram",l.href="#mailgo-telegram",l.classList.add("mailgo-open"),l.classList.add("mailgo-telegram");var i=document.createTextNode("open in ");l.appendChild(i);var n=document.createElement("span");n.className="mailgo-weight-500";var d=document.createTextNode("Telegram");n.appendChild(d),l.appendChild(n),o.appendChild(l);var m=document.createElement("a");m.id="mailgo-wa",m.href="#mailgo-wa",m.classList.add("mailgo-open"),m.classList.add("mailgo-wa");var c=document.createTextNode("open in ");m.appendChild(c);var r=document.createElement("span");r.className="mailgo-weight-500";var g=document.createTextNode("WhatsApp");r.appendChild(g),m.appendChild(r),o.appendChild(m);var s=document.createElement("a");s.id="mailgo-call",s.href="#mailgo-call",s.classList.add("mailgo-open"),s.classList.add("mailgo-default");var p=document.createElement("span");p.className="mailgo-weight-500";var u=document.createTextNode("call");p.appendChild(u);var h=document.createTextNode(" as default");s.appendChild(p),s.appendChild(h),o.appendChild(s);var v=document.createElement("a");v.id="mailgo-tel-copy",v.href="#mailgo-copy",v.classList.add("mailgo-copy"),v.classList.add("mailgo-weight-500");var f=document.createTextNode("copy");v.appendChild(f),o.appendChild(v);var b=document.createElement("a");b.href="https://mailgo.js.org?ref=mailgo-modal",b.className="mailgo-by",b.target="_blank",b.rel="noopener noreferrer";var C=document.createTextNode("mailgo.js.org");b.appendChild(C),o.appendChild(b),document.body.appendChild(e),a.addEventListener("click",hideMailgo)},mailgoRender=function(e){var a="",o="",t="",l="",i="",n="";if(e.href&&e.href.toLowerCase().startsWith(MAILTO)){o=decodeURIComponent(e.href.split("?")[0].split(MAILTO)[1].trim()),a=new URL(e.href);var d=new URLSearchParams(a.search);t=d.get("cc"),l=d.get("bcc"),i=d.get("subject"),n=d.get("body")}else o=e.getAttribute("data-address")+"@"+e.getAttribute("data-domain"),a=new URL(MAILTO+encodeURIComponent(o)),t=e.getAttribute("data-cc-address")+"@"+e.getAttribute("data-cc-domain"),l=e.getAttribute("data-bcc-address")+"@"+e.getAttribute("data-bcc-domain"),i=e.getAttribute("data-subject"),n=e.getAttribute("data-body");if(validateEmails(o.split(","))){t&&!validateEmails(t.split(","))&&(t=""),l&&!validateEmails(l.split(","))&&(l="");var m=getE("mailgo-title"),c=(getE("mailgo-details"),getE("mailgo-cc")),r=getE("mailgo-cc-value"),g=getE("mailgo-bcc"),s=getE("mailgo-bcc-value"),p=getE("mailgo-subject"),u=getE("mailgo-subject-value"),h=getE("mailgo-body"),v=getE("mailgo-body-value"),f=getE("mailgo-gmail"),b=getE("mailgo-outlook"),C=getE("mailgo-open"),E=getE("mailgo-copy");m.innerHTML=o.split(",").join("
"),t?(c.style.display="block",r.innerHTML=t.split(",").join("
")):c.style.display="none",l?(g.style.display="block",s.innerHTML=l.split(",").join("
")):g.style.display="none",i?(p.style.display="block",u.textContent=i):p.style.display="none",n?(h.style.display="block",v.textContent=n):h.style.display="none",f.addEventListener("click",function(){return actions.openGmail(o,t,l,i,n)}),b.addEventListener("click",function(){return actions.openOutlook(o,i,n)});var y=encodeEmail(o);C.addEventListener("click",function(){return actions.openDefault(y)}),E.addEventListener("click",function(){return actions.copy(o,E)}),showMailgo(),document.addEventListener("keydown",function(){return mailgoKeydown(o,t,l,i,n,y,E)})}},mailgoTelRender=function(e){var a="";e.href&&e.href.toLowerCase().startsWith(TEL)&&(a=decodeURIComponent(e.href.split("?")[0].split(TEL)[1].trim())),e.href&&e.href.toLowerCase().startsWith(CALLTO)&&(a=decodeURIComponent(e.href.split("?")[0].split(CALLTO)[1].trim())),console.log(a);var o=getE("mailgo-tel-title"),t=getE("mailgo-wa"),l=getE("mailgo-telegram"),i=getE("mailgo-call"),n=getE("mailgo-tel-copy");o.innerHTML=a,t.addEventListener("click",function(){return actions.openWhatsApp(a)}),l.addEventListener("click",function(){return actions.openTelegram(a)}),i.addEventListener("click",function(){return actions.callDefault(a)}),n.addEventListener("click",function(){return actions.copy(a,n)}),showMailgoTel()},actions={openGmail:function(e,a,o,t,l){var i="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(e);a&&(i=i.concat("&cc="+encodeURIComponent(a))),o&&(i=i.concat("&bcc="+encodeURIComponent(o))),t&&(i=i.concat("&subject="+t)),l&&(i=i.concat("&body="+l)),window.open(i,"_blank")},openOutlook:function(e,a,o){var t="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(e);a&&(t=t.concat("&subject="+a)),o&&(t=t.concat("&body="+o)),window.open(t,"_blank")},openDefault:function(e){mailToEncoded(e)},openTelegram:function(e,a){var o="tg://msg?text="+(1()[\]\\.,;:\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)},showMailgo=function(){return getE("mailgo").style.display="flex"},showMailgoTel=function(){return getE("mailgo-tel").style.display="flex"},hideMailgo=function(){return getE("mailgo").style.display="none",getE("mailgo-tel").style.display="none"},mailgoIsShowing=function(){return"flex"===getE("mailgo").style.display},mailToEncoded=function(e){return window.location.href=MAILTO+atob(e)},encodeEmail=function(e){return btoa(e)},getE=function(e){return document.getElementById(e)},composedPath=function(e){for(var a=[];e;){if(a.push(e),"HTML"===e.tagName)return a.push(document),a.push(window),a;e=e.parentElement}},validateEmails=function(e){return e.every(validateEmail)},cleanTel=function(e){return e},copyToClipboard=function(e){var a=document.createElement("textarea");a.value=e,a.setAttribute("readonly",""),a.style.position="absolute",a.style.left="-9999px",document.body.appendChild(a);var o=0"),cc?(n.style.display="block",d.innerHTML=cc.split(",").join("
")):n.style.display="none",bcc?(c.style.display="block",m.innerHTML=bcc.split(",").join("
")):c.style.display="none",subject?(r.style.display="block",s.textContent=subject):r.style.display="none",bodyMail?(g.style.display="block",p.textContent=bodyMail):g.style.display="none",u.addEventListener("click",function(){return actions.openGmail(mail,cc,bcc,subject,bodyMail)}),h.addEventListener("click",function(){return actions.openOutlook(mail,subject,bodyMail)}),encEmail=encodeEmail(mail),v.addEventListener("click",function(){return actions.openDefault(encEmail)}),b.addEventListener("click",function(){return actions.copy(mail,b)})}if(o===TEL_TYPE){t.href&&t.href.toLowerCase().startsWith(TEL)&&(tel=decodeURIComponent(t.href.split("?")[0].split(TEL)[1].trim())),t.href&&t.href.toLowerCase().startsWith(CALLTO)&&(tel=decodeURIComponent(t.href.split("?")[0].split(CALLTO)[1].trim()));var E=getE("mailgo-tel-title"),f=getE("mailgo-wa"),y=getE("mailgo-telegram"),C=getE("mailgo-call"),L=getE("mailgo-tel-copy");E.innerHTML=tel,f.addEventListener("click",function(){return actions.openWhatsApp(tel)}),y.addEventListener("click",function(){return actions.openTelegram(tel)}),C.addEventListener("click",function(){return actions.callDefault(tel)}),L.addEventListener("click",function(){return actions.copy(tel,L)})}showMailgo(o),document.addEventListener("keydown",mailgoKeydown)},actions={openGmail:function(e,a,o,t,l){var i="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(e);a&&(i=i.concat("&cc="+encodeURIComponent(a))),o&&(i=i.concat("&bcc="+encodeURIComponent(o))),t&&(i=i.concat("&subject="+t)),l&&(i=i.concat("&body="+l)),window.open(i,"_blank")},openOutlook:function(e,a,o){var t="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(e);a&&(t=t.concat("&subject="+a)),o&&(t=t.concat("&body="+o)),window.open(t,"_blank")},openDefault:function(e){mailToEncoded(e)},openTelegram:function(e,a){var o="tg://msg?text="+(1()[\]\\.,;:\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)},validateEmails=function(e){return e.every(validateEmail)},cleanTel=function(e){return e},copyToClipboard=function(e){var a=document.createElement("textarea");a.value=e,a.setAttribute("readonly",""),a.style.position="absolute",a.style.left="-9999px",document.body.appendChild(a);var o=0"),t?(s.style.display="block",f.innerHTML=t.split(",").join("
")):s.style.display="none",n?(v.style.display="block",b.innerHTML=n.split(",").join("
")):v.style.display="none",d?(y.style.display="block",C.textContent=d):y.style.display="none",m?(x.style.display="block",w.textContent=m):x.style.display="none",E.addEventListener("click",(function(){return l.openGmail(o,t,n,d,m)})),k.addEventListener("click",(function(){return l.openOutlook(o,d,m)}));var T=g(o);L.addEventListener("click",(function(){return l.openDefault(T)})),N.addEventListener("click",(function(){return l.copy(o,N)})),c(),document.addEventListener("keydown",(function(){return i(o,t,n,d,m,T,N)}))}}(a)):function(e){return e.href&&(e.href.toLowerCase().startsWith("tel:")||e.href.toLowerCase().startsWith("callto:"))&&!e.classList.contains("no-mailgo")}(a)?(e.preventDefault(),void function(e){var a="";e.href&&e.href.toLowerCase().startsWith("tel:")&&(a=decodeURIComponent(e.href.split("?")[0].split("tel:")[1].trim())),e.href&&e.href.toLowerCase().startsWith("callto:")&&(a=decodeURIComponent(e.href.split("?")[0].split("callto:")[1].trim())),console.log(a);var o=u("mailgo-tel-title"),t=u("mailgo-wa"),n=u("mailgo-telegram"),i=u("mailgo-call"),d=u("mailgo-tel-copy");o.innerHTML=a,t.addEventListener("click",(function(){return l.openWhatsApp(a)})),n.addEventListener("click",(function(){return l.openTelegram(a)})),i.addEventListener("click",(function(){return l.callDefault(a)})),d.addEventListener("click",(function(){return l.copy(a,d)})),m()}(a)):void 0}))}}));var d=function(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)},c=function(){return u("mailgo").style.display="flex"},m=function(){return u("mailgo-tel").style.display="flex"},r=function(){return u("mailgo").style.display="none",u("mailgo-tel").style.display="none"},p=function(){return"flex"===u("mailgo").style.display},s=function(e){return window.location.href="mailto:"+atob(e)},g=function(e){return btoa(e)},u=function(e){return document.getElementById(e)},f=function(e){for(var a=[];e;){if(a.push(e),"HTML"===e.tagName)return a.push(document),a.push(window),a;e=e.parentElement}},h=function(e){return e.every(d)},v=function(e){var a=document.createElement("textarea");a.value=e,a.setAttribute("readonly",""),a.style.position="absolute",a.style.left="-9999px",document.body.appendChild(a);var o=0"),c?(y.style.display="block",C.innerHTML=c.split(",").join("
")):y.style.display="none",m?(x.style.display="block",k.innerHTML=m.split(",").join("
")):x.style.display="none",r?(L.style.display="block",N.textContent=r):L.style.display="none",p?(T.style.display="block",A.textContent=p):T.style.display="none",R.addEventListener("click",(function(){return f.openGmail(i,c,m,r,p)})),S.addEventListener("click",(function(){return f.openOutlook(i,r,p)})),d=w(i),U.addEventListener("click",(function(){return f.openDefault(d)})),O.addEventListener("click",(function(){return f.copy(i,O)}))}if("tel"===o){g.href&&g.href.toLowerCase().startsWith(n)&&(s=decodeURIComponent(g.href.split("?")[0].split(n)[1].trim())),g.href&&g.href.toLowerCase().startsWith("callto:")&&(s=decodeURIComponent(g.href.split("?")[0].split("callto:")[1].trim()));var I=E("mailgo-tel-title"),M=E("mailgo-wa"),_=E("mailgo-telegram"),z=E("mailgo-call"),D=E("mailgo-tel-copy");I.innerHTML=s,M.addEventListener("click",(function(){return f.openWhatsApp(s)})),_.addEventListener("click",(function(){return f.openTelegram(s)})),z.addEventListener("click",(function(){return f.callDefault(s)})),D.addEventListener("click",(function(){return f.copy(s,D)}))}b(o),document.addEventListener("keydown",v)},f={openGmail:function(e,a,o,t,n){var l="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(e);a&&(l=l.concat("&cc="+encodeURIComponent(a))),o&&(l=l.concat("&bcc="+encodeURIComponent(o))),t&&(l=l.concat("&subject="+t)),n&&(l=l.concat("&body="+n)),window.open(l,"_blank")},openOutlook:function(e,a,o){var t="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(e);a&&(t=t.concat("&subject="+a)),o&&(t=t.concat("&body="+o)),window.open(t,"_blank")},openDefault:function(e){x(e)},openTelegram:function(e,a){var o="tg://msg?text="+(1()[\]\\.,;:\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)},j=function(e){return e.every(T)},A=function(e){var a=document.createElement("textarea");a.value=e,a.setAttribute("readonly",""),a.style.position="absolute",a.style.left="-9999px",document.body.appendChild(a);var o=0 { * mailgoRender * function to render a single mailgo */ -const mailgoRender = mailgo => { - let url = "", - mail = "", - cc = "", - bcc = "", - subject = "", - bodyMail = ""; +const mailgoRender = (type = MAIL_TYPE, mailgo) => { + // mailgo mail + if (type === MAIL_TYPE) { + // if the element href=^"mailto:" + if (mailgo.href && mailgo.href.toLowerCase().startsWith(MAILTO)) { + mail = decodeURIComponent( + mailgo.href + .split("?")[0] + .split(MAILTO)[1] + .trim() + ); - // if the element href=^"mailto:" - if (mailgo.href && mailgo.href.toLowerCase().startsWith(MAILTO)) { - mail = decodeURIComponent( - mailgo.href - .split("?")[0] - .split(MAILTO)[1] - .trim() + url = new URL(mailgo.href); + let urlParams = new URLSearchParams(url.search); + + // optional parameters for the email + cc = urlParams.get("cc"); + bcc = urlParams.get("bcc"); + subject = urlParams.get("subject"); + bodyMail = urlParams.get("body"); + } else { + // if the element href="#mailgo" or class="mailgo" + // mail = data-address + @ + data-domain + mail = + mailgo.getAttribute("data-address") + + "@" + + mailgo.getAttribute("data-domain"); + + url = new URL(MAILTO + encodeURIComponent(mail)); + + // cc = data-cc-address + @ + data-cc-domain + cc = + mailgo.getAttribute("data-cc-address") + + "@" + + mailgo.getAttribute("data-cc-domain"); + + // bcc = data-bcc-address + @ + data-bcc-domain + bcc = + mailgo.getAttribute("data-bcc-address") + + "@" + + mailgo.getAttribute("data-bcc-domain"); + + // subject = data-subject + subject = mailgo.getAttribute("data-subject"); + + // body = data-body + bodyMail = mailgo.getAttribute("data-body"); + } + + // validate the email address + if (!validateEmails(mail.split(","))) return; + + // if cc, bcc is not valid cc, bcc = "" + if (cc && !validateEmails(cc.split(","))) cc = ""; + if (bcc && !validateEmails(bcc.split(","))) bcc = ""; + + // information + let titleEl = getE("mailgo-title"); + let detailsEl = getE("mailgo-details"); + let ccEl = getE("mailgo-cc"); + let ccValueEl = getE("mailgo-cc-value"); + let bccEl = getE("mailgo-bcc"); + let bccValueEl = getE("mailgo-bcc-value"); + let subjectEl = getE("mailgo-subject"); + let subjectValueEl = getE("mailgo-subject-value"); + let bodyEl = getE("mailgo-body"); + let bodyValueEl = getE("mailgo-body-value"); + + // actions + let gmailButton = getE("mailgo-gmail"); + let outlookButton = getE("mailgo-outlook"); + let openButton = getE("mailgo-open"); + let copyButton = getE("mailgo-copy"); + + // the title of the modal (email address) + titleEl.innerHTML = mail.split(",").join("
"); + + // add the details if provided + cc + ? ((ccEl.style.display = "block"), + (ccValueEl.innerHTML = cc.split(",").join("
"))) + : (ccEl.style.display = "none"); + + bcc + ? ((bccEl.style.display = "block"), + (bccValueEl.innerHTML = bcc.split(",").join("
"))) + : (bccEl.style.display = "none"); + + subject + ? ((subjectEl.style.display = "block"), + (subjectValueEl.textContent = subject)) + : (subjectEl.style.display = "none"); + + bodyMail + ? ((bodyEl.style.display = "block"), (bodyValueEl.textContent = bodyMail)) + : (bodyEl.style.display = "none"); + + // add the actions + gmailButton.addEventListener("click", () => + actions.openGmail(mail, cc, bcc, subject, bodyMail) ); - url = new URL(mailgo.href); - let urlParams = new URLSearchParams(url.search); + outlookButton.addEventListener("click", () => + actions.openOutlook(mail, subject, bodyMail) + ); - // optional parameters for the email - cc = urlParams.get("cc"); - bcc = urlParams.get("bcc"); - subject = urlParams.get("subject"); - bodyMail = urlParams.get("body"); - } else { - // if the element href="#mailgo" or class="mailgo" - // mail = data-address + @ + data-domain - mail = - mailgo.getAttribute("data-address") + - "@" + - mailgo.getAttribute("data-domain"); + encEmail = encodeEmail(mail); + openButton.addEventListener("click", () => actions.openDefault(encEmail)); - url = new URL(MAILTO + encodeURIComponent(mail)); - - // cc = data-cc-address + @ + data-cc-domain - cc = - mailgo.getAttribute("data-cc-address") + - "@" + - mailgo.getAttribute("data-cc-domain"); - - // bcc = data-bcc-address + @ + data-bcc-domain - bcc = - mailgo.getAttribute("data-bcc-address") + - "@" + - mailgo.getAttribute("data-bcc-domain"); - - // subject = data-subject - subject = mailgo.getAttribute("data-subject"); - - // body = data-body - bodyMail = mailgo.getAttribute("data-body"); + copyButton.addEventListener("click", () => actions.copy(mail, copyButton)); } + // mailgo tel + if (type === TEL_TYPE) { + if (mailgo.href && mailgo.href.toLowerCase().startsWith(TEL)) { + tel = decodeURIComponent( + mailgo.href + .split("?")[0] + .split(TEL)[1] + .trim() + ); + } - // validate the email address - if (!validateEmails(mail.split(","))) return; + if (mailgo.href && mailgo.href.toLowerCase().startsWith(CALLTO)) { + tel = decodeURIComponent( + mailgo.href + .split("?")[0] + .split(CALLTO)[1] + .trim() + ); + } - // if cc, bcc is not valid cc, bcc = "" - if (cc && !validateEmails(cc.split(","))) cc = ""; - if (bcc && !validateEmails(bcc.split(","))) bcc = ""; + // information + let titleEl = getE("mailgo-tel-title"); - // information - let titleEl = getE("mailgo-title"); - let detailsEl = getE("mailgo-details"); - let ccEl = getE("mailgo-cc"); - let ccValueEl = getE("mailgo-cc-value"); - let bccEl = getE("mailgo-bcc"); - let bccValueEl = getE("mailgo-bcc-value"); - let subjectEl = getE("mailgo-subject"); - let subjectValueEl = getE("mailgo-subject-value"); - let bodyEl = getE("mailgo-body"); - let bodyValueEl = getE("mailgo-body-value"); + // actions + let waButton = getE("mailgo-wa"); + let telegramButton = getE("mailgo-telegram"); + let callButton = getE("mailgo-call"); + let copyButton = getE("mailgo-tel-copy"); - // actions - let gmailButton = getE("mailgo-gmail"); - let outlookButton = getE("mailgo-outlook"); - let openButton = getE("mailgo-open"); - let copyButton = getE("mailgo-copy"); + // the title of the modal (tel) + titleEl.innerHTML = tel; - // the title of the modal (email address) - titleEl.innerHTML = mail.split(",").join("
"); + // add the actions + waButton.addEventListener("click", () => actions.openWhatsApp(tel)); - // add the details if provided - cc - ? ((ccEl.style.display = "block"), - (ccValueEl.innerHTML = cc.split(",").join("
"))) - : (ccEl.style.display = "none"); + telegramButton.addEventListener("click", () => actions.openTelegram(tel)); - bcc - ? ((bccEl.style.display = "block"), - (bccValueEl.innerHTML = bcc.split(",").join("
"))) - : (bccEl.style.display = "none"); + callButton.addEventListener("click", () => actions.callDefault(tel)); - subject - ? ((subjectEl.style.display = "block"), - (subjectValueEl.textContent = subject)) - : (subjectEl.style.display = "none"); - - bodyMail - ? ((bodyEl.style.display = "block"), (bodyValueEl.textContent = bodyMail)) - : (bodyEl.style.display = "none"); - - // add the actions - gmailButton.addEventListener("click", () => - actions.openGmail(mail, cc, bcc, subject, bodyMail) - ); - - outlookButton.addEventListener("click", () => - actions.openOutlook(mail, subject, bodyMail) - ); - - let encEmail = encodeEmail(mail); - openButton.addEventListener("click", () => actions.openDefault(encEmail)); - - copyButton.addEventListener("click", () => actions.copy(mail, copyButton)); + copyButton.addEventListener("click", () => actions.copy(tel, copyButton)); + } // show the mailgo - showMailgo(); + showMailgo(type); // listener keyDown - document.addEventListener("keydown", () => - mailgoKeydown(mail, cc, bcc, subject, bodyMail, encEmail, copyButton) - ); -}; - -/** - * mailgoTelRender - * function to render a single tel mailgo - */ -const mailgoTelRender = mailgo => { - let tel = ""; - - if (mailgo.href && mailgo.href.toLowerCase().startsWith(TEL)) { - tel = decodeURIComponent( - mailgo.href - .split("?")[0] - .split(TEL)[1] - .trim() - ); - } - - if (mailgo.href && mailgo.href.toLowerCase().startsWith(CALLTO)) { - tel = decodeURIComponent( - mailgo.href - .split("?")[0] - .split(CALLTO)[1] - .trim() - ); - } - - // information - let titleEl = getE("mailgo-tel-title"); - - // actions - let waButton = getE("mailgo-wa"); - let telegramButton = getE("mailgo-telegram"); - let callButton = getE("mailgo-call"); - let copyButton = getE("mailgo-tel-copy"); - - // the title of the modal (tel) - titleEl.innerHTML = tel; - - // add the actions - waButton.addEventListener("click", () => actions.openWhatsApp(tel)); - - telegramButton.addEventListener("click", () => actions.openTelegram(tel)); - - callButton.addEventListener("click", () => actions.callDefault(tel)); - - copyButton.addEventListener("click", () => actions.copy(tel, copyButton)); - - // show the mailgo - showMailgoTel(); - - // listener keyDown - /* - document.addEventListener("keydown", () => - mailgoKeydown(mail, cc, bcc, subject, bodyMail, encEmail, copyButton) - ); - */ + document.addEventListener("keydown", mailgoKeydown); }; // actions @@ -560,7 +549,7 @@ const mailgoCheckRender = event => { event.preventDefault(); // render mailgo - mailgoRender(element); + mailgoRender(MAIL_TYPE, element); return; } @@ -569,7 +558,7 @@ const mailgoCheckRender = event => { event.preventDefault(); // render mailgo - mailgoTelRender(element); + mailgoRender(TEL_TYPE, element); return; } @@ -583,41 +572,35 @@ const mailgoCheckRender = event => { * mailgoKeydown * function to manage the keydown event when the modal is showing */ -const mailgoKeydown = ( - mail, - cc, - bcc, - subject, - bodyMail, - encEmail, - copyButton -) => { - // if mailgo is not showing do nothing - if (!mailgoIsShowing()) return; - switch (event.keyCode) { - case 27: - // Escape - hideMailgo(); - break; - case 71: - // g -> open GMail - actions.openGmail(mail, cc, bcc, subject, bodyMail); - break; - case 79: - // o -> open Outlook - actions.openOutlook(mail, subject, bodyMail); - break; - case 32: - case 13: - // spacebar or enter -> open default - actions.openDefault(encEmail); - break; - case 67: - // c -> copy - actions.copy(mail, copyButton); - break; - default: - return; +const mailgoKeydown = () => { + // if mailgo is showing + if (mailgoIsShowing(MAIL_TYPE)) { + switch (event.keyCode) { + case 27: + // Escape + hideMailgo(); + break; + case 71: + // g -> open GMail + actions.openGmail(mail, cc, bcc, subject, bodyMail); + break; + case 79: + // o -> open Outlook + actions.openOutlook(mail, subject, bodyMail); + break; + case 32: + case 13: + // spacebar or enter -> open default + actions.openDefault(encEmail); + break; + case 67: + // c -> copy + actions.copy(mail, copyButton); + break; + default: + return; + } + } else if (mailgoIsShowing(TEL_TYPE)) { } return; }; @@ -629,17 +612,11 @@ document.addEventListener("DOMContentLoaded", mailgoTelInit); // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered document.addEventListener("click", mailgoCheckRender); -// validate a single email with regex -const validateEmail = email => { - let re = /^(([^<>()[\]\\.,;:\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,}))$/; - return re.test(email); -}; - // show the modal -const showMailgo = type => { +const showMailgo = (type = MAIL_TYPE) => { type === TEL_TYPE - ? setDisplay("mailgo", "flex") - : setDisplay("mailgo-tel", "flex"); + ? setDisplay("mailgo-tel", "flex") + : setDisplay("mailgo", "flex"); }; // hide the modal @@ -649,10 +626,10 @@ const hideMailgo = () => { }; // is the mailgo modal hidden? -const mailgoIsShowing = (type = "mail") => { +const mailgoIsShowing = (type = MAIL_TYPE) => { type === TEL_TYPE - ? getDisplay("mailgo") === "flex" - : getDisplay("mailgo-tel") === "flex"; + ? getDisplay("mailgo-tel") === "flex" + : getDisplay("mailgo") === "flex"; }; // decrypt email @@ -688,6 +665,12 @@ const composedPath = el => { } }; +// validate a single email with regex +const validateEmail = email => { + let re = /^(([^<>()[\]\\.,;:\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,}))$/; + return re.test(email); +}; + // validate an array of emails const validateEmails = arr => arr.every(validateEmail); diff --git a/src/mailgo.scss b/src/mailgo.scss index 0f1e2e8..28bc19d 100644 --- a/src/mailgo.scss +++ b/src/mailgo.scss @@ -129,16 +129,16 @@ $telegram-color: #0088cc; color: $outlook-color; } - &.mailgo-wa:hover { - background-color: rgba(0, 114, 198, 0.08); - color: $wa-color; - } - &.mailgo-telegram:hover { background-color: rgba(0, 114, 198, 0.08); color: $telegram-color; } + &.mailgo-wa:hover { + background-color: rgba(0, 191, 165, 0.08); + color: $wa-color; + } + &.mailgo-by { display: block; font-size: 8px;