-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemoji-favicon-toolkit.min.js
2 lines (2 loc) · 1.91 KB
/
emoji-favicon-toolkit.min.js
1
2
/*! @source https://github.com/eligrey/emoji-favicon-toolkit/blob/master/src/emoji-favicon-toolkit.ts */
var set_emoji_favicon=function(){function e(e,a){var r=String(e)||"",f=Boolean(a),h=u.measureText(r).width,m=(i+i/o)/2,p=Math.min(i/h,1),v=m/p;u.clearRect(0,0,i,i),u.save(),u.scale(p,p),u.fillText(r,v,v),u.restore(),l.href=d.toDataURL(t),document.getElementsByTagName("head")[0].appendChild(l),f&&c&&d.toBlob(function(e){var t=new FileReader;t.addEventListener("loadend",function(){var e=t.result;n.then(function(){c.register(s,{scope:"/"}),c.ready.then(function(t){t.active.postMessage(e,[e])})})}),t.readAsArrayBuffer(e)},t)}var t="image/png";if(!!self.document){var n=new Promise(function(e){window.addEventListener("load",e)}),a="http://www.w3.org/1999/xhtml",r=/^\s*(?:text\/plain)\s*(?:$|;)/i,i=256,o=16,s=document.currentScript.getAttribute("src"),c=navigator.serviceWorker,d=document.createElementNS(a,"canvas"),l=document.createElementNS(a,"link"),u=d.getContext("2d");d.width=d.height=i,u.font="normal normal normal "+i+"px/"+i+"px sans-serif",u.textAlign="center",u.textBaseline="middle",l.rel="icon",l.type=t,l.setAttribute("sizes",i+"x"+i);var f=[].slice.call(document.getElementsByTagNameNS(a,"link"),0).filter(function(e){return"icon"===e.rel.toLowerCase()&&r.test(e.type)}).pop();if(f){var h=new XMLHttpRequest,m=f.href.trim().replace(/^data:(;base64)?,/,"data:text/plain;charset=utf-8$1,");h.open("GET",m),h.addEventListener("load",function(){if(h.readyState===h.DONE&&200===h.status){e(h.responseText,!1)}}),h.send()}return e}var p="favicon-cache";self.addEventListener("message",function(e){var n=e.data,a=new Request("/favicon.ico"),r=new Response(n,{headers:{"Content-Type":t,"Content-Length":String(n.byteLength)}});caches.open(p).then(function(e){e.put(a,r)})}),self.addEventListener("fetch",function(e){e.respondWith(caches.open(p).then(function(t){return t.match(e.request).then(function(t){return t||fetch(e.request)})}))})}();