Add dark theme + theme switcher
Also has the option to follow the system theme.next v0.8.3
parent
ce70d0dbca
commit
a05f42b5ee
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<SzuruSiteConfig> = [];
|
||||
|
||||
public async save() {
|
||||
await browser.storage.local.set({
|
||||
config: JSON.stringify(this)
|
||||
config: JSON.stringify(this),
|
||||
});
|
||||
|
||||
console.dir("Save " + JSON.stringify(this));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,21 @@
|
|||
|
||||
<ul class="input">
|
||||
<li class="full-width">
|
||||
<label>Szurubooru URL</label><input text="Szurubooru URL" type="text" name="domain" v-model="domain" />
|
||||
<label>Szurubooru URL</label>
|
||||
<input text="Szurubooru URL" type="text" name="domain" v-model="domain" />
|
||||
</li>
|
||||
<li><label>Username</label><input text="Username" type="text" name="username" v-model="username" /></li>
|
||||
<li style="min-width: 320px">
|
||||
<label>Authentication token</label>
|
||||
<input text="Authentication token" type="text" name="token" v-model="authToken" />
|
||||
</li>
|
||||
<li>
|
||||
<label>Authentication token</label
|
||||
><input text="Authentication token" type="text" name="token" v-model="authToken" />
|
||||
<label>Theme</label>
|
||||
<select v-model="theme">
|
||||
<option value="system">System</option>
|
||||
<option value="light">Light</option>
|
||||
<option value="dark">Dark</option>
|
||||
</select>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
|
@ -63,7 +72,8 @@
|
|||
<script lang="ts">
|
||||
import Vue from "vue";
|
||||
import SzuruWrapper from "../SzuruWrapper";
|
||||
import { Config, SzuruSiteConfig } from "../Config";
|
||||
import { Config, SzuruSiteConfig, Theme } from "../Config";
|
||||
import { applyTheme } from "../Common";
|
||||
|
||||
type StatusType = "ok" | "error";
|
||||
|
||||
|
|
@ -77,6 +87,7 @@ export default Vue.extend({
|
|||
loadTagCounts: false,
|
||||
addPageUrlToSource: false,
|
||||
useContentTokens: false,
|
||||
theme: "system" as Theme,
|
||||
statusText: "",
|
||||
statusType: "",
|
||||
};
|
||||
|
|
@ -117,6 +128,7 @@ export default Vue.extend({
|
|||
config.loadTagCounts = this.loadTagCounts;
|
||||
config.addPageUrlToSource = this.addPageUrlToSource;
|
||||
config.useContentTokens = this.useContentTokens;
|
||||
config.theme = this.theme;
|
||||
|
||||
await config.save();
|
||||
|
||||
|
|
@ -143,6 +155,10 @@ export default Vue.extend({
|
|||
this.loadTagCounts = config.loadTagCounts;
|
||||
this.addPageUrlToSource = config.addPageUrlToSource;
|
||||
this.useContentTokens = config.useContentTokens;
|
||||
this.theme = config.theme;
|
||||
},
|
||||
watch: {
|
||||
theme: (value) => applyTheme(value),
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
|
@ -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; */
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue