添加了本地状态记录

This commit is contained in:
OLDREDSTONE
2025-07-21 00:48:56 +08:00
parent 239e15c01d
commit ac39d732b7
3 changed files with 81 additions and 67 deletions
+11 -8
View File
@@ -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];
}