Skip to content

Commit

Permalink
without localStorage for lower version of Anki
Browse files Browse the repository at this point in the history
  • Loading branch information
krmanik committed Oct 4, 2022
1 parent 876ff12 commit 752efdb
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 81 deletions.
23 changes: 15 additions & 8 deletions card templates/Card 1/back.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

<div id="char_meaning" class="meaning-card">{{Meaning}}</div>

<script>
// v1.0.0 - https://github.com/SimonLammer/anki-persistence/blob/eeb2e1a9e37c941dd63e1fe6c2a257f043c40e0d/script.js
if(void 0===window.Persistence){var _persistenceKey="github.com/SimonLammer/anki-persistence/",_defaultKey="_default";if(window.Persistence_sessionStorage=function(){var e=!1;try{"object"==typeof window.sessionStorage&&(e=!0,this.clear=function(){for(var e=0;e<sessionStorage.length;e++){var t=sessionStorage.key(e);0==t.indexOf(_persistenceKey)&&(sessionStorage.removeItem(t),e--)}},this.setItem=function(e,t){null==t&&(t=e,e=_defaultKey),sessionStorage.setItem(_persistenceKey+e,JSON.stringify(t))},this.getItem=function(e){return null==e&&(e=_defaultKey),JSON.parse(sessionStorage.getItem(_persistenceKey+e))},this.removeItem=function(e){null==e&&(e=_defaultKey),sessionStorage.removeItem(_persistenceKey+e)})}catch(e){}this.isAvailable=function(){return e}},window.Persistence_windowKey=function(e){var t=window[e],n=!1;"object"==typeof t&&(n=!0,this.clear=function(){t[_persistenceKey]={}},this.setItem=function(e,n){null==n&&(n=e,e=_defaultKey),t[_persistenceKey][e]=n},this.getItem=function(e){return null==e&&(e=_defaultKey),null==t[_persistenceKey][e]?null:t[_persistenceKey][e]},this.removeItem=function(e){null==e&&(e=_defaultKey),delete t[_persistenceKey][e]},null==t[_persistenceKey]&&this.clear()),this.isAvailable=function(){return n}},window.Persistence=new Persistence_sessionStorage,Persistence.isAvailable()||(window.Persistence=new Persistence_windowKey("py")),!Persistence.isAvailable()){var titleStartIndex=window.location.toString().indexOf("title"),titleContentIndex=window.location.toString().indexOf("main",titleStartIndex);titleStartIndex>0&&titleContentIndex>0&&titleContentIndex-titleStartIndex<10&&(window.Persistence=new Persistence_windowKey("qt"))}}
</script>

