hexo-theme-keep/source/js/main.js

75 lines
1.6 KiB
JavaScript
Raw Normal View History

/* global KEEP */
window.addEventListener('DOMContentLoaded', () => {
2022-10-17 21:54:21 +08:00
const { version, local_search, code_block, code_copy, lazyload } = KEEP.theme_config
KEEP.themeInfo = {
theme: `Keep v${version}`,
author: 'XPoet',
repository: 'https://github.com/XPoet/hexo-theme-keep'
}
KEEP.localStorageKey = 'KEEP-THEME-STATUS'
KEEP.styleStatus = {
isExpandPageWidth: false,
isDark: false,
fontSizeLevel: 0,
isShowToc: true
}
2021-01-07 15:23:31 +08:00
// print theme base info
KEEP.printThemeInfo = () => {
2022-09-28 10:18:06 +08:00
console.log(
`\n %c ${KEEP.themeInfo.theme} %c ${KEEP.themeInfo.repository} \n`,
`color: #fadfa3; background: #333; padding: 6px 0;`,
`padding: 6px 0;`
)
2021-01-07 15:23:31 +08:00
}
// set styleStatus to localStorage
KEEP.setStyleStatus = () => {
localStorage.setItem(KEEP.localStorageKey, JSON.stringify(KEEP.styleStatus))
}
// get styleStatus from localStorage
KEEP.getStyleStatus = () => {
let temp = localStorage.getItem(KEEP.localStorageKey)
if (temp) {
temp = JSON.parse(temp)
for (let key in KEEP.styleStatus) {
KEEP.styleStatus[key] = temp[key]
}
return temp
} else {
return null
}
}
KEEP.refresh = () => {
KEEP.initUtils()
KEEP.initHeaderShrink()
KEEP.initModeToggle()
KEEP.initBack2Top()
2021-01-05 17:01:15 +08:00
if (local_search?.enable === true) {
KEEP.initLocalSearch()
2021-01-05 17:01:15 +08:00
}
2022-10-20 12:26:19 +08:00
if (
code_block?.tools?.enable === true ||
code_block?.enable === true ||
code_copy?.enable === true
) {
KEEP.initCodeBlockTools()
2021-01-05 17:01:15 +08:00
}
2021-01-07 15:15:39 +08:00
if (lazyload?.enable === true) {
KEEP.initLazyLoad()
2021-01-07 15:15:39 +08:00
}
}
KEEP.printThemeInfo()
KEEP.refresh()
})