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 BrowserCommandName = "grab_post" | "upload_post" | "push_message" | "remove_messages";
|
||||||
export type MessageType = "error" | "info" | "success";
|
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.
|
// Searching for posts with re\:zero will show posts tagged with re:zero.
|
||||||
return tagName.replace(/:/g, "\\:");
|
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";
|
import { browser } from "webextension-polyfill-ts";
|
||||||
|
|
||||||
|
export type Theme = "system" | "light" | "dark";
|
||||||
|
|
||||||
export class SzuruSiteConfig {
|
export class SzuruSiteConfig {
|
||||||
domain = "";
|
domain = "";
|
||||||
username = "";
|
username = "";
|
||||||
|
|
@ -14,11 +16,12 @@ export class Config {
|
||||||
autoSearchSimilar = false;
|
autoSearchSimilar = false;
|
||||||
loadTagCounts = true;
|
loadTagCounts = true;
|
||||||
useContentTokens = true;
|
useContentTokens = true;
|
||||||
|
theme: Theme = "system";
|
||||||
sites: Array<SzuruSiteConfig> = [];
|
sites: Array<SzuruSiteConfig> = [];
|
||||||
|
|
||||||
public async save() {
|
public async save() {
|
||||||
await browser.storage.local.set({
|
await browser.storage.local.set({
|
||||||
config: JSON.stringify(this)
|
config: JSON.stringify(this),
|
||||||
});
|
});
|
||||||
|
|
||||||
console.dir("Save " + 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 {
|
body {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
font-family: "Open Sans", sans-serif;
|
font-family: "Open Sans", sans-serif;
|
||||||
|
|
@ -6,7 +34,7 @@ body {
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
background-color: #a2a2a2;
|
background-color: var(--button-bg-color);
|
||||||
border: none;
|
border: none;
|
||||||
color: white;
|
color: white;
|
||||||
font-family: "Open Sans", sans-serif;
|
font-family: "Open Sans", sans-serif;
|
||||||
|
|
@ -17,7 +45,7 @@ button {
|
||||||
}
|
}
|
||||||
|
|
||||||
button.primary {
|
button.primary {
|
||||||
background-color: #24aadd;
|
background-color: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="text"] {
|
input[type="text"] {
|
||||||
|
|
@ -26,14 +54,15 @@ input[type="text"] {
|
||||||
|
|
||||||
input[type="text"],
|
input[type="text"],
|
||||||
textarea {
|
textarea {
|
||||||
background-color: #fafafa;
|
color: var(--text-color);
|
||||||
border: 1px solid #eee;
|
background-color: var(--bg-secondary-color);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="text"]:focus,
|
input[type="text"]:focus,
|
||||||
textarea:focus {
|
textarea:focus {
|
||||||
outline: #24aadd solid 2px;
|
outline: var(--primary-color) solid 2px;
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,8 +84,9 @@ img {
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
background-color: #fafafa;
|
color: var(--text-color);
|
||||||
border: 1px solid #eee;
|
background-color: var(--bg-secondary-color);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
height: 30px;
|
height: 30px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +108,7 @@ ul.compact,
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-general {
|
.tag-general {
|
||||||
color: #24aadd;
|
color: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-copyright {
|
.tag-copyright {
|
||||||
|
|
@ -107,7 +137,7 @@ ul.compact,
|
||||||
|
|
||||||
.remove-tag,
|
.remove-tag,
|
||||||
.tag-usages {
|
.tag-usages {
|
||||||
color: #888;
|
color: var(--secondary-text);
|
||||||
}
|
}
|
||||||
|
|
||||||
a.remove-tag {
|
a.remove-tag {
|
||||||
|
|
@ -131,7 +161,7 @@ a.remove-tag {
|
||||||
.messages > li {
|
.messages > li {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
background: #24aadd;
|
background: var(--primary-color);
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,9 +179,9 @@ a.remove-tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-error {
|
.message-error {
|
||||||
background: #f44336 !important;
|
background: var(--error-color) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-success {
|
.message-success {
|
||||||
background: #4caf50 !important;
|
background: var(--success-color) !important;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,21 @@
|
||||||
|
|
||||||
<ul class="input">
|
<ul class="input">
|
||||||
<li class="full-width">
|
<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>
|
||||||
<li><label>Username</label><input text="Username" type="text" name="username" v-model="username" /></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>
|
<li>
|
||||||
<label>Authentication token</label
|
<label>Theme</label>
|
||||||
><input text="Authentication token" type="text" name="token" v-model="authToken" />
|
<select v-model="theme">
|
||||||
|
<option value="system">System</option>
|
||||||
|
<option value="light">Light</option>
|
||||||
|
<option value="dark">Dark</option>
|
||||||
|
</select>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
@ -63,7 +72,8 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
import SzuruWrapper from "../SzuruWrapper";
|
import SzuruWrapper from "../SzuruWrapper";
|
||||||
import { Config, SzuruSiteConfig } from "../Config";
|
import { Config, SzuruSiteConfig, Theme } from "../Config";
|
||||||
|
import { applyTheme } from "../Common";
|
||||||
|
|
||||||
type StatusType = "ok" | "error";
|
type StatusType = "ok" | "error";
|
||||||
|
|
||||||
|
|
@ -77,6 +87,7 @@ export default Vue.extend({
|
||||||
loadTagCounts: false,
|
loadTagCounts: false,
|
||||||
addPageUrlToSource: false,
|
addPageUrlToSource: false,
|
||||||
useContentTokens: false,
|
useContentTokens: false,
|
||||||
|
theme: "system" as Theme,
|
||||||
statusText: "",
|
statusText: "",
|
||||||
statusType: "",
|
statusType: "",
|
||||||
};
|
};
|
||||||
|
|
@ -117,6 +128,7 @@ export default Vue.extend({
|
||||||
config.loadTagCounts = this.loadTagCounts;
|
config.loadTagCounts = this.loadTagCounts;
|
||||||
config.addPageUrlToSource = this.addPageUrlToSource;
|
config.addPageUrlToSource = this.addPageUrlToSource;
|
||||||
config.useContentTokens = this.useContentTokens;
|
config.useContentTokens = this.useContentTokens;
|
||||||
|
config.theme = this.theme;
|
||||||
|
|
||||||
await config.save();
|
await config.save();
|
||||||
|
|
||||||
|
|
@ -143,6 +155,10 @@ export default Vue.extend({
|
||||||
this.loadTagCounts = config.loadTagCounts;
|
this.loadTagCounts = config.loadTagCounts;
|
||||||
this.addPageUrlToSource = config.addPageUrlToSource;
|
this.addPageUrlToSource = config.addPageUrlToSource;
|
||||||
this.useContentTokens = config.useContentTokens;
|
this.useContentTokens = config.useContentTokens;
|
||||||
|
this.theme = config.theme;
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
theme: (value) => applyTheme(value),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -167,6 +183,10 @@ export default Vue.extend({
|
||||||
padding: 1.8em;
|
padding: 1.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html[data-theme="dark"] .content-holder > .content-wrapper:not(.transparent) {
|
||||||
|
background: var(--section-header-bg-color);
|
||||||
|
}
|
||||||
|
|
||||||
.settings-footer {
|
.settings-footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 5px;
|
gap: 5px;
|
||||||
|
|
@ -195,7 +215,7 @@ export default Vue.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
.input li {
|
.input li {
|
||||||
flex: 1 0 20em;
|
flex: 1 0 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input li.full-width {
|
.input li.full-width {
|
||||||
|
|
@ -210,7 +230,7 @@ export default Vue.extend({
|
||||||
.hint {
|
.hint {
|
||||||
margin-top: 0.2em;
|
margin-top: 0.2em;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
color: #888;
|
color: var(--secondary-text);
|
||||||
font-size: 80%;
|
font-size: 80%;
|
||||||
line-height: 120%;
|
line-height: 120%;
|
||||||
}
|
}
|
||||||
|
|
@ -228,10 +248,10 @@ textarea {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
border: 2px solid #eee;
|
border: 2px solid var(--border-color);
|
||||||
background: #fafafa;
|
background: var(--bg-secondary-color);
|
||||||
color: #111;
|
color: var(--text-color);
|
||||||
box-shadow: none;
|
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>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ import "../css/style.css";
|
||||||
|
|
||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
|
import { applyTheme } from "../Common";
|
||||||
|
|
||||||
|
applyTheme();
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
el: "#app",
|
el: "#app",
|
||||||
|
|
|
||||||
|
|
@ -580,7 +580,7 @@ video {
|
||||||
.section-header {
|
.section-header {
|
||||||
height: 30px;
|
height: 30px;
|
||||||
padding: 0 6px 0 10px;
|
padding: 0 6px 0 10px;
|
||||||
background-color: #eee;
|
background-color: var(--section-header-bg-color);
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
@ -590,6 +590,7 @@ video {
|
||||||
.section-header > span {
|
.section-header > span {
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
color: var(--section-header-fg-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-row {
|
.section-row {
|
||||||
|
|
@ -612,8 +613,8 @@ video {
|
||||||
.autocomplete-items {
|
.autocomplete-items {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
background-color: white;
|
background-color: var(--bg-main-color);
|
||||||
border: 2px solid #24aadd;
|
border: 2px solid var(--primary-color);
|
||||||
margin-top: 34px;
|
margin-top: 34px;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
@ -628,19 +629,19 @@ video {
|
||||||
}
|
}
|
||||||
|
|
||||||
.autocomplete-items > div:hover {
|
.autocomplete-items > div:hover {
|
||||||
background: #24aadd;
|
background: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.autocomplete-items > div:hover > span {
|
.autocomplete-items > div:hover > span {
|
||||||
color: #fff;
|
color: var(--text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.autocomplete-items > div.active {
|
.autocomplete-items > div.active {
|
||||||
background: #24aadd;
|
background: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.autocomplete-items > div.active > span {
|
.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. */
|
/* 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 Vue from "vue";
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
|
import { applyTheme } from "../Common";
|
||||||
|
|
||||||
|
applyTheme();
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
el: "#app",
|
el: "#app",
|
||||||
render: h => h(App)
|
render: (h) => h(App),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue