Add feature to manually add tag category colors
parent
f66591db6d
commit
63d88dc7e5
|
|
@ -4,3 +4,7 @@ export class SzuruSiteConfig {
|
||||||
username = "user";
|
username = "user";
|
||||||
authToken = "";
|
authToken = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class TagCategoryColor {
|
||||||
|
constructor(public name: string, public color: string) {}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { TagCategoryColor } from "./config";
|
||||||
|
|
||||||
|
export function makeCssName(prefix: string, name: string) {
|
||||||
|
return prefix + "-" + name.replace(/[^a-z0-9]/g, "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function refreshTagCategoryColorMap(tagCategories: TagCategoryColor[], styleElement?: HTMLStyleElement) {
|
||||||
|
if (styleElement) {
|
||||||
|
document.head.removeChild(styleElement);
|
||||||
|
}
|
||||||
|
styleElement = document.createElement("style");
|
||||||
|
document.head.appendChild(styleElement);
|
||||||
|
for (let category of tagCategories) {
|
||||||
|
const ruleName = makeCssName("tag", category.name);
|
||||||
|
styleElement.sheet!.insertRule(`.${ruleName} { color: ${category.color} }`, styleElement.sheet!.cssRules.length);
|
||||||
|
console.log("adding " + category);
|
||||||
|
}
|
||||||
|
return styleElement;
|
||||||
|
}
|
||||||
|
|
@ -1,17 +1,24 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useColorMode } from "@vueuse/core";
|
import { useColorMode } from "@vueuse/core";
|
||||||
import SzuruWrapper from "~/api";
|
import SzuruWrapper from "~/api";
|
||||||
import { SzuruSiteConfig } from "~/config";
|
import { SzuruSiteConfig, TagCategoryColor } from "~/config";
|
||||||
import { cfg } from "~/stores";
|
import { cfg } from "~/stores";
|
||||||
import { getErrorMessage } from "~/utils";
|
import { getErrorMessage } from "~/utils";
|
||||||
|
|
||||||
import TabView from "primevue/tabview";
|
import TabView from "primevue/tabview";
|
||||||
import TabPanel from "primevue/tabpanel";
|
import TabPanel from "primevue/tabpanel";
|
||||||
|
import DataTable from "primevue/datatable";
|
||||||
|
import Column from "primevue/column";
|
||||||
|
|
||||||
const statusText = ref("");
|
const statusText = ref("");
|
||||||
const statusType = ref("status-quiet");
|
const statusType = ref("status-quiet");
|
||||||
const versionInfo = "Version: " + (import.meta.env.VITE_SZ_VERSION_INFO ?? browser.runtime.getManifest().version);
|
const versionInfo = "Version: " + (import.meta.env.VITE_SZ_VERSION_INFO ?? browser.runtime.getManifest().version);
|
||||||
|
|
||||||
|
const columns = ref([
|
||||||
|
{ field: "name", header: "Category name" },
|
||||||
|
{ field: "color", header: "CSS color" },
|
||||||
|
]);
|
||||||
|
|
||||||
const selectedSite = computed(() => {
|
const selectedSite = computed(() => {
|
||||||
if (cfg.value.selectedSiteId) {
|
if (cfg.value.selectedSiteId) {
|
||||||
return cfg.value.sites.find((x) => x.id == cfg.value.selectedSiteId);
|
return cfg.value.sites.find((x) => x.id == cfg.value.selectedSiteId);
|
||||||
|
|
@ -20,6 +27,8 @@ const selectedSite = computed(() => {
|
||||||
|
|
||||||
type StatusType = "success" | "error" | "quiet";
|
type StatusType = "success" | "error" | "quiet";
|
||||||
|
|
||||||
|
let mode = useColorMode({ emitAuto: true });
|
||||||
|
|
||||||
async function testConnection() {
|
async function testConnection() {
|
||||||
if (
|
if (
|
||||||
!selectedSite.value ||
|
!selectedSite.value ||
|
||||||
|
|
@ -69,7 +78,19 @@ function removeSelectedSite() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mode = useColorMode({ emitAuto: true });
|
function resetTagCategories() {
|
||||||
|
cfg.value.tagCategories.splice(0);
|
||||||
|
cfg.value.tagCategories.push(
|
||||||
|
new TagCategoryColor("copyright", "#a0a"),
|
||||||
|
new TagCategoryColor("character", "#0a0"),
|
||||||
|
new TagCategoryColor("artist", "#a00"),
|
||||||
|
new TagCategoryColor("meta", "#f80")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTagCategory() {
|
||||||
|
cfg.value.tagCategories.push(new TagCategoryColor("category", "#abcdef"));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -79,7 +100,7 @@ let mode = useColorMode({ emitAuto: true });
|
||||||
|
|
||||||
<TabView>
|
<TabView>
|
||||||
<TabPanel header="General">
|
<TabPanel header="General">
|
||||||
<div class="grid grid-nogutter gap-3">
|
<div class="grid">
|
||||||
<div class="col-12 md:col-6">
|
<div class="col-12 md:col-6">
|
||||||
<label>Theme</label>
|
<label>Theme</label>
|
||||||
<select v-model="mode">
|
<select v-model="mode">
|
||||||
|
|
@ -187,6 +208,44 @@ let mode = useColorMode({ emitAuto: true });
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
<TabPanel header="Tags">
|
<TabPanel header="Tags">
|
||||||
|
<div class="grid">
|
||||||
|
<DataTable :value="cfg.tagCategories" table-class="col-12" style="width: 100%">
|
||||||
|
<Column v-for="col of columns" :key="col.field" :field="col.field" :header="col.header">
|
||||||
|
<template #body="{ data, field }">
|
||||||
|
<template v-if="field == 'color'">
|
||||||
|
<div class="color-preview">
|
||||||
|
<input type="text" class="color" v-model="data[field]" />
|
||||||
|
<div
|
||||||
|
class="preview background-preview"
|
||||||
|
:style="{ 'border-color': data[field], 'background-color': data[field] }"
|
||||||
|
></div>
|
||||||
|
<div
|
||||||
|
class="preview text-preview"
|
||||||
|
:style="{ 'border-color': data[field], color: data[field] }"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<input type="text" :name="field" v-model="data[field]" />
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
|
||||||
|
<Column field="name">
|
||||||
|
<template #body="{ index }">
|
||||||
|
<a class="color-primary cursor-pointer" @click="() => cfg.tagCategories.splice(index, 1)">Remove</a>
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
</DataTable>
|
||||||
|
|
||||||
|
<div class="col-12 flex flex-wrap grid grid-nogutter gap-1">
|
||||||
|
<button class="primary" @click="addTagCategory">Add new category</button>
|
||||||
|
<!-- <button>Import from connected instances</button> -->
|
||||||
|
<button class="bg-danger sm:ml-auto" @click="resetTagCategories">Reset to default</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- TODO: Tag category colors -->
|
<!-- TODO: Tag category colors -->
|
||||||
|
|
||||||
<!-- TODO: Tag ignore list -->
|
<!-- TODO: Tag ignore list -->
|
||||||
|
|
@ -208,7 +267,7 @@ let mode = useColorMode({ emitAuto: true });
|
||||||
|
|
||||||
> .content-wrapper {
|
> .content-wrapper {
|
||||||
// box-sizing: border-box;
|
// box-sizing: border-box;
|
||||||
// text-align: left;
|
text-align: left;
|
||||||
// display: inline-block;
|
// display: inline-block;
|
||||||
// flex: auto;
|
// flex: auto;
|
||||||
max-width: 1000px;
|
max-width: 1000px;
|
||||||
|
|
@ -259,4 +318,31 @@ input[type="checkbox"] {
|
||||||
flex: 0 0 100%;
|
flex: 0 0 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.color-preview {
|
||||||
|
white-space: nowrap;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
input {
|
||||||
|
margin-right: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview {
|
||||||
|
display: inline-block;
|
||||||
|
text-align: center;
|
||||||
|
padding: 0 0.5em;
|
||||||
|
border: 2px solid #000;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: "A";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.background-preview {
|
||||||
|
border-right: 0;
|
||||||
|
border-right-color: currentcolor;
|
||||||
|
color: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import App from "./App.vue";
|
||||||
import { setupApp } from "~/logic/common-setup";
|
import { setupApp } from "~/logic/common-setup";
|
||||||
|
|
||||||
import "../styles/main.scss";
|
import "../styles/main.scss";
|
||||||
|
import "../styles/primevue.scss";
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
setupApp(app);
|
setupApp(app);
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,21 @@ import { onMounted } from "vue";
|
||||||
import { isChrome } from "~/env";
|
import { isChrome } from "~/env";
|
||||||
import { BrowserCommand, SetPostUploadInfoData, SetExactPostId } from "~/models";
|
import { BrowserCommand, SetPostUploadInfoData, SetExactPostId } from "~/models";
|
||||||
import { Runtime, WebRequest } from "webextension-polyfill";
|
import { Runtime, WebRequest } from "webextension-polyfill";
|
||||||
import { useMergeStore, usePopupStore } from "~/stores";
|
import { cfg, useMergeStore, usePopupStore } from "~/stores";
|
||||||
|
import { refreshTagCategoryColorMap } from "~/dynamicStyle";
|
||||||
|
|
||||||
const pop = usePopupStore();
|
const pop = usePopupStore();
|
||||||
const merge = useMergeStore();
|
const merge = useMergeStore();
|
||||||
|
|
||||||
|
let el: any;
|
||||||
|
watch(
|
||||||
|
cfg,
|
||||||
|
(value) => {
|
||||||
|
el = refreshTagCategoryColorMap(value.tagCategories, el);
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
browser.runtime.onMessage.addListener((cmd: BrowserCommand, _sender: Runtime.MessageSender) => {
|
browser.runtime.onMessage.addListener((cmd: BrowserCommand, _sender: Runtime.MessageSender) => {
|
||||||
console.log("Popup received message:");
|
console.log("Popup received message:");
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import deepMerge from "deepmerge";
|
import deepMerge from "deepmerge";
|
||||||
import { SzuruSiteConfig } from "~/config";
|
import { SzuruSiteConfig, TagCategoryColor } from "~/config";
|
||||||
import type { ScrapedPostDetails, SetPostUploadInfoData } from "~/models";
|
import type { ScrapedPostDetails, SetPostUploadInfoData } from "~/models";
|
||||||
import { useStorageLocal } from "~/composables/useStorageLocal";
|
import { useStorageLocal } from "~/composables/useStorageLocal";
|
||||||
|
|
||||||
|
|
@ -24,6 +24,7 @@ export const cfg = useStorageLocal(
|
||||||
appendSource: true,
|
appendSource: true,
|
||||||
mergeSafety: true,
|
mergeSafety: true,
|
||||||
},
|
},
|
||||||
|
tagCategories: [] as Array<TagCategoryColor>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mergeDefaults: (storageValue, defaults) => deepMerge(defaults, storageValue),
|
mergeDefaults: (storageValue, defaults) => deepMerge(defaults, storageValue),
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ input[type="text"],
|
||||||
select {
|
select {
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
background-color: var(--bg-secondary-color);
|
background-color: var(--bg-secondary-color);
|
||||||
border: 1px solid var(--border-color);
|
border: 2px solid var(--border-color);
|
||||||
|
|
||||||
padding: 0.2em 0.3em;
|
padding: 0.2em 0.3em;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
@ -107,7 +107,7 @@ input[type="radio"] {
|
||||||
textarea {
|
textarea {
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
background-color: var(--bg-secondary-color);
|
background-color: var(--bg-secondary-color);
|
||||||
border: 1px solid var(--border-color);
|
border: 2px solid var(--border-color);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
overflow-wrap: normal;
|
overflow-wrap: normal;
|
||||||
|
|
@ -158,30 +158,6 @@ ul.compact {
|
||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-copyright {
|
|
||||||
color: rgb(170, 0, 170);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-character {
|
|
||||||
color: rgb(0, 170, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-artist {
|
|
||||||
color: rgb(170, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-meta {
|
|
||||||
color: rgb(255, 128, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-species {
|
|
||||||
color: rgb(17, 14, 247);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-lore {
|
|
||||||
color: rgb(48, 48, 48);
|
|
||||||
}
|
|
||||||
|
|
||||||
.remove-tag {
|
.remove-tag {
|
||||||
color: var(--secondary-text);
|
color: var(--secondary-text);
|
||||||
}
|
}
|
||||||
|
|
@ -280,19 +256,6 @@ a.remove-tag {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.p-tabview {
|
.color-primary {
|
||||||
.p-tabview-nav {
|
color: var(--primary-color);
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-tabview-header {
|
|
||||||
span {
|
|
||||||
padding: 0 1.2em;
|
|
||||||
line-height: 2.3em;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.p-highlight {
|
|
||||||
background-color: var(--tab-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
.p-tabview {
|
||||||
|
.p-tabview-nav {
|
||||||
|
margin: 1em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-tabview-header {
|
||||||
|
span {
|
||||||
|
padding: 0 1.2em;
|
||||||
|
line-height: 2.3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.p-highlight {
|
||||||
|
background-color: var(--tab-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-datatable {
|
||||||
|
margin: -0.4em;
|
||||||
|
|
||||||
|
.p-datatable-table {
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
padding: 0.4em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue