-
Notifications
You must be signed in to change notification settings - Fork 5
/
imagebeast.min.js
1 lines (1 loc) · 1.54 KB
/
imagebeast.min.js
1
'use strict';var dataCacheName=''+location.hostname+(location.port?':'+location.port:'')+'$$cache';function calculateSaveDataUrl(a){return a.substr(0,a.lastIndexOf('.'))+'-savedata'+a.substr(a.lastIndexOf('.'),a.length-1)}function fetchAndProcess(a,b,c){return regeneratorRuntime.async(function(h){for(;;)switch(h.prev=h.next){case 0:return h.next=2,regeneratorRuntime.awrap(caches.match(b));case 2:if(d=h.sent,!d){h.next=5;break}return h.abrupt('return',d);case 5:return h.next=7,regeneratorRuntime.awrap(fetch(b));case 7:if(e=h.sent,e.ok||a.includes('placeholder')){h.next=10;break}return h.abrupt('return',fetch('/images/placeholder.jpg'));case 10:if(!c){h.next=18;break}return h.next=13,regeneratorRuntime.awrap(caches.open(dataCacheName));case 13:return f=h.sent,f.put(b,e.clone()),h.abrupt('return',e);case 18:return h.abrupt('return',e);case 19:case'end':return h.stop();}},null,this)}function calculateReturnUrl(a,b,c,d){return a.get('accept').includes('webp')&&d?b.substr(0,b.lastIndexOf('.'))+'.webp':a.get('accept').includes('ms-photo')&&c?b.substr(0,b.lastIndexOf('.'))+'.jxr':void 0}function optimize(a){return regeneratorRuntime.async(function(c){for(;;)switch(c.prev=c.next){case 0:this.addEventListener('fetch',function(d){var e,f=d.request.headers,g=d.request.url;/\.jpg$|.gif$|.png$/.test(g)&&!g.includes('placeholder')&&(f.get('save-data')&&a.useSaveData?e=calculateSaveDataUrl(g):f.has('accept')&&(e=calculateReturnUrl(f,g,a.useXr,a.useWebp)),e==void 0&&(e=g),d.respondWith(fetchAndProcess(g,e,a.useCache)))});case 1:case'end':return c.stop();}},null,this)}