<!--sidebar-->
<script>
function completeAudio() {
Expand All @@ -42,7 +47,7 @@
function initSwitchPrefs() {
for (var _id of switchIdList) {
var divId = _id.replace("text-", "char_");
if (localStorage.getItem(_id) == "false") {
if (Persistence.getItem(_id) == "false") {
document.getElementById(_id).checked = false;
document.getElementById(divId).style.display = "none";
if (_id == "text-pinyin") {
Expand All @@ -53,14 +58,14 @@
}
} else {
document.getElementById(_id).checked = true;
localStorage.setItem(_id, "true");
Persistence.setItem(_id, "true");
}
}
}

function setPrefs(e) {
if (e.type == "checkbox") {
localStorage.setItem(e.id, e.checked);
Persistence.setItem(e.id, e.checked.toString());
var divId = e.id.replace("text-", "char_");
if (e.checked) {
document.getElementById(divId).style.display = "block";
Expand Down Expand Up @@ -126,10 +131,12 @@
}
});

if (document.querySelector(".win")) {
initSwitchPrefs();
} else {
window.addEventListener("load", initSwitchPrefs, false);
if (Persistence.isAvailable()) {
if (document.querySelector(".win")) {
initSwitchPrefs();
} else {
window.addEventListener("load", initSwitchPrefs, false);
}
}
</script>

Expand Down Expand Up @@ -232,4 +239,4 @@ <h3>xie hanzi</h3>
<small>Tatoeba</small>
</a>
</div>
<!----------->
<!-----sidebar------>
18 changes: 15 additions & 3 deletions card templates/Card 1/front.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="header">What is the <span class="question">meanings</span>?</div>
<div class="header">What is the <span class="question-sub-text">meanings</span>?</div>

<br>

Expand All @@ -7,15 +7,27 @@
<div id="char_sim" class="char-card">{{Simplified}}</div>
<div id="char_trad" class="char-card">{{Traditional}}</div>

<script>
// v1.0.0 - https://github.com/SimonLammer/anki-persistence/blob/eeb2e1a9e37c941dd63e1fe6c2a257f043c40e0d/script.js
if(void 0===window.Persistence){var _persistenceKey="github.com/SimonLammer/anki-persistence/",_defaultKey="_default";if(window.Persistence_sessionStorage=function(){var e=!1;try{"object"==typeof window.sessionStorage&&(e=!0,this.clear=function(){for(var e=0;e<sessionStorage.length;e++){var t=sessionStorage.key(e);0==t.indexOf(_persistenceKey)&&(sessionStorage.removeItem(t),e--)}},this.setItem=function(e,t){null==t&&(t=e,e=_defaultKey),sessionStorage.setItem(_persistenceKey+e,JSON.stringify(t))},this.getItem=function(e){return null==e&&(e=_defaultKey),JSON.parse(sessionStorage.getItem(_persistenceKey+e))},this.removeItem=function(e){null==e&&(e=_defaultKey),sessionStorage.removeItem(_persistenceKey+e)})}catch(e){}this.isAvailable=function(){return e}},window.Persistence_windowKey=function(e){var t=window[e],n=!1;"object"==typeof t&&(n=!0,this.clear=function(){t[_persistenceKey]={}},this.setItem=function(e,n){null==n&&(n=e,e=_defaultKey),t[_persistenceKey][e]=n},this.getItem=function(e){return null==e&&(e=_defaultKey),null==t[_persistenceKey][e]?null:t[_persistenceKey][e]},this.removeItem=function(e){null==e&&(e=_defaultKey),delete t[_persistenceKey][e]},null==t[_persistenceKey]&&this.clear()),this.isAvailable=function(){return n}},window.Persistence=new Persistence_sessionStorage,Persistence.isAvailable()||(window.Persistence=new Persistence_windowKey("py")),!Persistence.isAvailable()){var titleStartIndex=window.location.toString().indexOf("title"),titleContentIndex=window.location.toString().indexOf("main",titleStartIndex);titleStartIndex>0&&titleContentIndex>0&&titleContentIndex-titleStartIndex<10&&(window.Persistence=new Persistence_windowKey("qt"))}}
</script>

<script>
var switchIdList = ["text-pinyin", "text-zhuyin", "text-meaning", "text-sim", "text-trad"];
function initSwitchPrefs() {
for (var _id of switchIdList) {
var divId = _id.replace("text-", "char_");
if (localStorage.getItem(_id) == "false") {
if (Persistence.getItem(_id) == "false") {
document.getElementById(divId).style.display = "none";
}
}
}
initSwitchPrefs();

if (Persistence.isAvailable()) {
if (document.querySelector(".win")) {
initSwitchPrefs();
} else {
window.addEventListener("load", initSwitchPrefs, false);
}
}
</script>
23 changes: 15 additions & 8 deletions card templates/Card 2/back.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

<div id="char_meaning" class="meaning-card">{{Meaning}}</div>

<script>
// v1.0.0 - https://github.com/SimonLammer/anki-persistence/blob/eeb2e1a9e37c941dd63e1fe6c2a257f043c40e0d/script.js
if(void 0===window.Persistence){var _persistenceKey="github.com/SimonLammer/anki-persistence/",_defaultKey="_default";if(window.Persistence_sessionStorage=function(){var e=!1;try{"object"==typeof window.sessionStorage&&(e=!0,this.clear=function(){for(var e=0;e<sessionStorage.length;e++){var t=sessionStorage.key(e);0==t.indexOf(_persistenceKey)&&(sessionStorage.removeItem(t),e--)}},this.setItem=function(e,t){null==t&&(t=e,e=_defaultKey),sessionStorage.setItem(_persistenceKey+e,JSON.stringify(t))},this.getItem=function(e){return null==e&&(e=_defaultKey),JSON.parse(sessionStorage.getItem(_persistenceKey+e))},this.removeItem=function(e){null==e&&(e=_defaultKey),sessionStorage.removeItem(_persistenceKey+e)})}catch(e){}this.isAvailable=function(){return e}},window.Persistence_windowKey=function(e){var t=window[e],n=!1;"object"==typeof t&&(n=!0,this.clear=function(){t[_persistenceKey]={}},this.setItem=function(e,n){null==n&&(n=e,e=_defaultKey),t[_persistenceKey][e]=n},this.getItem=function(e){return null==e&&(e=_defaultKey),null==t[_persistenceKey][e]?null:t[_persistenceKey][e]},this.removeItem=function(e){null==e&&(e=_defaultKey),delete t[_persistenceKey][e]},null==t[_persistenceKey]&&this.clear()),this.isAvailable=function(){return n}},window.Persistence=new Persistence_sessionStorage,Persistence.isAvailable()||(window.Persistence=new Persistence_windowKey("py")),!Persistence.isAvailable()){var titleStartIndex=window.location.toString().indexOf("title"),titleContentIndex=window.location.toString().indexOf("main",titleStartIndex);titleStartIndex>0&&titleContentIndex>0&&titleContentIndex-titleStartIndex<10&&(window.Persistence=new Persistence_windowKey("qt"))}}
</script>

<!--sidebar-->
<script>
function completeAudio() {
Expand All @@ -42,7 +47,7 @@
function initSwitchPrefs() {
for (var _id of switchIdList) {
var divId = _id.replace("text-", "char_");
if (localStorage.getItem(_id) == "false") {
if (Persistence.getItem(_id) == "false") {
document.getElementById(_id).checked = false;
document.getElementById(divId).style.display = "none";
if (_id == "text-pinyin") {
Expand All @@ -53,14 +58,14 @@
}
} else {
document.getElementById(_id).checked = true;
localStorage.setItem(_id, "true");
Persistence.setItem(_id, "true");
}
}
}

function setPrefs(e) {
if (e.type == "checkbox") {
localStorage.setItem(e.id, e.checked);
Persistence.setItem(e.id, e.checked.toString());
var divId = e.id.replace("text-", "char_");
if (e.checked) {
document.getElementById(divId).style.display = "block";
Expand Down Expand Up @@ -126,10 +131,12 @@
}
});

if (document.querySelector(".win")) {
initSwitchPrefs();
} else {
window.addEventListener("load", initSwitchPrefs, false);
if (Persistence.isAvailable()) {
if (document.querySelector(".win")) {
initSwitchPrefs();
} else {
window.addEventListener("load", initSwitchPrefs, false);
}
}
</script>

Expand Down Expand Up @@ -232,4 +239,4 @@ <h3>xie hanzi</h3>
<small>Tatoeba</small>
</a>
</div>
<!----------->
<!-----sidebar------>
39 changes: 23 additions & 16 deletions card templates/Card 2/front.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
<div class="header">What is the <span class="question">pinyin & zhuyin</span>?</div>
<div class="header">What is the <span class="question-sub-text">pinyin & zhuyin</span>?</div>

<br>

<div id="char_sim" class="char-card">{{Simplified}}</div>
<div id="char_trad" class="char-card">{{Traditional}}</div>

<script>
if (localStorage.getItem("text-pinyin") == "true" && localStorage.getItem("text-zhuyin") == "false") {
document.querySelector(".question").innerHTML = "pinyin";
} else if (localStorage.getItem("text-pinyin") == "false" && localStorage.getItem("text-zhuyin") == "true") {
document.querySelector(".question").innerHTML = "zhuyin";
} else {
document.querySelector(".question").innerHTML = "pinyin & zhuyin";
}
// v1.0.0 - https://github.com/SimonLammer/anki-persistence/blob/eeb2e1a9e37c941dd63e1fe6c2a257f043c40e0d/script.js
if (void 0 === window.Persistence) { var _persistenceKey = "github.com/SimonLammer/anki-persistence/", _defaultKey = "_default"; if (window.Persistence_sessionStorage = function () { var e = !1; try { "object" == typeof window.sessionStorage && (e = !0, this.clear = function () { for (var e = 0; e < sessionStorage.length; e++) { var t = sessionStorage.key(e); 0 == t.indexOf(_persistenceKey) && (sessionStorage.removeItem(t), e--) } }, this.setItem = function (e, t) { null == t && (t = e, e = _defaultKey), sessionStorage.setItem(_persistenceKey + e, JSON.stringify(t)) }, this.getItem = function (e) { return null == e && (e = _defaultKey), JSON.parse(sessionStorage.getItem(_persistenceKey + e)) }, this.removeItem = function (e) { null == e && (e = _defaultKey), sessionStorage.removeItem(_persistenceKey + e) }) } catch (e) { } this.isAvailable = function () { return e } }, window.Persistence_windowKey = function (e) { var t = window[e], n = !1; "object" == typeof t && (n = !0, this.clear = function () { t[_persistenceKey] = {} }, this.setItem = function (e, n) { null == n && (n = e, e = _defaultKey), t[_persistenceKey][e] = n }, this.getItem = function (e) { return null == e && (e = _defaultKey), null == t[_persistenceKey][e] ? null : t[_persistenceKey][e] }, this.removeItem = function (e) { null == e && (e = _defaultKey), delete t[_persistenceKey][e] }, null == t[_persistenceKey] && this.clear()), this.isAvailable = function () { return n } }, window.Persistence = new Persistence_sessionStorage, Persistence.isAvailable() || (window.Persistence = new Persistence_windowKey("py")), !Persistence.isAvailable()) { var titleStartIndex = window.location.toString().indexOf("title"), titleContentIndex = window.location.toString().indexOf("main", titleStartIndex); titleStartIndex > 0 && titleContentIndex > 0 && titleContentIndex - titleStartIndex < 10 && (window.Persistence = new Persistence_windowKey("qt")) } }
</script>

var pinyinList = document.querySelectorAll(".pinyin");
for (var pinyin of pinyinList) {
pinyin.style.display = "none";
}
<script>
if (Persistence.isAvailable()) {
if (Persistence.getItem("text-pinyin") == "true" && Persistence.getItem("text-zhuyin") == "false") {
document.querySelector(".question").innerHTML = "pinyin";
} else if (Persistence.getItem("text-pinyin") == "false" && Persistence.getItem("text-zhuyin") == "true") {
document.querySelector(".question").innerHTML = "zhuyin";
} else {
document.querySelector(".question").innerHTML = "pinyin & zhuyin";
}
}

var pinyinList = document.querySelectorAll(".pinyin");
for (var pinyin of pinyinList) {
pinyin.style.display = "none";
}

var zhuyinList = document.querySelectorAll(".zhuyin");
for (var zhuyin of zhuyinList) {
zhuyin.style.display = "none";
}
var zhuyinList = document.querySelectorAll(".zhuyin");
for (var zhuyin of zhuyinList) {
zhuyin.style.display = "none";
}
</script>
23 changes: 15 additions & 8 deletions card templates/Card 3/back.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

<div id="char_meaning" class="meaning-card">{{Meaning}}</div>

<script>
// v1.0.0 - https://github.com/SimonLammer/anki-persistence/blob/eeb2e1a9e37c941dd63e1fe6c2a257f043c40e0d/script.js
if(void 0===window.Persistence){var _persistenceKey="github.com/SimonLammer/anki-persistence/",_defaultKey="_default";if(window.Persistence_sessionStorage=function(){var e=!1;try{"object"==typeof window.sessionStorage&&(e=!0,this.clear=function(){for(var e=0;e<sessionStorage.length;e++){var t=sessionStorage.key(e);0==t.indexOf(_persistenceKey)&&(sessionStorage.removeItem(t),e--)}},this.setItem=function(e,t){null==t&&(t=e,e=_defaultKey),sessionStorage.setItem(_persistenceKey+e,JSON.stringify(t))},this.getItem=function(e){return null==e&&(e=_defaultKey),JSON.parse(sessionStorage.getItem(_persistenceKey+e))},this.removeItem=function(e){null==e&&(e=_defaultKey),sessionStorage.removeItem(_persistenceKey+e)})}catch(e){}this.isAvailable=function(){return e}},window.Persistence_windowKey=function(e){var t=window[e],n=!1;"object"==typeof t&&(n=!0,this.clear=function(){t[_persistenceKey]={}},this.setItem=function(e,n){null==n&&(n=e,e=_defaultKey),t[_persistenceKey][e]=n},this.getItem=function(e){return null==e&&(e=_defaultKey),null==t[_persistenceKey][e]?null:t[_persistenceKey][e]},this.removeItem=function(e){null==e&&(e=_defaultKey),delete t[_persistenceKey][e]},null==t[_persistenceKey]&&this.clear()),this.isAvailable=function(){return n}},window.Persistence=new Persistence_sessionStorage,Persistence.isAvailable()||(window.Persistence=new Persistence_windowKey("py")),!Persistence.isAvailable()){var titleStartIndex=window.location.toString().indexOf("title"),titleContentIndex=window.location.toString().indexOf("main",titleStartIndex);titleStartIndex>0&&titleContentIndex>0&&titleContentIndex-titleStartIndex<10&&(window.Persistence=new Persistence_windowKey("qt"))}}
</script>

<!--sidebar-->
<script>
function completeAudio() {
Expand All @@ -42,7 +47,7 @@
function initSwitchPrefs() {
for (var _id of switchIdList) {
var divId = _id.replace("text-", "char_");
if (localStorage.getItem(_id) == "false") {
if (Persistence.getItem(_id) == "false") {
document.getElementById(_id).checked = false;
document.getElementById(divId).style.display = "none";
if (_id == "text-pinyin") {
Expand All @@ -53,14 +58,14 @@
}
} else {
document.getElementById(_id).checked = true;
localStorage.setItem(_id, "true");
Persistence.setItem(_id, "true");
}
}
}

function setPrefs(e) {
if (e.type == "checkbox") {
localStorage.setItem(e.id, e.checked);
Persistence.setItem(e.id, e.checked.toString());
var divId = e.id.replace("text-", "char_");
if (e.checked) {
document.getElementById(divId).style.display = "block";
Expand Down Expand Up @@ -126,10 +131,12 @@
}
});

if (document.querySelector(".win")) {
initSwitchPrefs();
} else {
window.addEventListener("load", initSwitchPrefs, false);
if (Persistence.isAvailable()) {
if (document.querySelector(".win")) {
initSwitchPrefs();
} else {
window.addEventListener("load", initSwitchPrefs, false);
}
}
</script>

Expand Down Expand Up @@ -232,4 +239,4 @@ <h3>xie hanzi</h3>
<small>Tatoeba</small>
</a>
</div>
<!----------->
<!-----sidebar------>
Loading

0 comments on commit 752efdb

Please sign in to comment.