Skip to content

Commit

Permalink
Merge pull request #29 from SimonLammer/fix-previews
Browse files Browse the repository at this point in the history
Fix previews
  • Loading branch information
Simon Lammer authored May 25, 2018
2 parents 16d478b + a41d16d commit 2d25c3b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
Binary file modified examples/random-number/anki-persistence-test.apkg
Binary file not shown.
Binary file modified examples/random-number/anki-persistence.apkg
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anki-persistence",
"version": "0.3.0",
"version": "0.4.0",
"description": "Persist data between both sides of an anki flashcard.",
"main": "script.js",
"directories": {
Expand Down
20 changes: 8 additions & 12 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (typeof(window.Persistence) === 'undefined') {
return isAvailable;
};
};
window.Persistence_windowKey = function(persistentKey) {
window.Persistence_windowKey = function(persistentKey) { // used in windows, linux, mac and iOS
var obj = window[persistentKey];
var isAvailable = false;
if (typeof(obj) === 'object') {
Expand Down Expand Up @@ -76,17 +76,13 @@ if (typeof(window.Persistence) === 'undefined') {
return isAvailable;
};
};
var persistentKeys = [
"py", // used in windows
"qt" // used in linux, mac and iOS
];
for (var i = 0; i < persistentKeys.length; i++) {
window.Persistence = new Persistence_windowKey(persistentKeys[i]);
if (window.Persistence.isAvailable()) {
break;
}
}
window.Persistence = new Persistence_sessionStorage(); // android
if (!window.Persistence.isAvailable()) {
window.Persistence = new Persistence_sessionStorage();
var userAgentSubstr = navigator.userAgent.match(/\([^)]*\)/)[0];
if (userAgentSubstr.indexOf("Windows") >= 0) {
window.Persistence = new Persistence_windowKey("py"); // windows
} else if (window.location.toString().indexOf("main") >= 0) { // disable in preview and card editor preview; see https://github.com/SimonLammer/anki-persistence/issues/23
window.Persistence = new Persistence_windowKey("qt"); // linux, mac & iOS
}
}
}

0 comments on commit 2d25c3b

Please sign in to comment.