-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·24 lines (22 loc) · 2.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!doctype html>
<head>
<script>/**
* cross-storage - Cross domain local storage
*
* @version 0.8.2
* @link https://github.com/zendesk/cross-storage
* @author Daniel St. Jules <[email protected]>
* @copyright Zendesk
* @license Apache-2.0
*/
!function(e){var t={};t.init=function(e){var r=!0;try{window.localStorage||(r=!1)}catch(n){r=!1}if(!r)try{return window.parent.postMessage("cross-storage:unavailable","*")}catch(n){return}t._permissions=e||[],t._installListener(),window.parent.postMessage("cross-storage:ready","*")},t._installListener=function(){var e=t._listener;window.addEventListener?window.addEventListener("message",e,!1):window.attachEvent("onmessage",e)},t._listener=function(e){var r,n,o,i,s,a,l;if(r="null"===e.origin?"file://":e.origin,"cross-storage:poll"===e.data)return window.parent.postMessage("cross-storage:ready",e.origin);if("cross-storage:ready"!==e.data){try{o=JSON.parse(e.data)}catch(u){return}if(o&&"string"==typeof o.method&&(i=o.method.split("cross-storage:")[1])){if(t._permitted(r,i))try{a=t["_"+i](o.params)}catch(u){s=u.message}else s="Invalid permissions for "+i;l=JSON.stringify({id:o.id,error:s,result:a}),n="file://"===r?"*":r,window.parent.postMessage(l,n)}}},t._permitted=function(e,r){var n,o,i,s;if(n=["get","set","del","clear","getKeys"],!t._inArray(r,n))return!1;for(o=0;o<t._permissions.length;o++)if(i=t._permissions[o],i.origin instanceof RegExp&&i.allow instanceof Array&&(s=i.origin.test(e),s&&t._inArray(r,i.allow)))return!0;return!1},t._set=function(e){var r,n;if(r=e.ttl,r&&parseInt(r,10)!==r)throw new Error("ttl must be a number");n={value:e.value},r&&(n.expire=t._now()+r),window.localStorage.setItem(e.key,JSON.stringify(n))},t._get=function(e){var r,n,o,i,s;for(r=window.localStorage,n=[],o=0;o<e.keys.length;o++){s=e.keys[o];try{i=JSON.parse(r.getItem(s))}catch(a){i=null}null===i?n.push(null):i.expire&&i.expire<t._now()?(r.removeItem(s),n.push(null)):n.push(i.value)}return n.length>1?n:n[0]},t._del=function(e){for(var t=0;t<e.keys.length;t++)window.localStorage.removeItem(e.keys[t])},t._clear=function(){window.localStorage.clear()},t._getKeys=function(){var e,t,r;for(r=[],t=window.localStorage.length,e=0;t>e;e++)r.push(window.localStorage.key(e));return r},t._inArray=function(e,t){for(var r=0;r<t.length;r++)if(e===t[r])return!0;return!1},t._now=function(){return"function"==typeof Date.now?Date.now():(new Date).getTime()},"undefined"!=typeof module&&module.exports?module.exports=t:"undefined"!=typeof exports?exports.CrossStorageHub=t:"function"==typeof define&&define.amd?define([],function(){return t}):e.CrossStorageHub=t}(this);</script>
</head>
<body>
<script>
var origins = [ /.*/i ];
CrossStorageHub.init(origins.map(function(o) {
return { origin: o, allow: ['get', 'set', 'del', 'clear'] };
}));
</script>
</body>
</html>