2021-01-23 01:02:56 +08:00
|
|
|
/* global KEEP */
|
|
|
|
|
2020-03-29 19:54:28 +08:00
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
2022-10-17 21:54:21 +08:00
|
|
|
const { version, local_search, code_block, code_copy, lazyload } = KEEP.theme_config
|
2020-11-24 20:06:08 +08:00
|
|
|
|
|
|
|
KEEP.themeInfo = {
|
2022-09-29 21:59:40 +08:00
|
|
|
theme: `Keep v${version}`,
|
2020-11-24 20:06:08 +08:00
|
|
|
author: 'XPoet',
|
|
|
|
repository: 'https://github.com/XPoet/hexo-theme-keep'
|
|
|
|
}
|
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.localStorageKey = 'KEEP-THEME-STATUS'
|
2021-01-23 01:02:56 +08:00
|
|
|
|
|
|
|
KEEP.styleStatus = {
|
|
|
|
isExpandPageWidth: false,
|
|
|
|
isDark: false,
|
2021-01-24 19:54:44 +08:00
|
|
|
fontSizeLevel: 0,
|
2022-10-11 12:37:06 +08:00
|
|
|
isShowToc: true
|
2021-01-23 01:02:56 +08:00
|
|
|
}
|
|
|
|
|
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`,
|
2022-09-30 11:40:30 +08:00
|
|
|
`color: #fadfa3; background: #333; padding: 6px 0;`,
|
|
|
|
`padding: 6px 0;`
|
|
|
|
)
|
2021-01-07 15:23:31 +08:00
|
|
|
}
|
|
|
|
|
2021-01-23 01:02:56 +08:00
|
|
|
// set styleStatus to localStorage
|
|
|
|
KEEP.setStyleStatus = () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
localStorage.setItem(KEEP.localStorageKey, JSON.stringify(KEEP.styleStatus))
|
2021-01-23 01:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// get styleStatus from localStorage
|
|
|
|
KEEP.getStyleStatus = () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
let temp = localStorage.getItem(KEEP.localStorageKey)
|
2021-01-23 01:02:56 +08:00
|
|
|
if (temp) {
|
2022-09-30 11:40:30 +08:00
|
|
|
temp = JSON.parse(temp)
|
2021-01-23 01:02:56 +08:00
|
|
|
for (let key in KEEP.styleStatus) {
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.styleStatus[key] = temp[key]
|
2021-01-23 01:02:56 +08:00
|
|
|
}
|
2022-09-30 11:40:30 +08:00
|
|
|
return temp
|
2021-01-23 01:02:56 +08:00
|
|
|
} else {
|
2022-09-30 11:40:30 +08:00
|
|
|
return null
|
2021-01-23 01:02:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
KEEP.refresh = () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.initUtils()
|
|
|
|
KEEP.initHeaderShrink()
|
|
|
|
KEEP.initModeToggle()
|
|
|
|
KEEP.initBack2Top()
|
2021-01-05 17:01:15 +08:00
|
|
|
|
2022-09-29 21:59:40 +08:00
|
|
|
if (local_search?.enable === true) {
|
2022-09-30 11:40:30 +08:00
|
|
|
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
|
|
|
|
) {
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.initCodeBlockTools()
|
2021-01-05 17:01:15 +08:00
|
|
|
}
|
2021-01-07 15:15:39 +08:00
|
|
|
|
2022-09-29 21:59:40 +08:00
|
|
|
if (lazyload?.enable === true) {
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.initLazyLoad()
|
2021-01-07 15:15:39 +08:00
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
2020-11-24 20:06:08 +08:00
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.printThemeInfo()
|
|
|
|
KEEP.refresh()
|
|
|
|
})
|