Created
July 11, 2018 20:29
-
-
Save atomize/bf041e022469802ab367fac1d11b60c0 to your computer and use it in GitHub Desktop.
houd1ni/localStorage-by-IndexedDB-shim - Helps MS Edge be a real browser. [https://github.com/houd1ni/localStorage-by-IndexedDB-shim]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var options={poll_time:200},localStorageShim=function(t){var e,r="__localStorageShim",n="pairs",o="localStorageShim Error: ";const a=[];try{if(localStorage.setItem("a",4),4!=localStorage.getItem("a"))throw 1;e=function(){this.setItem=function(t,e){return localStorage.setItem(t,e)},this.getItem=function(t){return localStorage.getItem(t)}}}catch(c){e=function(){var e,c,i=indexedDB.open(r,7),u={},s=function(){e=db.transaction(n).objectStore(n),e.openCursor().onsuccess=function(t){var e,r=t.target.result;r&&(e=r.value,u[e.k]=[e.v,r.key],r["continue"]())}},l=function(t,r){if(t+="",r+="",!u[t]||u[t][0]!==r){u[t]=u[t]||[],u[t][0]=r,clearInterval(c),e=db.transaction(n,"readwrite").objectStore(n);var o=[{k:t,v:r}];u[t][1]&&o.push(u[t][1]),e=e.put.apply(window,o),e.onsuccess=d}},d=function(){s(),c=setInterval(s,t.poll_time)};i.onupgradeneeded=function(t){var e,r=t.target.result;try{e=t.target.transaction.objectStore(n)}catch(o){e=r.createObjectStore(n,{autoIncrement:!0})}try{e.createIndex("k","k",{unique:!0}),e.createIndex("v","v",{unique:!1}),e.transaction.oncomplete=function(t){var e=r.transaction(n,"readwrite").objectStore(n);for(var o in a)e.add(a[o])}}catch(o){}},i.onsuccess=function(t){db=t.target.result,e=db.transaction(n,"readwrite").objectStore(n),d()},this.getItem=function(t){if(!t)throw o+"one arguments required";return u[t+""]?u[t+""][0]:void 0},this.setItem=function(t,e){if(!t||!e)throw o+"two arguments required";l(t,e)}}}return new e}(options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment