From 4293a9474e8bfe5fc3374f1bb27962e192c870f9 Mon Sep 17 00:00:00 2001 From: Matteo Manzinello Date: Thu, 9 Jan 2020 22:34:52 +0100 Subject: [PATCH] a test: trying to reduce bundle size, reduced of 0.4kb renaming appendChild function --- dist/mailgo.min.js | 2 +- mailgo.js | 2 +- src/mailgo.js | 131 +++++++++++++++++++++++---------------------- 3 files changed, 70 insertions(+), 65 deletions(-) diff --git a/dist/mailgo.min.js b/dist/mailgo.min.js index 07ab493..51fc64f 100644 --- a/dist/mailgo.min.js +++ b/dist/mailgo.min.js @@ -1 +1 @@ -"use strict";var mailgoVersion="0.8.2";!function(){function t(){var e=de("div");e.style.display="none",e.id="mailgo",e.classList.add("m-modal");var a=de("div");a.className="m-modal-back",e.appendChild(a);var t=de("div");t.className="m-modal-content",e.appendChild(t),(_=de("strong")).id="m-title",_.className="m-title",t.appendChild(_);var o=de("div");o.id="m-details",o.className="m-details",(P=de("p")).id="m-cc";var n=de("span");n.className="w-500";var i=le("cc ");n.appendChild(i),(F=de("span")).id="m-cc-value",P.appendChild(n),P.appendChild(F),o.appendChild(P),(B=de("p")).id="m-bcc";var d=de("span");d.className="w-500";var l=le("bcc ");d.appendChild(l),(G=de("span")).id="m-bcc-value",B.appendChild(d),B.appendChild(G),o.appendChild(B),(O=de("p")).id="m-subject";var s=de("span");s.className="w-500";var r=le("subject ");s.appendChild(r),(V=de("span")).id="m-subject-value",O.appendChild(s),O.appendChild(V),o.appendChild(O),(Z=de("p")).id="m-body";var c=de("span");c.className="w-500";var m=le("body ");c.appendChild(m),($=de("span")).id="m-body-value",Z.appendChild(c),Z.appendChild($),o.appendChild(Z),t.appendChild(o),(q=de("a")).id="m-gmail",q.href=oe,q.classList.add("m-open"),q.classList.add("m-gmail");var p=le("open in ");q.appendChild(p);var b=de("span");b.className="w-500";var h=le("Gmail");b.appendChild(h),q.appendChild(b),t.appendChild(q),(J=de("a")).id="m-outlook",J.href=oe,J.classList.add("m-open"),J.classList.add("m-outlook");var u=le("open in ");J.appendChild(u);var f=de("span");f.className="w-500";var g=le("Outlook");f.appendChild(g),J.appendChild(f),t.appendChild(J),(K=de("a")).id="m-open",K.href=oe,K.classList.add("m-open"),K.classList.add("m-default");var v=de("span");v.className="w-500";var w=le("open");v.appendChild(w);var x=le(" default");K.appendChild(v),K.appendChild(x),t.appendChild(K),(ae=de("a")).id="m-copy",ae.href=oe,ae.classList.add("m-copy"),ae.classList.add("w-500");var C=le("copy");ae.appendChild(C),t.appendChild(ae),t.appendChild(ie()),document.body.appendChild(e),a.addEventListener("click",ne);var y=de("div");y.style.display="none",y.id="mailgo-tel",y.classList.add("m-modal");var k=de("div");k.className="m-modal-back",y.appendChild(k);var L=de("div");L.className="m-modal-content",y.appendChild(L),(D=de("strong")).id="m-tel-title",D.className="m-title",L.appendChild(D),(Q=de("a")).id="m-tg",Q.href=oe,Q.classList.add("m-open"),Q.classList.add("m-tg"),Q.style.display="none";var z=le("open in ");Q.appendChild(z);var A=de("span");A.className="w-500";var E=le("Telegram");A.appendChild(E),Q.appendChild(A),L.appendChild(Q),(X=de("a")).id="m-wa",X.href=oe,X.classList.add("m-open"),X.classList.add("m-wa");var N=le("open in ");X.appendChild(N);var j=de("span");j.className="w-500";var R=le("WhatsApp");j.appendChild(R),X.appendChild(j),L.appendChild(X),(Y=de("a")).id="m-skype",Y.href=oe,Y.classList.add("m-open"),Y.classList.add("m-skype");var U=le("open in ");Y.appendChild(U);var I=de("span");I.className="w-500";var S=le("Skype");I.appendChild(S),Y.appendChild(I),L.appendChild(Y),(ee=de("a")).id="m-call",ee.href=oe,ee.classList.add("m-open"),ee.classList.add("m-default");var T=de("span");T.className="w-500";var M=le("call");T.appendChild(M);var W=le(" as default");ee.appendChild(T),ee.appendChild(W),L.appendChild(ee),(te=de("a")).id="m-tel-copy",te.href=oe,te.classList.add("m-copy"),te.classList.add("w-500");var H=le("copy");te.appendChild(H),L.appendChild(te),L.appendChild(ie()),document.body.appendChild(y),k.addEventListener("click",ne)}function o(e,a){var t=0"),h?(P.style.display="block",F.innerHTML=h.split(",").join("
")):P.style.display="none",u?(B.style.display="block",G.innerHTML=u.split(",").join("
")):B.style.display="none",f?(O.style.display="block",V.textContent=f):O.style.display="none",g?(Z.style.display="block",$.textContent=g):Z.style.display="none",q.addEventListener("click",C),J.addEventListener("click",y),b=I(p),K.addEventListener("click",k),ae.addEventListener("click",function(){return N(p)})}t===c&&(o.href&&o.href.toLowerCase().startsWith(l)?v=decodeURIComponent(o.href.split("?")[0].split(l)[1].trim()):o.href&&o.href.toLowerCase().startsWith(s)?v=decodeURIComponent(o.href.split("?")[0].split(s)[1].trim()):o.hasAttribute("data-tel")&&(v=o.getAttribute("data-tel"),o.getAttribute("data-msg")),o.hasAttribute("data-telegram")&&(w=o.getAttribute("data-telegram")),o.hasAttribute("data-skype")&&(x=o.getAttribute("data-skype")),D.innerHTML=v,X.addEventListener("click",A),w&&(M("m-tg","block"),Q.addEventListener("click",L)),Y.addEventListener("click",z),ee.addEventListener("click",E),te.addEventListener("click",function(){return N(v)})),R(t),document.addEventListener("keydown",j)}function n(e,a){var t=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)}var _,D,P,B,O,Z,F,G,V,$,q,J,K,Q,X,Y,ee,ae,te,d="mailto:",l="tel:",s="callto:",r="mail",c="tel",oe="javascript:void(0);",m="",p="",b="",h="",u="",f="",g="",v="",w="",x="",C=function(){var e="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(p);h&&(e=e.concat("&cc="+encodeURIComponent(h))),u&&(e=e.concat("&bcc="+encodeURIComponent(u))),f&&(e=e.concat("&subject="+f)),g&&(e=e.concat("&body="+g)),window.open(e,"_blank"),ne()},y=function(){var e="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(p);f&&(e=e.concat("&subject="+f)),g&&(e=e.concat("&body="+g)),window.open(e,"_blank"),ne()},k=function(){e(b),ne()},L=function(){var e="https://t.me/"+w;window.open(e,"_blank"),ne()},z=function(){var e="skype:"+(""!==x?x:v);window.open(e,"_blank"),ne()},A=function(){var e="https://wa.me/"+v;window.open(e,"_blank"),ne()},E=function(){var e="tel:"+v;window.open(e),ne()},N=function(e){var a;se(e),(a=U(r)?ae:te).textContent="copied",setTimeout(function(){a.textContent="copy",ne()},999)},j=function(e){if(U(r))switch(e.keyCode){case 27:ne();break;case 71:C();break;case 79:y();break;case 32:case 13:k();break;case 67:N(p);break;default:return}else if(U(c))switch(e.keyCode){case 27:ne();break;case 84:L();break;case 87:A();break;case 32:case 13:E();break;case 67:N(v);break;default:return}},R=function(e){var a=0"),u?(P.style.display="block",F.innerHTML=u.split(",").join("
")):P.style.display="none",f?(B.style.display="block",G.innerHTML=f.split(",").join("
")):B.style.display="none",g?(O.style.display="block",V.textContent=g):O.style.display="none",v?(Z.style.display="block",$.textContent=v):Z.style.display="none",q.addEventListener("click",y),J.addEventListener("click",k),b=I(p),K.addEventListener("click",L),ta.addEventListener("click",function(){return N(p)})}e===l&&(o.href&&o.href.toLowerCase().startsWith(s)?w=decodeURIComponent(o.href.split("?")[0].split(s)[1].trim()):o.href&&o.href.toLowerCase().startsWith(r)?w=decodeURIComponent(o.href.split("?")[0].split(r)[1].trim()):o.hasAttribute("data-tel")&&(w=o.getAttribute("data-tel"),o.getAttribute("data-msg")),o.hasAttribute("data-telegram")&&(h=o.getAttribute("data-telegram")),o.hasAttribute("data-skype")&&(x=o.getAttribute("data-skype")),D.innerHTML=w,X.addEventListener("click",A),h&&(M("m-tg","block"),Q.addEventListener("click",z)),Y.addEventListener("click",C),aa.addEventListener("click",E),ea.addEventListener("click",function(){return N(w)})),R(e),document.addEventListener("keydown",j)}function n(a,t){var e=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(a)}var sa=function(a){return document.createTextNode(a)},a=function(a){return window.location.href=c+atob(a)},I=function(a){return btoa(a)},S=function(a){return document.getElementById(a)},T=function(a){return S(a).style.display},M=function(a,t){return S(a).style.display=t},H=function(a){for(var t=[];a;){if(t.push(a),"HTML"===a.tagName)return t.push(document),t.push(window),t;a=a.parentElement}},W=function(a){return a.every(t)},ra=function(a){var t=ca("textarea");t.value=a,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.ac(t);var e=0"),I?(l.style.display="block",m.innerHTML=I.split(",").join("
")):l.style.display="none",M?(r.style.display="block",p.innerHTML=M.split(",").join("
")):r.style.display="none",_?(s.style.display="block",u.textContent=_):s.style.display="none",T?(c.style.display="block",b.textContent=T):c.style.display="none",f.addEventListener("click",H),h.addEventListener("click",D),U=ae(R),g.addEventListener("click",B),C.addEventListener("click",(function(){return q(R)}))}a===E&&(o.href&&o.href.toLowerCase().startsWith(z)?O=decodeURIComponent(o.href.split("?")[0].split(z)[1].trim()):o.href&&o.href.toLowerCase().startsWith(j)?O=decodeURIComponent(o.href.split("?")[0].split(j)[1].trim()):o.hasAttribute("data-tel")&&(O=o.getAttribute("data-tel"),o.getAttribute("data-msg")),o.hasAttribute("data-telegram")&&(P=o.getAttribute("data-telegram")),o.hasAttribute("data-skype")&&(W=o.getAttribute("data-skype")),d.innerHTML=O,x.addEventListener("click",G),P&&(ie("m-tg","block"),v.addEventListener("click",Z)),w.addEventListener("click",F),y.addEventListener("click",$),k.addEventListener("click",(function(){return q(O)}))),K(a),document.addEventListener("keydown",J)}function a(e,t){var a=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)}var i,d,l,r,s,c,m,p,u,b,f,h,g,v,x,w,y,C,k,L="mailto:",z="tel:",j="callto:",A="mail",E="tel",N="javascript:void(0);",S="",R="",U="",I="",M="",_="",T="",O="",P="",W="",H=function(){var e="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(R);I&&(e=e.concat("&cc="+encodeURIComponent(I))),M&&(e=e.concat("&bcc="+encodeURIComponent(M))),_&&(e=e.concat("&subject="+_)),T&&(e=e.concat("&body="+T)),window.open(e,"_blank"),Q()},D=function(){var e="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(R);_&&(e=e.concat("&subject="+_)),T&&(e=e.concat("&body="+T)),window.open(e,"_blank"),Q()},B=function(){te(U),Q()},Z=function(){var e="https://t.me/"+P;window.open(e,"_blank"),Q()},F=function(){var e="skype:"+(""!==W?W:O);window.open(e,"_blank"),Q()},G=function(){var e="https://wa.me/"+O;window.open(e,"_blank"),Q()},$=function(){var e="tel:"+O;window.open(e),Q()},q=function(e){var t;re(e),(t=V(A)?C:k).textContent="copied",setTimeout((function(){t.textContent="copy",Q()}),999)},J=function(e){if(V(A))switch(e.keyCode){case 27:Q();break;case 71:H();break;case 79:D();break;case 32:case 13:B();break;case 67:q(R);break;default:return}else if(V(E))switch(e.keyCode){case 27:Q();break;case 84:Z();break;case 87:G();break;case 32:case 13:$();break;case 67:q(O);break;default:return}},K=function(e){var t=0"),U?(c.style.display="block",d.innerHTML=U.split(",").join("
")):c.style.display="none",M?(r.style.display="block",m.innerHTML=M.split(",").join("
")):r.style.display="none",I?(l.style.display="block",p.textContent=I):l.style.display="none",T?(s.style.display="block",u.textContent=T):s.style.display="none",b.addEventListener("click",P),f.addEventListener("click",W),R=ae(S),g.addEventListener("click",D),h.addEventListener("click",(function(){return $(S)}))}a===A&&(o.href&&o.href.toLowerCase().startsWith(z)?_=decodeURIComponent(o.href.split("?")[0].split(z)[1].trim()):o.href&&o.href.toLowerCase().startsWith(C)?_=decodeURIComponent(o.href.split("?")[0].split(C)[1].trim()):o.hasAttribute("data-tel")&&(_=o.getAttribute("data-tel"),o.getAttribute("data-msg")),o.hasAttribute("data-telegram")&&(O=o.getAttribute("data-telegram")),o.hasAttribute("data-skype")&&(H=o.getAttribute("data-skype")),i.innerHTML=_,x.addEventListener("click",F),O&&(ie("m-tg","block"),v.addEventListener("click",B)),w.addEventListener("click",Z),y.addEventListener("click",G),k.addEventListener("click",(function(){return $(_)}))),J(a),document.addEventListener("keydown",q)}function a(e,t){var a=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)}HTMLElement.prototype.ac=function(e){return this.appendChild(e)};var ee=function(e){return document.createTextNode(e)},te=function(e){return window.location.href=L+atob(e)},ae=function(e){return btoa(e)},oe=function(e){return document.getElementById(e)},ne=function(e){return oe(e).style.display},ie=function(e,t){return oe(e).style.display=t},ce=function(e){for(var t=[];e;){if(t.push(e),"HTML"===e.tagName)return t.push(document),t.push(window),t;e=e.parentElement}},re=function(e){return e.every(Y)},le=function(e){var t=X("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.ac(t);var a=0 document.createElement(element); + // append child (prototype) + HTMLElement.prototype.ac = function(childElement) { + return this.appendChild(childElement); + }; + // create text node const createTextNode = element => document.createTextNode(element); @@ -827,7 +832,7 @@ const mailgoVersion = "MAILGO_VERSION"; el.setAttribute("readonly", ""); el.style.position = "absolute"; el.style.left = "-9999px"; - document.body.appendChild(el); + document.body.ac(el); let selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) @@ -850,8 +855,8 @@ const mailgoVersion = "MAILGO_VERSION"; mailgoCSS.id = "mailgo-style"; mailgoCSS.type = "text/css"; let mailgoCSSContent = createTextNode(`MAILGO_STYLE`); - mailgoCSS.appendChild(mailgoCSSContent); - document.head.appendChild(mailgoCSS); + mailgoCSS.ac(mailgoCSSContent); + document.head.ac(mailgoCSS); // DOMContentLoaded -> mailgoInit (creates the modals) document.addEventListener("DOMContentLoaded", mailgoInit);