diff --git a/src/Common.ts b/src/Common.ts index dd25db3..c02be43 100644 --- a/src/Common.ts +++ b/src/Common.ts @@ -1,3 +1,5 @@ +import { Config, Theme } from "./Config"; + export type BrowserCommandName = "grab_post" | "upload_post" | "push_message" | "remove_messages"; export type MessageType = "error" | "info" | "success"; @@ -40,3 +42,14 @@ export function encodeTagName(tagName: string) { // Searching for posts with re\:zero will show posts tagged with re:zero. return tagName.replace(/:/g, "\\:"); } + +export async function applyTheme(theme?: Theme) { + if (!theme) { + var cfg = await Config.load(); + theme = cfg.theme; + } + if (theme == "system") { + theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; + } + document.documentElement.setAttribute("data-theme", theme); +} diff --git a/src/Config.ts b/src/Config.ts index 628f42e..c896cd6 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -1,5 +1,7 @@ import { browser } from "webextension-polyfill-ts"; +export type Theme = "system" | "light" | "dark"; + export class SzuruSiteConfig { domain = ""; username = ""; @@ -14,11 +16,12 @@ export class Config { autoSearchSimilar = false; loadTagCounts = true; useContentTokens = true; + theme: Theme = "system"; sites: Array = []; public async save() { await browser.storage.local.set({ - config: JSON.stringify(this) + config: JSON.stringify(this), }); console.dir("Save " + JSON.stringify(this)); diff --git a/src/css/style.css b/src/css/style.css index fbc8b74..da95c07 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -1,3 +1,31 @@ +:root { + --button-bg-color: #a2a2a2; + --primary-color: #24aadd; + --bg-main-color: #fff; + --bg-secondary-color: #fafafa; + --border-color: #eee; + --secondary-text: #888; + --error-color: #f44336; + --success-color: #4caf50; + --section-header-fg-color: #4c4c4c; + --section-header-bg-color: #eee; + --text-color: #111; +} + +html[data-theme="dark"] { + --button-bg-color: #666; + --primary-color: #1b87b0; + --bg-main-color: #1a1a1a; + --bg-secondary-color: #3e3e3e; + --border-color: #474747; + --section-header-fg-color: #d9d9d9; + --section-header-bg-color: #272727; + --text-color: #e6e6e6; + + color: var(--text-color); + background-color: var(--bg-main-color); +} + body { margin: 0px; font-family: "Open Sans", sans-serif; @@ -6,7 +34,7 @@ body { } button { - background-color: #a2a2a2; + background-color: var(--button-bg-color); border: none; color: white; font-family: "Open Sans", sans-serif; @@ -17,7 +45,7 @@ button { } button.primary { - background-color: #24aadd; + background-color: var(--primary-color); } input[type="text"] { @@ -26,14 +54,15 @@ input[type="text"] { input[type="text"], textarea { - background-color: #fafafa; - border: 1px solid #eee; + color: var(--text-color); + background-color: var(--bg-secondary-color); + border: 1px solid var(--border-color); width: 100%; } input[type="text"]:focus, textarea:focus { - outline: #24aadd solid 2px; + outline: var(--primary-color) solid 2px; box-sizing: content-box; } @@ -55,8 +84,9 @@ img { } select { - background-color: #fafafa; - border: 1px solid #eee; + color: var(--text-color); + background-color: var(--bg-secondary-color); + border: 1px solid var(--border-color); height: 30px; width: 100%; } @@ -78,7 +108,7 @@ ul.compact, } .tag-general { - color: #24aadd; + color: var(--primary-color); } .tag-copyright { @@ -107,7 +137,7 @@ ul.compact, .remove-tag, .tag-usages { - color: #888; + color: var(--secondary-text); } a.remove-tag { @@ -131,7 +161,7 @@ a.remove-tag { .messages > li { padding: 5px; border-radius: 2px; - background: #24aadd; + background: var(--primary-color); color: white; } @@ -149,9 +179,9 @@ a.remove-tag { } .message-error { - background: #f44336 !important; + background: var(--error-color) !important; } .message-success { - background: #4caf50 !important; + background: var(--success-color) !important; } diff --git a/src/options/App.vue b/src/options/App.vue index d97c0c3..e305c6e 100644 --- a/src/options/App.vue +++ b/src/options/App.vue @@ -7,12 +7,21 @@ @@ -63,7 +72,8 @@ @@ -167,6 +183,10 @@ export default Vue.extend({ padding: 1.8em; } +html[data-theme="dark"] .content-holder > .content-wrapper:not(.transparent) { + background: var(--section-header-bg-color); +} + .settings-footer { display: flex; gap: 5px; @@ -195,7 +215,7 @@ export default Vue.extend({ } .input li { - flex: 1 0 20em; + flex: 1 0 200px; } .input li.full-width { @@ -210,7 +230,7 @@ export default Vue.extend({ .hint { margin-top: 0.2em; margin-bottom: 0; - color: #888; + color: var(--secondary-text); font-size: 80%; line-height: 120%; } @@ -228,10 +248,10 @@ textarea { text-overflow: ellipsis; width: 100%; box-sizing: border-box; - border: 2px solid #eee; - background: #fafafa; - color: #111; + border: 2px solid var(--border-color); + background: var(--bg-secondary-color); + color: var(--text-color); box-shadow: none; - transition: border-color 0.1s linear, background-color 0.1s linear; + /* transition: border-color 0.1s linear, background-color 0.1s linear; */ } diff --git a/src/options/options.ts b/src/options/options.ts index 6dc846a..d29c5f6 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -2,6 +2,9 @@ import "../css/style.css"; import Vue from "vue"; import App from "./App.vue"; +import { applyTheme } from "../Common"; + +applyTheme(); new Vue({ el: "#app", diff --git a/src/popup/App.vue b/src/popup/App.vue index 0c78274..6b7d6b5 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -580,7 +580,7 @@ video { .section-header { height: 30px; padding: 0 6px 0 10px; - background-color: #eee; + background-color: var(--section-header-bg-color); display: flex; justify-content: space-between; @@ -590,6 +590,7 @@ video { .section-header > span { font-size: 1.2em; vertical-align: middle; + color: var(--section-header-fg-color); } .section-row { @@ -612,8 +613,8 @@ video { .autocomplete-items { position: absolute; z-index: 10; - background-color: white; - border: 2px solid #24aadd; + background-color: var(--bg-main-color); + border: 2px solid var(--primary-color); margin-top: 34px; display: none; } @@ -628,19 +629,19 @@ video { } .autocomplete-items > div:hover { - background: #24aadd; + background: var(--primary-color); } .autocomplete-items > div:hover > span { - color: #fff; + color: var(--text-color); } .autocomplete-items > div.active { - background: #24aadd; + background: var(--primary-color); } .autocomplete-items > div.active > span { - color: #fff; + color: var(--text-color); } /* Hacky way to stop the layout from resizing when we lazy load the usage count. */ diff --git a/src/popup/popup.ts b/src/popup/popup.ts index cbfc681..4a90014 100644 --- a/src/popup/popup.ts +++ b/src/popup/popup.ts @@ -4,8 +4,11 @@ import "../css/solid.css"; import Vue from "vue"; import App from "./App.vue"; +import { applyTheme } from "../Common"; + +applyTheme(); new Vue({ el: "#app", - render: h => h(App) + render: (h) => h(App), });