Skip to content

Commit

Permalink
Update plugin-custom-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayideyia committed Sep 21, 2024
1 parent e1206e2 commit a5d5f67
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
35 changes: 26 additions & 9 deletions plugins/Generic/plugin-custom-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,35 @@ const onRun = async () => {
}

/**
* 插件钩子 - 右键:下个背景
* 插件钩子 - 右键:选取背景
*/
const Next = async () => {
const Select = async () => {
const config = JSON.parse(await Plugins.Readfile(THEME_FILE))

if (config.backgroundIndex++ >= BackgroundList.length - 1) {
config.backgroundIndex = 0
const backgroundColor = document.body.style.backgroundColor
const backgroundImage = document.body.style.backgroundImage
try {
const { index } = await Plugins.picker.single(
'请选择背景',
BackgroundList.map((theme, index) => {
return {
label: '背景' + (index + 1),
value: { theme, index },
background: theme[1],
onSelect: ({ value }) => {
document.body.style.backgroundColor = value.theme[0]
document.body.style.backgroundImage = value.theme[1]
}
}
}),
[]
)
config.backgroundIndex = index
await Plugins.Writefile(THEME_FILE, JSON.stringify(config, null, 2))
await setBackground(config)
} catch (error) {
document.body.style.backgroundColor = backgroundColor
document.body.style.backgroundImage = backgroundImage
}

await Plugins.Writefile(THEME_FILE, JSON.stringify(config, null, 2))

await setBackground(config)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@
"path": "data/plugins/plugin-custom-theme.js",
"triggers": ["on::manual", "on::ready"],
"menus": {
"下个背景": "Next",
"选择背景": "Select",
"清除主题": "Clear",
"重置配置": "Reset"
},
Expand Down

0 comments on commit a5d5f67

Please sign in to comment.