Skip to content

Instantly share code, notes, and snippets.

@elusiveunit
Last active August 29, 2022 22:31
Show Gist options
  • Save elusiveunit/439a53d4af76f1b9c96130b7885162c6 to your computer and use it in GitHub Desktop.
Save elusiveunit/439a53d4af76f1b9c96130b7885162c6 to your computer and use it in GitHub Desktop.
Anki - persistent data between front and back
// 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));
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