/*
* @Author: pikapikapikaori pikapikapi_kaori@icloud.com
* @Date: 2023-04-30 12:57:52
* @LastEditors: pikapikapikaori pikapikapi_kaori@icloud.com
* @LastEditTime: 2023-05-05 22:29:02
* @FilePath: /pikapikapi-blog/docs/utils/countWords.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
// default values
var switchLightDarkModeOptions = {
useSwitchMode: true,
top: 130,
right: 26,
svgColor: '#7d7b75',
}
const themeModes = ['light', 'dark', 'auto',]
var switchSpan = document.createElement('span')
switchSpan.id = 'switchLightDarkModeDivBeforeArticle'
switchSpan.classList.add('controlSpan')
switchSpan.style.position = 'fixed'
switchSpan.style.right = switchLightDarkModeOptions.right.toString() + 'px'
switchSpan.style.top = switchLightDarkModeOptions.top.toString() + 'px'
const lightModeIconXml = ''
const darkModeIconXml = ''
const autoModeIconXml = ''
const zoomInIconXml = ''
const zoomOutIconXml = ''
const zoomDefaultIconXml = ''
const ottoIconXml = `
`
let setThemeMode = function (currentTheme) {
switch (currentTheme) {
case 'light':
document.body.classList.remove('dark')
document.body.classList.add('light')
switchSpan.innerHTML = lightModeIconXml
break
case 'dark':
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
if (isDarkMode) {
document.body.classList.remove('light')
document.body.classList.add('dark')
}
else {
document.body.classList.remove('dark')
document.body.classList.add('light')
}
switchSpan.innerHTML = autoModeIconXml
break
}
}
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
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) {
setThemeMode(themeModes[currentThemeModeIndex])
}
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', preferredThemeChangeEventListenerFunction)
switchSpan.onclick = function (e) {
if (currentThemeModeIndex === 2) {
currentThemeModeIndex = 0
}
else {
currentThemeModeIndex ++
}
window.$docsify.currentThemeModeIndex = currentThemeModeIndex
setThemeMode(themeModes[currentThemeModeIndex])
window.localStorage.setItem('currentThemeModeIndex', currentThemeModeIndex)
if (window.$docsify.onLightDarkModeChange) {
window.$docsify.onLightDarkModeChange();
}
}
var zoomInSpan = document.createElement('span')
zoomInSpan.id = 'zoomInSpan'
zoomInSpan.classList.add('controlSpan')
zoomInSpan.style.position = 'fixed'
zoomInSpan.style.right = switchLightDarkModeOptions.right.toString() + 'px'
zoomInSpan.style.top = (switchLightDarkModeOptions.top + 35).toString() + 'px'
zoomInSpan.innerHTML = zoomInIconXml
var zoomOutSpan = document.createElement('span')
zoomOutSpan.id = 'zoomOutSpan'
zoomOutSpan.classList.add('controlSpan')
zoomOutSpan.style.position = 'fixed'
zoomOutSpan.style.right = switchLightDarkModeOptions.right.toString() + 'px'
zoomOutSpan.style.top = (switchLightDarkModeOptions.top + 70).toString() + 'px'
zoomOutSpan.innerHTML = zoomOutIconXml
var zoomDefaultSpan = document.createElement('span')
zoomDefaultSpan.id = 'zoomDefaultSpan'
zoomDefaultSpan.classList.add('controlSpan')
zoomDefaultSpan.style.position = 'fixed'
zoomDefaultSpan.style.right = switchLightDarkModeOptions.right.toString() + 'px'
zoomDefaultSpan.style.top = (switchLightDarkModeOptions.top + 105).toString() + 'px'
zoomDefaultSpan.innerHTML = zoomDefaultIconXml
var ottoSpan = document.createElement('span')
ottoSpan.id = 'ottoSpan'
ottoSpan.classList.add('controlSpan')
ottoSpan.style.position = 'fixed'
ottoSpan.style.right = switchLightDarkModeOptions.right.toString() + 'px'
ottoSpan.style.top = (switchLightDarkModeOptions.top + 140).toString() + 'px'
ottoSpan.innerHTML = ottoIconXml
let defaultSize = 1.0
let currentSize = defaultSize
function set(targetSize) {
document.body.style.zoom = targetSize
document.body.style.cssText += '; -moz-transform: scale(' + targetSize + ');-moz-transform-origin: 0 0; '
}
function showOtto(show) {
window.$docsify.onOttoShow(show)
}
zoomInSpan.onclick = function () {
currentSize = currentSize + 0.1
set(currentSize)
}
zoomOutSpan.onclick = function () {
currentSize = currentSize - 0.1
set(currentSize)
}
zoomDefaultSpan.onclick = function () {
currentSize = defaultSize
set(currentSize)
}
ottoSpan.onclick = function () {
showOtto()
}
document.body.appendChild(switchSpan)
document.body.appendChild(zoomInSpan)
document.body.appendChild(zoomOutSpan)
document.body.appendChild(zoomDefaultSpan)
document.body.appendChild(ottoSpan)
})
}
// Docsify plugin options
window.$docsify['switchLightDarkMode'] = Object.assign(
switchLightDarkModeOptions,
window.$docsify['switchLightDarkMode']
)
window.$docsify.plugins = [].concat(plugin, window.$docsify.plugins)