添加了本地状态记录
This commit is contained in:
+11
-8
@@ -10,8 +10,11 @@ var ottos = [
|
||||
"/images/otto-rd2-xmas-compressed.png",
|
||||
"/images/otto-traditional.png",
|
||||
]
|
||||
function getCurrentImage() {
|
||||
ottoIndex = (ottoIndex) % ottos.length;
|
||||
return ottos[ottoIndex];
|
||||
}
|
||||
var ottoIndex = 0;
|
||||
|
||||
function showOtto(callback) {
|
||||
node.style.opacity = 1;
|
||||
anim = node.animate([
|
||||
@@ -37,13 +40,13 @@ function hideOtto(callback) {
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
window.addEventListener("load", function () {
|
||||
fetch("tips.json").then(response => response.json()).then(data => {
|
||||
tipTexts = data;
|
||||
});
|
||||
addOtto(document);
|
||||
showOtto()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
window.$docsify.onOttoShow = function () {
|
||||
@@ -57,9 +60,14 @@ window.$docsify.onOttoShow = function () {
|
||||
} else {
|
||||
hideOtto();
|
||||
ottoIndex++;
|
||||
window.localStorage.setItem('ottoIndex', ottoIndex);
|
||||
}
|
||||
}
|
||||
function addOtto(document) {
|
||||
let localStorageOttoIndex = window.localStorage.getItem('ottoIndex');
|
||||
if (localStorageOttoIndex !== null) {
|
||||
ottoIndex = parseInt(localStorageOttoIndex);
|
||||
}
|
||||
node = document.createElement("div");
|
||||
node.className = "otto";
|
||||
image = document.createElement("img");
|
||||
@@ -117,8 +125,3 @@ function playTips() {
|
||||
function randomTips() {
|
||||
return tipTexts[Math.floor(Math.random() * tipTexts.length)];
|
||||
}
|
||||
|
||||
function getCurrentImage() {
|
||||
ottoIndex = (ottoIndex) % ottos.length;
|
||||
return ottos[ottoIndex];
|
||||
}
|
||||
Reference in New Issue
Block a user