Last active
August 29, 2022 22:31
-
-
Save elusiveunit/439a53d4af76f1b9c96130b7885162c6 to your computer and use it in GitHub Desktop.
Anki - persistent data between front and back
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
// Inspired by https://github.com/SimonLammer/anki-persistence | |
// A much dumber variant to reduce the amount of code on the card. | |
// Basically just native sessionStorage and a global object | |
// fallback with a matching API. | |
window.valueStore = (function (win) { | |
try { | |
return win.sessionStorage; | |
} catch (e) {} | |
win.vso = win.vso || {}; | |
return { | |
setItem: function (key, val) { | |
win.vso[key] = String(val); | |
}, | |
getItem: function (key) { | |
return win.vso[key]; | |
}, | |
removeItem: function (key) { | |
delete win.vso[key]; | |
}, | |
clear: function () { | |
for (k in win.vso) { | |
delete win.vso[k]; | |
} | |
} | |
}; | |
}(window)); |
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
window.valueStore=function(w){try{return w.sessionStorage}catch(e){}return w.vso=w.vso||{},{setItem:function(k,v){w.vso[k]=String(v)},getItem:function(k){return w.vso[k]},removeItem:function(k){delete w.vso[k]},clear:function(){for(k in w.vso)delete w.vso[k]}}}(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment