forked from RDCNWebs/rd.rdlevel.cn
添加了本地状态记录
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
# 更新信息
|
||||
|
||||
#### 2025-07-21
|
||||
- 添加了本地状态存储
|
||||
|
||||
#### 2025-07-19
|
||||
- 补充了目录图标
|
||||
- 整理并添加了新的板块
|
||||
|
||||
+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];
|
||||
}
|
||||
@@ -14,22 +14,7 @@ var switchLightDarkModeOptions = {
|
||||
svgColor: '#7d7b75',
|
||||
}
|
||||
|
||||
window.$docsify.currentThemeModeIndex = 2;
|
||||
|
||||
// Docsify plugin functions
|
||||
function plugin(hook, vm) {
|
||||
|
||||
if (!switchLightDarkModeOptions.useSwitchMode) {
|
||||
return
|
||||
}
|
||||
|
||||
let themeModes = ['light', 'dark', 'auto',]
|
||||
|
||||
let currentThemeModeIndex = 2
|
||||
|
||||
hook.mounted(function () {
|
||||
// let lightTheme = Docsify.dom.findAll('[href="/style/light.css"]')[0]
|
||||
// let darkTheme = Docsify.dom.findAll('[href="/style/dark.css"]')[0]
|
||||
const themeModes = ['light', 'dark', 'auto',]
|
||||
|
||||
var switchSpan = document.createElement('span')
|
||||
|
||||
@@ -64,23 +49,17 @@ function plugin(hook, vm) {
|
||||
let setThemeMode = function (currentTheme) {
|
||||
switch (currentTheme) {
|
||||
case 'light':
|
||||
// lightTheme.disabled = false
|
||||
// darkTheme.disabled = true
|
||||
document.body.classList.remove('dark')
|
||||
document.body.classList.add('light')
|
||||
switchSpan.innerHTML = lightModeIconXml
|
||||
break
|
||||
case 'dark':
|
||||
// lightTheme.disabled = true
|
||||
// darkTheme.disabled = false
|
||||
document.body.classList.remove('light')
|
||||
document.body.classList.add('dark')
|
||||
switchSpan.innerHTML = darkModeIconXml
|
||||
break
|
||||
case 'auto':
|
||||
var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
// lightTheme.disabled = isDarkMode
|
||||
// darkTheme.disabled = !isDarkMode
|
||||
if (isDarkMode) {
|
||||
document.body.classList.remove('light')
|
||||
document.body.classList.add('dark')
|
||||
@@ -94,6 +73,33 @@ function plugin(hook, vm) {
|
||||
}
|
||||
}
|
||||
|
||||
window.$docsify.currentThemeModeIndex = 2;
|
||||
|
||||
// Docsify plugin functions
|
||||
function plugin(hook, vm) {
|
||||
|
||||
if (!switchLightDarkModeOptions.useSwitchMode) {
|
||||
return
|
||||
}
|
||||
|
||||
let localStorageCurrentThemeModeIndex = window.localStorage.getItem('currentThemeModeIndex')
|
||||
let currentThemeModeIndex = 2
|
||||
if (localStorageCurrentThemeModeIndex !== null) {
|
||||
currentThemeModeIndex = parseInt(window.localStorage.getItem('currentThemeModeIndex'))
|
||||
}
|
||||
window.$docsify.currentThemeModeIndex = currentThemeModeIndex
|
||||
console.log(window.localStorage)
|
||||
setThemeMode(themeModes[currentThemeModeIndex])
|
||||
window.localStorage.setItem('currentThemeModeIndex', currentThemeModeIndex)
|
||||
if (window.$docsify.onLightDarkModeChange) {
|
||||
window.$docsify.onLightDarkModeChange();
|
||||
}
|
||||
|
||||
hook.mounted(function () {
|
||||
// let lightTheme = Docsify.dom.findAll('[href="/style/light.css"]')[0]
|
||||
// let darkTheme = Docsify.dom.findAll('[href="/style/dark.css"]')[0]
|
||||
|
||||
|
||||
setThemeMode(themeModes[currentThemeModeIndex])
|
||||
let preferredThemeChangeEventListenerFunction = function () {
|
||||
if (currentThemeModeIndex === 2) {
|
||||
@@ -111,6 +117,8 @@ function plugin(hook, vm) {
|
||||
}
|
||||
window.$docsify.currentThemeModeIndex = currentThemeModeIndex
|
||||
setThemeMode(themeModes[currentThemeModeIndex])
|
||||
window.localStorage.setItem('currentThemeModeIndex', currentThemeModeIndex)
|
||||
console.log('currentThemeModeIndex', window.localStorage.getItem('currentThemeModeIndex'))
|
||||
if (window.$docsify.onLightDarkModeChange) {
|
||||
window.$docsify.onLightDarkModeChange();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user