-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-page-speed-scores.package.min.js
2 lines (2 loc) · 8.49 KB
/
google-page-speed-scores.package.min.js
1
2
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.qwest=e()}}(function(){var e;return function e(t,n,o){function r(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var f=n[s]={exports:{}};t[s][0].call(f.exports,function(e){var n=t[s][1][e];return r(n?n:e)},f,f.exports,e,t,n,o)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<o.length;s++)r(o[s]);return r}({1:[function(t,n,o){!function(t){"use strict";var o=function(e){var t=function(e,t,n){n="function"==typeof n?n():null===n?"":void 0===n?"":n,e[e.length]=encodeURIComponent(t)+"="+encodeURIComponent(n)},n=function(e,o,r){var i,s,a;if("[object Array]"===Object.prototype.toString.call(o))for(i=0,s=o.length;s>i;i++)n(e+"["+("object"==typeof o[i]?i:"")+"]",o[i],r);else if(o&&"[object Object]"===o.toString())for(a in o)o.hasOwnProperty(a)&&(e?n(e+"["+a+"]",o[a],r,t):n(a,o[a],r,t));else if(e)t(r,e,o);else for(a in o)t(r,a,o[a]);return r};return n("",e,[]).join("&").replace(/%20/g,"+")};"object"==typeof n&&"object"==typeof n.exports?n.exports=o:"function"==typeof e&&e.amd?e([],function(){return o}):t.param=o}(this)},{}],2:[function(e,t,n){!function(e){function t(e){return"function"==typeof e}function n(e){return"object"==typeof e}function o(e){"undefined"!=typeof setImmediate?setImmediate(e):"undefined"!=typeof process&&process.nextTick?process.nextTick(e):setTimeout(e,0)}var r;e[0][e[1]]=function e(i){var s,a=[],u=[],p=function(e,t){return null==s&&null!=e&&(s=e,a=t,u.length&&o(function(){for(var e=0;e<u.length;e++)u[e]()})),s};return p.then=function(p,f){var c=e(i),l=function(){function e(o){var i,s=0;try{if(o&&(n(o)||t(o))&&t(i=o.then)){if(o===c)throw new TypeError;i.call(o,function(){s++||e.apply(r,arguments)},function(e){s++||c(!1,[e])})}else c(!0,arguments)}catch(e){s++||c(!1,[e])}}try{var o=s?p:f;t(o)?e(o.apply(r,a||[])):c(s,a)}catch(e){c(!1,[e])}};return null!=s?o(l):u.push(l),c},i&&(p=i(p)),p}}("undefined"==typeof t?[window,"pinkySwear"]:[t,"exports"])},{}],qwest:[function(e,t,n){t.exports=function(){var t="undefined"!=typeof window?window:self,n=e("pinkyswear"),o=e("jquery-param"),r={},i="json",s="post",a=null,u=0,p=[],f=t.XMLHttpRequest?function(){return new t.XMLHttpRequest}:function(){return new ActiveXObject("Microsoft.XMLHTTP")},c=""===f().responseType,l=function(e,l,d,y,h){e=e.toUpperCase(),d=d||null,y=y||{};for(var m in r)if(!(m in y))if("object"==typeof r[m]&&"object"==typeof y[m])for(var T in r[m])y[m][T]=r[m][T];else y[m]=r[m];var w,v,x,b,g,j=!1,q=!1,C=!1,O=0,D={},E={text:"*/*",xml:"text/xml",json:"application/json",post:"application/x-www-form-urlencoded",document:"text/html"},M={text:"*/*",xml:"application/xml; q=1.0, text/xml; q=0.8, */*; q=0.1",json:"application/json; q=1.0, text/*; q=0.8, */*; q=0.1"},X=!1,L=n(function(n){return n.abort=function(){C||(v&&4!=v.readyState&&v.abort(),X&&(--u,X=!1),C=!0)},n.send=function(){if(!X){if(u==a)return void p.push(n);if(C)return void(p.length&&p.shift().send());if(++u,X=!0,v=f(),w&&("withCredentials"in v||!t.XDomainRequest||(v=new XDomainRequest,q=!0,"GET"!=e&&"POST"!=e&&(e="POST"))),q?v.open(e,l):(v.open(e,l,y.async,y.user,y.password),c&&y.async&&(v.withCredentials=y.withCredentials)),!q)for(var o in D)D[o]&&v.setRequestHeader(o,D[o]);if(c&&"auto"!=y.responseType)try{v.responseType=y.responseType,j=v.responseType==y.responseType}catch(e){}c||q?(v.onload=R,v.onerror=S,q&&(v.onprogress=function(){})):v.onreadystatechange=function(){4==v.readyState&&R()},y.async?"timeout"in v?(v.timeout=y.timeout,v.ontimeout=k):x=setTimeout(k,y.timeout):q&&(v.ontimeout=function(){}),"auto"!=y.responseType&&"overrideMimeType"in v&&v.overrideMimeType(E[y.responseType]),h&&h(v),q?setTimeout(function(){v.send("GET"!=e?d:null)},0):v.send("GET"!=e?d:null)}},n}),R=function(){var e;if(X=!1,clearTimeout(x),p.length&&p.shift().send(),!C){--u;try{if(j){if("response"in v&&null===v.response)throw"The request response is empty";g=v.response}else{if(e=y.responseType,"auto"==e)if(q)e=i;else{var n=v.getResponseHeader("Content-Type")||"";e=n.indexOf(E.json)>-1?"json":n.indexOf(E.xml)>-1?"xml":"text"}switch(e){case"json":if(v.responseText.length)try{g="JSON"in t?JSON.parse(v.responseText):new Function("return ("+v.responseText+")")()}catch(e){throw"Error while parsing JSON body : "+e}break;case"xml":try{t.DOMParser?g=(new DOMParser).parseFromString(v.responseText,"text/xml"):(g=new ActiveXObject("Microsoft.XMLDOM"),g.async="false",g.loadXML(v.responseText))}catch(e){g=void 0}if(!g||!g.documentElement||g.getElementsByTagName("parsererror").length)throw"Invalid XML";break;default:g=v.responseText}}if("status"in v&&!/^2|1223/.test(v.status))throw v.status+" ("+v.statusText+")";L(!0,[v,g])}catch(e){L(!1,[e,v,g])}}},S=function(e){C||(e="string"==typeof e?e:"Connection aborted",L.abort(),L(!1,[new Error(e),v,null]))},k=function(){C||(y.attempts&&++O==y.attempts?S("Timeout ("+l+")"):(v.abort(),X=!1,L.send()))};if(y.async=!("async"in y)||!!y.async,y.cache="cache"in y&&!!y.cache,y.dataType="dataType"in y?y.dataType.toLowerCase():s,y.responseType="responseType"in y?y.responseType.toLowerCase():"auto",y.user=y.user||"",y.password=y.password||"",y.withCredentials=!!y.withCredentials,y.timeout="timeout"in y?parseInt(y.timeout,10):3e4,y.attempts="attempts"in y?parseInt(y.attempts,10):1,b=l.match(/\/\/(.+?)\//),w=b&&!!b[1]&&b[1]!=location.host,"ArrayBuffer"in t&&d instanceof ArrayBuffer?y.dataType="arraybuffer":"Blob"in t&&d instanceof Blob?y.dataType="blob":"Document"in t&&d instanceof Document?y.dataType="document":"FormData"in t&&d instanceof FormData&&(y.dataType="formdata"),null!==d)switch(y.dataType){case"json":d=JSON.stringify(d);break;case"post":d=o(d)}if(y.headers){var P=function(e,t,n){return t+n.toUpperCase()};for(b in y.headers)D[b.replace(/(^|-)([^-])/g,P)]=y.headers[b]}return"Content-Type"in D||"GET"==e||y.dataType in E&&E[y.dataType]&&(D["Content-Type"]=E[y.dataType]),D.Accept||(D.Accept=y.responseType in M?M[y.responseType]:"*/*"),w||"X-Requested-With"in D||(D["X-Requested-With"]="XMLHttpRequest"),y.cache||"Cache-Control"in D||(D["Cache-Control"]="no-cache"),"GET"==e&&d&&"string"==typeof d&&(l+=(/\?/.test(l)?"&":"?")+d),y.async&&L.send(),L},d=function(e){var t=[],o=0,r=[];return n(function(n){var i=-1,s=function(e){return function(s,a,u,p){var f=++i;return++o,t.push(l(e,n.base+s,a,u,p).then(function(e,t){r[f]=arguments,--o||n(!0,1==r.length?r[0]:[r])},function(){n(!1,arguments)})),n}};n.get=s("GET"),n.post=s("POST"),n.put=s("PUT"),n.delete=s("DELETE"),n.catch=function(e){return n.then(null,e)},n.complete=function(e){var t=function(){e()};return n.then(t,t)},n.map=function(e,t,n,o,r){return s(e.toUpperCase()).call(this,t,n,o,r)};for(var a in e)a in n||(n[a]=e[a]);return n.send=function(){for(var e=0,o=t.length;o>e;++e)t[e].send();return n},n.abort=function(){for(var e=0,o=t.length;o>e;++e)t[e].abort();return n},n})},y={base:"",get:function(){return d(y).get.apply(this,arguments)},post:function(){return d(y).post.apply(this,arguments)},put:function(){return d(y).put.apply(this,arguments)},delete:function(){return d(y).delete.apply(this,arguments)},map:function(){return d(y).map.apply(this,arguments)},xhr2:c,limit:function(e){return a=e,y},setDefaultOptions:function(e){return r=e,y},setDefaultXdrResponseType:function(e){return i=e.toLowerCase(),y},setDefaultDataType:function(e){return s=e.toLowerCase(),y},getOpenRequests:function(){return u}};return y}()},{"jquery-param":1,pinkyswear:2}]},{},[1,2])("qwest")});
var googlePageSpeedScores=function(e,s){"use strict";if(e=e||[],e.length)return this.apiUrl="https://www.googleapis.com/pagespeedonline/v2/runPagespeed",this.results=[],this.fetchPromises=[],this.averageScore=function(e){var s=0,t=0;return e.forEach(function(e){s+=e.speed,t+=e.usability}),s=Math.round(s/e.length),t=Math.round(t/e.length),{speed:s,usability:t}},this.storeResult=function(e,s){var t=s.ruleGroups.SPEED,r=s.ruleGroups.USABILITY;this.results.push({speed:t.score,usability:r.score})},this.logError=function(e,s,t){console.log("logError: ",arguments)},e.forEach(function(e){var s=qwest.get(this.apiUrl,{url:e,strategy:"mobile"}).then(this.storeResult.bind(this)).catch(this.logError);this.fetchPromises.push(s),s=null}.bind(this)),Promise.all(this.fetchPromises).then(function(){s(this.averageScore(this.results))}.bind(this)).catch(function(){console.log("ALL error: ",arguments)})};