-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobot.min.js
5 lines (5 loc) · 2.26 KB
/
mobot.min.js
1
2
3
4
5
/*!
* mobot.js v1.0.5
* (c) 2018 MOYU
* Released under the MIT License.
*/(function(a,b){function e(a,b){var c=new XMLHttpRequest;c.open("GET",a),c.onreadystatechange=function(){c.readyState===4&&((c.status>=200&&c.status<300||c.status===304)&&c.responseText?b(null,{content:c.responseText,type:c.getResponseHeader("content-type")}):b(new Error(c.statusText)))},setTimeout(function(){c.readyState<4&&(c.abort(),b(new Error("Request timeout")))},d.timeout),c.send()}function f(a,b){e(a.url,function(c,e){if(c)return b(c);var f={key:a.key,unique:a.unique,url:a.url,cache:a.cache,content:e.content,type:e.type,stamp:Date.now(),expire:Date.now()+(a.expire||d.expire)*60*60*1e3};f.cache&&g(f.key,f),b(null,f)})}function g(a,b){try{localStorage.setItem(d.prefix+a,JSON.stringify(b))}catch(c){if(c.name.toUpperCase().indexOf("QUOTA")>=0){var e;for(var f in localStorage)if(f.indexOf(d.prefix)===0){e=!0;break}e&&(d.clear(),g(a,b))}}}function h(a){if(/javascript/.test(a.type)){var d=b.createElement("script");d.type="text/javascript",d.defer=!0,d.crossOrigin="anonymous",d.text=a.content,c.appendChild(d)}else if(/css/.test(a.type)){var e=b.createElement("style");e.innerText=a.content,c.appendChild(e)}}function i(a,b){var c=d.get(a.key),e=!c||c.unique!==a.unique||c.expire>0&&c.expire<Date.now();e?f(a,function(a,c){if(a)return b(a);b(null,c)}):b(null,c)}function j(a,b){function e(){for(var a=0,b=d.length;a<b;a++){if(!d[a])break;d[a].executed!==!0&&(h(d[a]),d[a].executed=!0)}}var c=a.length,d=new Array(a.length);for(var f=0,g=a.length;f<g;f++)(function(f){i(a[f],function(a,g){--c,a?b.called!==!0&&(b.called=!0,b(a)):(d[f]=g,e(),c<=0&&b.called!==!0&&(b.called=!0,b(null,d)))})})(f)}"use strict";var c=b.head||b.getElementsByTagName("head")[0],d;d=a.mobot={timeout:1e4,expire:168,prefix:"mobot-",require:function(a,b){return a=a.reduce(function(a,b){return b.url?(b.cache=b.cache!==!1,b.key=b.key||b.url,b.unique=b.unique||b.url,a.push(b),a):a},[]),j(a,function(a,c){typeof b=="function"&&b(a,c)}),this},get:function(a){var b=null;try{b=JSON.parse(localStorage.getItem(d.prefix+a))}catch(c){d.remove(a)}return b},remove:function(a){try{localStorage.removeItem(d.prefix+a)}catch(b){}return this},clear:function(){for(var a in localStorage){var b=a.split(d.prefix)[1];b&&d.remove(b)}return this}}})(window,document);