Refactor some frontend components and add feature to disable automatic tag import

pull/55/head
neobooru 2023-09-03 11:54:05 +02:00
parent a9acd53f89
commit f66591db6d
9 changed files with 1323 additions and 1326 deletions

View File

@ -27,7 +27,6 @@
},
"dependencies": {
"axios": "^1.2.2",
"basscss": "^8.1.0",
"byte-size": "^8.1.1",
"deepmerge": "^4.3.1",
"lodash": "^4.17.21",
@ -35,6 +34,8 @@
"neo-scraper": "^0.7.1",
"normalize.css": "^8.0.1",
"pinia": "^2.0.36",
"primeflex": "^3.3.1",
"primevue": "^3.33.0",
"vue-router": "4"
},
"devDependencies": {

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,12 @@ import { SzuruSiteConfig } from "~/config";
import { cfg } from "~/stores";
import { getErrorMessage } from "~/utils";
const statusText = ref("Version " + browser.runtime.getManifest().version);
const statusType = ref("status-quiet");
const versionInfo = import.meta.env.VITE_SZ_VERSION_INFO ?? "info not available";
import TabView from "primevue/tabview";
import TabPanel from "primevue/tabpanel";
console.log("Version: " + versionInfo);
const statusText = ref("");
const statusType = ref("status-quiet");
const versionInfo = "Version: " + (import.meta.env.VITE_SZ_VERSION_INFO ?? browser.runtime.getManifest().version);
const selectedSite = computed(() => {
if (cfg.value.selectedSiteId) {
@ -73,113 +74,133 @@ let mode = useColorMode({ emitAuto: true });
<template>
<div class="content-holder">
<div class="content-wrapper flex flex-wrap gap-3">
<div class="flex-fit"><strong>SzuruChrome Settings</strong></div>
<div class="content-wrapper flex flex-column gap-3">
<div><strong>SzuruChrome Settings</strong></div>
<div class="flex-fit">
<div class="fit flex flex-wrap">
<div class="flex-fit">
<label>Szurubooru Instances</label>
<!-- This isn't perfectly responsive for very small devices. -->
<div class="fit flex gap-1 flex-fit">
<select v-model="cfg.selectedSiteId">
<option v-for="site in cfg.sites" :key="site.id" :value="site.id">
{{ site.username }} @ {{ site.domain }}
</option>
<TabView>
<TabPanel header="General">
<div class="grid grid-nogutter gap-3">
<div class="col-12 md:col-6">
<label>Theme</label>
<select v-model="mode">
<option value="auto">System</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<button class="primary" @click="addSite">Add</button>
<button class="bg-danger" @click="removeSelectedSite">Remove</button>
<p class="hint">This setting auto-saves.</p>
</div>
<div class="col-12 md:col-6">
<label>
<input type="checkbox" v-model="cfg.autoSearchSimilar" />
Automatically search for similar posts
</label>
<p class="hint">
Automatically start searching for similar posts when opening the popup. Enabling this option will hide
the "Find Similar" button.
</p>
</div>
<div class="col-12 md:col-6">
<label>
<input type="checkbox" v-model="cfg.addPageUrlToSource" />
Add page URL to the source list
</label>
<p class="hint">
This will add the current page URL (e.g. the booru link) to the source list in addition to the actual
source (e.g. twitter/pixiv/artstation). Note: if the source is empty/not detected then the page URL will
always be used as fallback source.
</p>
</div>
<div class="col-12 md:col-6">
<label>
<input type="checkbox" v-model="cfg.addAllParsedTags" />
Automatically import all tags on supported pages
</label>
<p class="hint">
This will automatically import all tags, including their categories, on supported pages such as Danbooru
and Zerochan.
</p>
</div>
<div class="col-12 md:col-6">
<label>
<input type="checkbox" v-model="cfg.loadTagCounts" />
Show how often a tag is used in the selected szurubooru instance
</label>
<p class="hint">
Shows how often a given tag is used in the selected szurubooru instance. No number will be displayed
when the tag does not yet exist.
</p>
</div>
<span class="col-12 status-quiet">{{ versionInfo }}</span>
</div>
</TabPanel>
<div v-if="selectedSite" class="flex-fit flex flex-wrap gap-1 border-box pb2">
<div style="flex: 1 1 20ch">
<label>URL</label>
<input
v-if="selectedSite"
text="Szurubooru URL"
type="text"
name="domain"
v-model.lazy="selectedSite.domain"
/>
<TabPanel header="Instances">
<div class="formgrid grid">
<div class="field col-12">
<label>Szurubooru Instances</label>
<div class="flex gap-1">
<select v-model="cfg.selectedSiteId">
<option v-for="site in cfg.sites" :key="site.id" :value="site.id">
{{ site.username }} @ {{ site.domain }}
</option>
</select>
<button class="primary" @click="addSite">Add</button>
<button class="bg-danger" @click="removeSelectedSite">Remove</button>
</div>
</div>
<div style="flex: 1 1 12ch">
<label>Username</label>
<input text="Username" type="text" name="username" v-model="selectedSite.username" />
</div>
<template v-if="selectedSite">
<div class="field col-12">
<label>URL</label>
<input
v-if="selectedSite"
text="Szurubooru URL"
type="text"
name="domain"
v-model="selectedSite.domain"
/>
</div>
<div style="flex: 1 1 28ch">
<label>Authentication token</label>
<input text="Authentication token" type="text" name="token" v-model="selectedSite.authToken" />
</div>
<div class="field col-12 md:col-6">
<label>Username</label>
<input text="Username" type="text" name="username" v-model="selectedSite.username" />
</div>
<div class="field col-12 md:col-6">
<label>Authentication token</label>
<input text="Authentication token" type="text" name="token" v-model="selectedSite.authToken" />
</div>
<div class="col-12 flex flex-wrap justify-content-between gap-3">
<span class="status" :class="statusType">{{ statusText }}</span>
<button @click="testConnection">Test connection</button>
</div>
</template>
</div>
</div>
</div>
</TabPanel>
<div class="flex-fit flex flex-wrap gap-3">
<div class="settings-block" style="flex: 1 0 10ch">
<label>Theme</label>
<select v-model="mode">
<option value="auto">System</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<p class="hint">This setting auto-saves.</p>
</div>
<TabPanel header="Tags">
<!-- TODO: Tag category colors -->
<div class="settings-block">
<label>
<input type="checkbox" v-model="cfg.autoSearchSimilar" />
Automatically search for similar posts
</label>
<p class="hint">
Automatically start searching for similar posts when opening the popup. Enabling this option will hide the
"Find Similar" button.
</p>
</div>
<!-- TODO: Tag ignore list -->
<div class="settings-block">
<label>
<input type="checkbox" v-model="cfg.addPageUrlToSource" />
Add page URL to the source list
</label>
<p class="hint">
This will add the current page URL (e.g. the booru link) to the source list in addition to the actual source
(e.g. twitter/pixiv/artstation). Note: if the source is empty/not detected then the page URL will always be
used as fallback source.
</p>
</div>
<!-- TODO: Category ignore list -->
</TabPanel>
<div class="settings-block">
<label>
<input type="checkbox" v-model="cfg.loadTagCounts" />
Show how often a tag is used in the selected szurubooru instance
</label>
<p class="hint">
Shows how often a given tag is used in the selected szurubooru instance. No number will be displayed when
the tag does not yet exist.
</p>
</div>
</div>
<div class="flex-fit flex flex-wrap justify-between gap-3">
<span class="status" :class="statusType">{{ statusText }}</span>
<div class="flex gap-1">
<button @click="testConnection">Test connection</button>
<!-- <button @click="saveSettings" class="primary">Save settings</button> -->
</div>
</div>
<!-- TODO: Settings import/export? -->
</TabView>
</div>
</div>
</template>
<style lang="scss">
@use "~/styles/main.scss";
.content-holder {
padding: 1.5em;
display: flex;
@ -201,15 +222,6 @@ html.dark .content-wrapper {
background: var(--section-header-bg-color);
}
.settings-block {
flex: 1 0 200px;
label {
padding: 0;
margin-bottom: 0.3em;
}
}
.hint {
margin-top: 0.4em;
margin-bottom: 0;
@ -234,11 +246,6 @@ html.dark .content-wrapper {
opacity: 0.6;
}
label {
display: block;
padding: 0.3em 0;
}
input[type="checkbox"] {
margin: 0 3px 0 0;
}

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<base target="_blank" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Options</title>
<title>SzuruChrome Settings</title>
</head>
<body>
<div id="app"></div>

View File

@ -1,7 +1,11 @@
import { createApp } from "vue";
import PrimeVue from "primevue/config";
import App from "./App.vue";
import { setupApp } from "~/logic/common-setup";
import "../styles/main.scss";
const app = createApp(App);
setupApp(app);
app.use(PrimeVue);
app.mount("#app");

View File

@ -103,6 +103,10 @@ async function grabPost() {
const vm = new ScrapedPostDetails(result.posts[i]);
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
if (!cfg.value.addAllParsedTags) {
vm.tags.splice(0);
}
// Add current pageUrl to the source if either
// a. user has addPageUrlToSource set to true
// b. source is empty
@ -562,7 +566,7 @@ useDark();
</div>
</div>
<div v-else class="p3 flex items-center gap-3">
<div v-else class="p-3 flex items-center gap-3">
<span>No content found</span>
<font-awesome-icon icon="fa-solid fa-cog" class="cursor-pointer" @click="openOptionsPage" />
</div>

View File

@ -15,6 +15,7 @@ export const cfg = useStorageLocal(
sites: [] as Array<SzuruSiteConfig>,
selectedSiteId: undefined as string | undefined,
addTagImplications: true,
addAllParsedTags: true,
merge: {
expandOptions: true,
expandExistingTags: false,

View File

@ -1,49 +1,6 @@
@use "sass:color";
@use "basscss/css/basscss-cp.css";
:root {
--space-1: 0.25rem;
--space-2: 0.5rem;
--space-3: 1rem;
--space-4: 2rem;
}
.flex-fit {
flex: 0 0 100%;
}
.gap-1 {
gap: var(--space-1);
}
.gap-2 {
gap: var(--space-2);
}
.gap-3 {
gap: var(--space-3);
}
.gap-4 {
gap: var(--space-4);
}
.gapx-1 {
column-gap: var(--space-1);
}
.gapx-2 {
column-gap: var(--space-2);
}
.gapx-3 {
column-gap: var(--space-3);
}
.gapx-4 {
column-gap: var(--space-4);
}
@use "primeflex/primeflex.scss";
/* open-sans-regular - latin */
@font-face {
@ -77,6 +34,7 @@ $danger-color-dark: color.scale($danger-color, $lightness: -50%);
--section-header-fg-color: #4c4c4c;
--section-header-bg-color: #eee;
--text-color: #111;
--tab-color: rgba(0, 0, 0, 0.06);
}
html.dark {
@ -89,6 +47,7 @@ html.dark {
--section-header-fg-color: #d9d9d9;
--section-header-bg-color: #272727;
--text-color: #e6e6e6;
--tab-color: rgba(255, 255, 255, 0.06);
color: var(--text-color);
background-color: var(--bg-main-color);
color-scheme: dark;
@ -171,6 +130,7 @@ img {
display: flex;
}
// DEPRECATED: Replace with primeflex w-full
.full {
width: 100%;
}
@ -283,3 +243,56 @@ a.remove-tag {
.cursor-pointer {
cursor: pointer;
}
.popup-section {
margin: 10px;
}
.section-header {
height: 30px;
padding: 0 6px 0 10px;
background-color: var(--section-header-bg-color);
display: flex;
justify-content: space-between;
align-items: center;
> span {
font-size: 1.2em;
vertical-align: middle;
color: var(--section-header-fg-color);
}
&.toggleable {
cursor: pointer;
}
}
.section-row {
margin: 10px 5px 0;
}
.section-label {
display: block;
margin: 0 0 5px 0;
}
.section-block {
display: block;
}
.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);
}
}
}

View File

@ -17,10 +17,6 @@
}
}
.popup-section {
margin: 10px;
}
video {
width: 100%;
}
@ -37,35 +33,3 @@ label {
margin: 3px 3px 0 0;
}
}
.section-header {
height: 30px;
padding: 0 6px 0 10px;
background-color: var(--section-header-bg-color);
display: flex;
justify-content: space-between;
align-items: center;
> span {
font-size: 1.2em;
vertical-align: middle;
color: var(--section-header-fg-color);
}
&.toggleable {
cursor: pointer;
}
}
.section-row {
margin: 10px 5px 0;
}
.section-label {
display: block;
margin: 0 0 5px 0;
}
.section-block {
display: block;
}