【QuickAdd脚本】为深浅模式配置不同的主题

2024-03-01_Quickadd脚本-为深浅模式配置不同的主题_IMG-1

如果想通过快捷键切换不同的主题,或者一键切换深浅模式,再或者是深浅模式设置不同的主题,可以通过以下 Quickadd 的脚本来实践,以下脚本全部以 Quickadd 的 Macro 来进行配置 (即将代码保存为 js 文件后,在 Quikadd 里面添加对应的 Macro 的动作)。

声明:推荐使用 obsidian-day-and-night 插件

实际上有插件 obsidian-day-and-night,作者:Kevin Patel 就可以实现以上需求,而且可以根据一天的时间来自动切换主题颜色,相比较脚本更加稳定快捷!写脚本只是为了少装插件和一时兴起。

2024-03-01_Quickadd脚本-为深浅模式配置不同的主题_IMG-1

Quickadd 为深浅模式配置不同的主题

2024-03-01_Quickadd脚本-为深浅模式配置不同的主题_IMG-2

如何打开QuickAdd设置示意

2024-03-01_Quickadd脚本-为深浅模式配置不同的主题_IMG-3

Quickadd 切换主题的脚本
// 获取所有主题
const themes = Object.keys(app.customCss.themes);
themes.unshift("default");
const themesMode = ["Auto", "Dark", "Light"];

// 获取当前模式
const light = "moonstone";
const dark = "obsidian";
const currentMode = app.vault.config.theme;

module.exports = {
	entry: async (QuickAdd, settings, params) => {
		const themeName1 = settings["theme 1"];
		const themeMode1 = settings["theme 1 mode"];

		const themeName2 = settings["theme 2"];
		const themeMode2 = settings["theme 2 mode"];
		let themeName = app.customCss.theme;
		let themeMode = "Auto";

		// 更换主题
		if (themeName1 === themeName2) {
			// 如果2个主题相等,则只设置深浅模式变化
			if (currentMode == dark) {
				themeMode = "Light";
			} else if (currentMode == light) {
				themeMode = "Dark";
			}
		}
		else if (themeName !== themeName1) {
			themeName = themeName1;
			themeMode = themeMode1;
			app.customCss.setTheme(themeName);
		} else {
			themeName = themeName2;
			themeMode = themeMode2;
			app.customCss.setTheme(themeName);
		}

		switch (themeMode) {
			case "Auto":
				new Notice(`🌗切换为${themeName}主题`);
				break;
			case "Dark":
				if (currentMode != dark) { //如果当前不是暗色,就切换为暗色
					app.commands.executeCommandById("theme:use-dark");
				}
				new Notice(`🌘切换为${themeName}主题深色模式`);
				break;
			case "Light":
				if (currentMode != light) { //如果当前不是亮色,就切换为亮色
					app.commands.executeCommandById("theme:use-light");
				}
				new Notice(`🌕切换为${themeName}主题浅色模式`);
				break;
		}
	},
	settings: {
		name: "Toggle Theme",
		author: "熊猫别熬夜",
		options: {
			"theme 1": {
				type: "dropdown",
				defaultValue: "Blue Topaz",
				options: themes,
				description: "设置第1个主题",
			},
			"theme 1 mode": {
				type: "select",
				defaultValue: "Auto",
				options: themesMode,
				description: "设置第1个主题的深浅模式,默认Auto为不更改",

			},
			"theme 2": {
				type: "dropdown",
				defaultValue: "default",
				options: themes,
				description: "设置第2个主题",

			},
			"theme 2 mode": {
				type: "select",
				defaultValue: "Auto",
				options: themesMode,
				description: "设置第2个主题的深浅模式,默认Auto为不更改",
			},
		}
	},
};

Reference

楼主的主题是blue topaz? 这个绿色好像没见过 :thinking:

是整体配色的Autumn
image
这个主题的深浅模式都还可以

