forked from RDCNWebs/rd.rdlevel.cn
添加了本地状态记录
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
# 更新信息
|
# 更新信息
|
||||||
|
|
||||||
|
#### 2025-07-21
|
||||||
|
- 添加了本地状态存储
|
||||||
|
|
||||||
#### 2025-07-19
|
#### 2025-07-19
|
||||||
- 补充了目录图标
|
- 补充了目录图标
|
||||||
- 整理并添加了新的板块
|
- 整理并添加了新的板块
|
||||||
|
|||||||
+11
-8
@@ -10,8 +10,11 @@ var ottos = [
|
|||||||
"/images/otto-rd2-xmas-compressed.png",
|
"/images/otto-rd2-xmas-compressed.png",
|
||||||
"/images/otto-traditional.png",
|
"/images/otto-traditional.png",
|
||||||
]
|
]
|
||||||
|
function getCurrentImage() {
|
||||||
|
ottoIndex = (ottoIndex) % ottos.length;
|
||||||
|
return ottos[ottoIndex];
|
||||||
|
}
|
||||||
var ottoIndex = 0;
|
var ottoIndex = 0;
|
||||||
|
|
||||||
function showOtto(callback) {
|
function showOtto(callback) {
|
||||||
node.style.opacity = 1;
|
node.style.opacity = 1;
|
||||||
anim = node.animate([
|
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 => {
|
fetch("tips.json").then(response => response.json()).then(data => {
|
||||||
tipTexts = data;
|
tipTexts = data;
|
||||||
});
|
});
|
||||||
addOtto(document);
|
addOtto(document);
|
||||||
showOtto()
|
showOtto()
|
||||||
}
|
})
|
||||||
|
|
||||||
|
|
||||||
window.$docsify.onOttoShow = function () {
|
window.$docsify.onOttoShow = function () {
|
||||||
@@ -57,9 +60,14 @@ window.$docsify.onOttoShow = function () {
|
|||||||
} else {
|
} else {
|
||||||
hideOtto();
|
hideOtto();
|
||||||
ottoIndex++;
|
ottoIndex++;
|
||||||
|
window.localStorage.setItem('ottoIndex', ottoIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function addOtto(document) {
|
function addOtto(document) {
|
||||||
|
let localStorageOttoIndex = window.localStorage.getItem('ottoIndex');
|
||||||
|
if (localStorageOttoIndex !== null) {
|
||||||
|
ottoIndex = parseInt(localStorageOttoIndex);
|
||||||
|
}
|
||||||
node = document.createElement("div");
|
node = document.createElement("div");
|
||||||
node.className = "otto";
|
node.className = "otto";
|
||||||
image = document.createElement("img");
|
image = document.createElement("img");
|
||||||
@@ -117,8 +125,3 @@ function playTips() {
|
|||||||
function randomTips() {
|
function randomTips() {
|
||||||
return tipTexts[Math.floor(Math.random() * tipTexts.length)];
|
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',
|
svgColor: '#7d7b75',
|
||||||
}
|
}
|
||||||
|
|
||||||
window.$docsify.currentThemeModeIndex = 2;
|
const themeModes = ['light', 'dark', 'auto',]
|
||||||
|
|
||||||
// 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]
|
|
||||||
|
|
||||||
var switchSpan = document.createElement('span')
|
var switchSpan = document.createElement('span')
|
||||||
|
|
||||||
@@ -64,23 +49,17 @@ function plugin(hook, vm) {
|
|||||||
let setThemeMode = function (currentTheme) {
|
let setThemeMode = function (currentTheme) {
|
||||||
switch (currentTheme) {
|
switch (currentTheme) {
|
||||||
case 'light':
|
case 'light':
|
||||||
// lightTheme.disabled = false
|
|
||||||
// darkTheme.disabled = true
|
|
||||||
document.body.classList.remove('dark')
|
document.body.classList.remove('dark')
|
||||||
document.body.classList.add('light')
|
document.body.classList.add('light')
|
||||||
switchSpan.innerHTML = lightModeIconXml
|
switchSpan.innerHTML = lightModeIconXml
|
||||||
break
|
break
|
||||||
case 'dark':
|
case 'dark':
|
||||||
// lightTheme.disabled = true
|
|
||||||
// darkTheme.disabled = false
|
|
||||||
document.body.classList.remove('light')
|
document.body.classList.remove('light')
|
||||||
document.body.classList.add('dark')
|
document.body.classList.add('dark')
|
||||||
switchSpan.innerHTML = darkModeIconXml
|
switchSpan.innerHTML = darkModeIconXml
|
||||||
break
|
break
|
||||||
case 'auto':
|
case 'auto':
|
||||||
var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
|
var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||||
// lightTheme.disabled = isDarkMode
|
|
||||||
// darkTheme.disabled = !isDarkMode
|
|
||||||
if (isDarkMode) {
|
if (isDarkMode) {
|
||||||
document.body.classList.remove('light')
|
document.body.classList.remove('light')
|
||||||
document.body.classList.add('dark')
|
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])
|
setThemeMode(themeModes[currentThemeModeIndex])
|
||||||
let preferredThemeChangeEventListenerFunction = function () {
|
let preferredThemeChangeEventListenerFunction = function () {
|
||||||
if (currentThemeModeIndex === 2) {
|
if (currentThemeModeIndex === 2) {
|
||||||
@@ -111,6 +117,8 @@ function plugin(hook, vm) {
|
|||||||
}
|
}
|
||||||
window.$docsify.currentThemeModeIndex = currentThemeModeIndex
|
window.$docsify.currentThemeModeIndex = currentThemeModeIndex
|
||||||
setThemeMode(themeModes[currentThemeModeIndex])
|
setThemeMode(themeModes[currentThemeModeIndex])
|
||||||
|
window.localStorage.setItem('currentThemeModeIndex', currentThemeModeIndex)
|
||||||
|
console.log('currentThemeModeIndex', window.localStorage.getItem('currentThemeModeIndex'))
|
||||||
if (window.$docsify.onLightDarkModeChange) {
|
if (window.$docsify.onLightDarkModeChange) {
|
||||||
window.$docsify.onLightDarkModeChange();
|
window.$docsify.onLightDarkModeChange();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user