我的BT Style设置
{
  "blue-topaz-theme@@color-scheme-options": "color-scheme-options-autumn-topaz",
  "blue-topaz-theme@@disable-auto-hide-header": true,
  "blue-topaz-theme@@background-image-settings-switch": true,
  "blue-topaz-theme@@toggle-nonoverlapping-bg": true,
  "blue-topaz-theme@@notebook-liked-markdown-page-options": "notebook-liked-markdown-page-grid-notebook-1",
  "blue-topaz-theme@@bg-panel-page-option": "panel-page-bg-theme-light-custom",
  "blue-topaz-theme@@background-panel-page-theme-light-custom": "\"\"",
  "blue-topaz-theme@@bg-panel-page-option-dark": "panel-page-bg-theme-dark-plant",
  "blue-topaz-theme@@left-ribbon-style": "bt-bubble-ribbon",
  "blue-topaz-theme@@hide-vault-name": true,
  "blue-topaz-theme@@bt-status-on": true,
  "blue-topaz-theme@@scrollbar-style-option": "hover-scrollbars",
  "blue-topaz-theme@@view-button-front": true,
  "blue-topaz-theme@@layout-style-options": "bt-bubble-layout",
  "blue-topaz-theme@@bt-bubble-not-file-tree": true,
  "blue-topaz-theme@@bt-bubble-layout-hide-borders": true,
  "blue-topaz-theme@@bt-bubble-buttons": true,
  "blue-topaz-theme@@bt-bubble-layout-padding": "5px",
  "blue-topaz-theme@@bt-bubble-radius": "10px",
  "blue-topaz-theme@@font-family-change-to-default": true,
  "blue-topaz-theme@@font-size-file-header-title": "0.9375em",
  "blue-topaz-theme@@font-size-code": "0.7em",
  "blue-topaz-theme@@font-size-latex": "0.7em",
  "blue-topaz-theme@@remove-heading-indicator": true,
  "blue-topaz-theme@@h1-size": "1.4m",
  "blue-topaz-theme@@h2-size": "1.2em",
  "blue-topaz-theme@@h3-size": "1.1em",
  "blue-topaz-theme@@h4-size": "1em",
  "blue-topaz-theme@@h5-size": "1em",
  "blue-topaz-theme@@toggle-left-aligned-content": true,
  "blue-topaz-theme@@inline-title-toggle-underline": true,
  "blue-topaz-theme@@inline-title-text-align-settings": "inline-title-text-align-center",
  "blue-topaz-theme@@muted-activeline-bg": true,
  "blue-topaz-theme@@plain-file-title": true,
  "blue-topaz-theme@@title-justify-start": true,
  "blue-topaz-theme@@unordered-list-style-options": "custom-unordered-list",
  "blue-topaz-theme@@colorful-ordered-list": true,
  "blue-topaz-theme@@ordered-list-style-options": "default-ol-list-marker",
  "blue-topaz-theme@@list-style-change-options": "list-no-border",
  "blue-topaz-theme@@rainbow-ordered-list": true,
  "blue-topaz-theme@@rainbow-checkbox": true,
  "blue-topaz-theme@@file-bg-shape-option": "file-shape-default",
  "blue-topaz-theme@@unmuted-collapsed-folder": true,
  "blue-topaz-theme@@folder-style-change-options-colorful": "folder-style-change-options-colorful-default",
  "blue-topaz-theme@@naked-embed": true,
  "blue-topaz-theme@@hide-embed-banner": true,
  "blue-topaz-theme@@toggle-table-transition": true,
  "blue-topaz-theme@@table-format-options": "wrapped-table",
  "blue-topaz-theme@@show-border-table": true,
  "blue-topaz-theme@@table-width": "table-width-100",
  "blue-topaz-theme@@table-style-options": "table-style-default",
  "blue-topaz-theme@@cursor-color@@dark": "#FF0000",
  "blue-topaz-theme@@cursor-color@@light": "#FF0000",
  "blue-topaz-theme@@checkbox-size": "1.5rem",
  "blue-topaz-theme@@unmute-checkbox-animation": true,
  "blue-topaz-theme@@image-zoom": true,
  "blue-topaz-theme@@obsidian-default-image": true,
  "blue-topaz-theme@@tag-click": true,
  "blue-topaz-theme@@head-tag-style": true,
  "blue-topaz-theme@@setting-etc-pane-style": "setting-style-traditional",
  "blue-topaz-theme@@titlebar-close-button": "default-titlebar",
  "blue-topaz-theme@@resizable-mermaid": true,
  "blue-topaz-theme@@toggle-canvas-grid": true,
  "blue-topaz-theme@@canvas-workplace-background": true,
  "blue-topaz-theme@@canvas-background-image": "default-canvas-background",
  "blue-topaz-theme@@canvas-background@@light": "#FFFFFF",
  "blue-topaz-theme@@popover-width-factor": 2,
  "blue-topaz-theme@@popover-height-factor": 1,
  "blue-topaz-theme@@callout-style-settings": "border-callout-style",
  "blue-topaz-theme@@style-options-for-kanban-plugin-static": "style-options-for-kanban-plugin-static-default",
  "blue-topaz-theme@@style-options-for-kanban-plugin-dynamic": "style-options-for-kanban-plugin-dynamic-default"
}

感谢,辛苦了~~晚上回去试试 :grin: