[wip] Multi szurubooru instance support
parent
e6c880314e
commit
f7849b42c8
12
README.md
12
README.md
|
|
@ -40,11 +40,13 @@ You can download a .zip containing the needed files from the [release tab](https
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Install node modules
|
# Install node modules
|
||||||
yarn install
|
pnpm install
|
||||||
|
|
||||||
# Use any of the following commands to build
|
# Live dev build (watch)
|
||||||
yarn build
|
pnpm dev
|
||||||
yarn build:dev
|
|
||||||
|
# Production build
|
||||||
|
pnpm build
|
||||||
```
|
```
|
||||||
|
|
||||||
After this you can load them in your browser.
|
After this you can load them in your browser.
|
||||||
|
|
@ -61,5 +63,3 @@ These are some things I might work on. Though honestly I don't expect this exten
|
||||||
- Right click any image on a page to import it
|
- Right click any image on a page to import it
|
||||||
- Configurable list of tags to always ignore (e.g. tagme, highres)
|
- Configurable list of tags to always ignore (e.g. tagme, highres)
|
||||||
- [low priority] Import artist commentary
|
- [low priority] Import artist commentary
|
||||||
- [lowest priority] Move from 'options_page' to 'options_ui'
|
|
||||||
- [lowest priority] Multiple szurubooru instances (where you can choose to which one you want to upload the post)
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.2.2",
|
"axios": "^1.2.2",
|
||||||
|
"basscss": "^8.1.0",
|
||||||
"markdown-it": "^13.0.1",
|
"markdown-it": "^13.0.1",
|
||||||
"neo-scraper": "^0.5.8",
|
"neo-scraper": "^0.5.8",
|
||||||
"normalize.css": "^8.0.1"
|
"normalize.css": "^8.0.1"
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ specifiers:
|
||||||
'@vue/test-utils': ^2.2.4
|
'@vue/test-utils': ^2.2.4
|
||||||
'@vueuse/core': ^9.6.0
|
'@vueuse/core': ^9.6.0
|
||||||
axios: ^1.2.2
|
axios: ^1.2.2
|
||||||
|
basscss: ^8.1.0
|
||||||
chokidar: ^3.5.3
|
chokidar: ^3.5.3
|
||||||
cross-env: ^7.0.3
|
cross-env: ^7.0.3
|
||||||
crx: ^5.0.1
|
crx: ^5.0.1
|
||||||
|
|
@ -41,6 +42,7 @@ specifiers:
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
axios: 1.2.2
|
axios: 1.2.2
|
||||||
|
basscss: 8.1.0
|
||||||
markdown-it: 13.0.1
|
markdown-it: 13.0.1
|
||||||
neo-scraper: 0.5.8
|
neo-scraper: 0.5.8
|
||||||
normalize.css: 8.0.1
|
normalize.css: 8.0.1
|
||||||
|
|
@ -1291,6 +1293,66 @@ packages:
|
||||||
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/basscss-align/1.0.2:
|
||||||
|
resolution: {integrity: sha512-T7XvlG6jqjBvQ27xSioO5p069E5jW12QbOy+V+QKnkmfwkU+SDTrcLI2DMSlTPGbPmtDZHeRrG9qwOhjbaMMbg==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-border/4.0.2:
|
||||||
|
resolution: {integrity: sha512-qw+AeA7zFVtYWdWR+GQ+CkXbGzJ6QhjyT4eE4SURSkviSoZkZEA+oVbtC/yD/hiy/spWFk9UDLE71vJ8CDEnHw==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-flexbox/1.0.2:
|
||||||
|
resolution: {integrity: sha512-AtG6yBmmza2nPo3x9X4/7rbW22gLmiSvYvirFs7Aspt1zp5FHwpRBz3BD2v/a3qPdmVM8OvOLVNWISGM6O50MA==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-grid/2.0.0:
|
||||||
|
resolution: {integrity: sha512-vUnHyLvNx4Bi7caXWMpooMBOBCP+bib/z+pu/kqySLHe0ap5kNTs9EgTBI/QVD8VrnruIznL5GUP3RuT0KLZ6g==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-hide/1.0.1:
|
||||||
|
resolution: {integrity: sha512-NYKtjyYIoY4GGiRrE5b3NV/9AmLJOoYTshKl2N6rNI+Bvh+rElT+F7GsOvNlmJvoVhDihcLK16U2UYYNlmb9Bw==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-layout/3.1.0:
|
||||||
|
resolution: {integrity: sha512-umKiuaeDS4THPPA/3N8UOO3wyubEKf+93Cm971QkAWLjDu2OrX5rOOAQC+tP+Q+OsMaAKvMNdZlA4kij+2y4nQ==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-margin/1.0.9:
|
||||||
|
resolution: {integrity: sha512-wpF8tXrtzU+iMtLvfSgYJlpkIxChOlay3YumoI+yJ6IiOe5uMmEGUG8FWAIkC8QalkKDAURAqHmQ4nbuyUvyag==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-padding/1.1.3:
|
||||||
|
resolution: {integrity: sha512-pfqA7LgTpdR9lCh36IxWFNV4kZM53G1lnQlvC/2MzUu62XhvRDXD2uENGXWwJYKgaxRAdqdDoHZ0K23mRlk29g==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-position/2.0.3:
|
||||||
|
resolution: {integrity: sha512-g3esHpUHqABF4wieZyAVaLI6JnK7/mPVG65OCfM6VcSRQcw7g4mxHI8nTWlnwlzpwFnqXnI/KBco00ccUJvOLg==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-type-scale/1.0.6:
|
||||||
|
resolution: {integrity: sha512-93KOVRr5iX0e38d6+k2pQ8WW1IA5DigQhJextts4rwbSt2+cr+XrokGJ74HB8LevO54HMoc3VJ8M6oOR2puc8A==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss-typography/3.0.4:
|
||||||
|
resolution: {integrity: sha512-PMCxUfYPpAj8gQV8qI09lfNp7eWNrKtQFkCN2fZjLyReSY/wnw8QP8irpvbJ67vSEhlkA6ZP8j7vmTDoxkyu8g==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/basscss/8.1.0:
|
||||||
|
resolution: {integrity: sha512-SJ48HWDKqX1OnzeZgqwweFPVM98h0lNtvC+megWPCEJ1R6LIbx6dnj3rpCJueElVn9giWipZhoozMEBRAIlnUw==}
|
||||||
|
dependencies:
|
||||||
|
basscss-align: 1.0.2
|
||||||
|
basscss-border: 4.0.2
|
||||||
|
basscss-flexbox: 1.0.2
|
||||||
|
basscss-grid: 2.0.0
|
||||||
|
basscss-hide: 1.0.1
|
||||||
|
basscss-layout: 3.1.0
|
||||||
|
basscss-margin: 1.0.9
|
||||||
|
basscss-padding: 1.1.3
|
||||||
|
basscss-position: 2.0.3
|
||||||
|
basscss-type-scale: 1.0.6
|
||||||
|
basscss-typography: 3.0.4
|
||||||
|
dev: false
|
||||||
|
|
||||||
/bcrypt-pbkdf/1.0.2:
|
/bcrypt-pbkdf/1.0.2:
|
||||||
resolution: {integrity: sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==}
|
resolution: {integrity: sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ export default class SzurubooruApi {
|
||||||
return await axios(config);
|
return await axios(config);
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
const error = ex.response?.data as SzuruError | undefined;
|
const error = ex.response?.data as SzuruError | undefined;
|
||||||
throw error ? error : ex;
|
throw error?.name ? error : ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { encodeTagName, getUrl } from "~/utils";
|
import { encodeTagName, getUrl } from "~/utils";
|
||||||
import { BrowserCommand, Message, PostDetails } from "~/models";
|
import { BrowserCommand, Message, PostUploadCommandData } from "~/models";
|
||||||
import { PostAlreadyUploadedError, SzuruError } from "~/api/models";
|
import { PostAlreadyUploadedError, SzuruError } from "~/api/models";
|
||||||
import SzurubooruApi from "~/api";
|
import SzurubooruApi from "~/api";
|
||||||
import { Config } from "~/config";
|
import { Config } from "~/config";
|
||||||
|
|
@ -12,24 +12,27 @@ if (import.meta.hot) {
|
||||||
import("./contentScriptHMR");
|
import("./contentScriptHMR");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadPost(post: PostDetails) {
|
async function uploadPost(data: PostUploadCommandData) {
|
||||||
console.dir(post);
|
console.dir(data.post);
|
||||||
|
|
||||||
const cfg = await Config.load();
|
const cfg = await Config.load();
|
||||||
|
const selectedSite = cfg.sites.find((x) => x.id == data.siteId);
|
||||||
|
|
||||||
if (cfg.sites.length == 0) {
|
if (!selectedSite) {
|
||||||
// TODO: Generic error handler which also shows the message in the popup frontend.
|
// TODO: Generic error handler which also shows the message in the popup frontend.
|
||||||
browser.runtime.sendMessage(new BrowserCommand("push_message", new Message("cfg.sites.length == 0", "error")));
|
browser.runtime.sendMessage(
|
||||||
|
new BrowserCommand("push_message", new Message("Selected instance not found in config!", "error"))
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const szuru = SzurubooruApi.createFromConfig(cfg.sites[0]);
|
const szuru = SzurubooruApi.createFromConfig(selectedSite);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create and upload post
|
// Create and upload post
|
||||||
browser.runtime.sendMessage(new BrowserCommand("pop_messages", 10));
|
browser.runtime.sendMessage(new BrowserCommand("pop_messages", 10));
|
||||||
browser.runtime.sendMessage(new BrowserCommand("push_message", new Message("Uploading...")));
|
browser.runtime.sendMessage(new BrowserCommand("push_message", new Message("Uploading...")));
|
||||||
const createdPost = await szuru.createPost(post);
|
const createdPost = await szuru.createPost(data.post);
|
||||||
browser.runtime.sendMessage(new BrowserCommand("pop_messages", 1));
|
browser.runtime.sendMessage(new BrowserCommand("pop_messages", 1));
|
||||||
browser.runtime.sendMessage(
|
browser.runtime.sendMessage(
|
||||||
new BrowserCommand("push_message", new Message("Uploaded post " + createdPost.id, "success"))
|
new BrowserCommand("push_message", new Message("Uploaded post " + createdPost.id, "success"))
|
||||||
|
|
@ -42,7 +45,7 @@ async function uploadPost(post: PostDetails) {
|
||||||
|
|
||||||
// Find tags with "default" category and update it
|
// Find tags with "default" category and update it
|
||||||
// TODO: Make all these categories configurable
|
// TODO: Make all these categories configurable
|
||||||
const tagsWithCategory = post.tags.filter((x) => x.category);
|
const tagsWithCategory = data.post.tags.filter((x) => x.category);
|
||||||
const unsetCategoryTags = createdPost.tags
|
const unsetCategoryTags = createdPost.tags
|
||||||
.filter((x) => x.category == "default")
|
.filter((x) => x.category == "default")
|
||||||
.filter((x) => tagsWithCategory.some((y) => x.names.includes(y.name)));
|
.filter((x) => tagsWithCategory.some((y) => x.names.includes(y.name)));
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
export class SzuruSiteConfig {
|
export class SzuruSiteConfig {
|
||||||
domain = "";
|
id = window.crypto.randomUUID();
|
||||||
username = "";
|
domain = "https://example.com";
|
||||||
|
username = "user";
|
||||||
authToken = "";
|
authToken = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -13,6 +14,7 @@ export class Config {
|
||||||
loadTagCounts = true;
|
loadTagCounts = true;
|
||||||
useContentTokens = true;
|
useContentTokens = true;
|
||||||
sites: Array<SzuruSiteConfig> = [];
|
sites: Array<SzuruSiteConfig> = [];
|
||||||
|
selectedSiteId: string | undefined = undefined;
|
||||||
|
|
||||||
public async save() {
|
public async save() {
|
||||||
await browser.storage.local.set({
|
await browser.storage.local.set({
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ export class TagDetails {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PostDetails {
|
export class ScrapedPostDetails {
|
||||||
name = "";
|
name = "";
|
||||||
tags: TagDetails[] = [];
|
tags: TagDetails[] = [];
|
||||||
notes: ScrapedNote[];
|
notes: ScrapedNote[];
|
||||||
|
|
@ -73,3 +73,7 @@ export class BrowserCommand<T = any> {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class PostUploadCommandData {
|
||||||
|
constructor(public readonly post: ScrapedPostDetails, public readonly siteId: string) {}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,61 @@
|
||||||
<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 { Config } from "~/config";
|
import { Config, SzuruSiteConfig } from "~/config";
|
||||||
|
|
||||||
let domain = ref("");
|
|
||||||
let username = ref("");
|
|
||||||
let authToken = ref("");
|
|
||||||
let autoSearchSimilar = ref(false);
|
let autoSearchSimilar = ref(false);
|
||||||
let loadTagCounts = ref(false);
|
let loadTagCounts = ref(false);
|
||||||
let addPageUrlToSource = ref(false);
|
let addPageUrlToSource = ref(false);
|
||||||
let useContentTokens = ref(false);
|
let useContentTokens = ref(false);
|
||||||
let statusText = ref("");
|
let statusText = ref("");
|
||||||
let statusType = ref("");
|
let statusType = ref("");
|
||||||
|
let sites = reactive<SzuruSiteConfig[]>([]);
|
||||||
|
let selectedSiteId = ref<string | undefined>(undefined);
|
||||||
|
const selectedSite = computed(() => {
|
||||||
|
if (selectedSiteId.value) {
|
||||||
|
return sites.find((x) => x.id == selectedSiteId.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
type StatusType = "ok" | "error";
|
type StatusType = "ok" | "error";
|
||||||
|
|
||||||
async function testConnection() {
|
async function testConnection() {
|
||||||
if (!domain.value || !username.value || !authToken.value) {
|
if (
|
||||||
|
!selectedSite.value ||
|
||||||
|
!selectedSite.value.domain ||
|
||||||
|
!selectedSite.value.username ||
|
||||||
|
!selectedSite.value.authToken
|
||||||
|
) {
|
||||||
setStatus("Domain, username and authentication token are all required.", "error");
|
setStatus("Domain, username and authentication token are all required.", "error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = new SzuruWrapper(domain.value, username.value, authToken.value);
|
const api = new SzuruWrapper(selectedSite.value.domain, selectedSite.value.username, selectedSite.value.authToken);
|
||||||
try {
|
try {
|
||||||
const info = (await api.getInfo()) as any;
|
const info = (await api.getInfo()) as any;
|
||||||
const instanceName = info?.config.name;
|
const instanceName = info?.config.name;
|
||||||
|
|
||||||
if (instanceName == undefined) {
|
if (instanceName == undefined) {
|
||||||
setStatus(`Connected to ${domain.value}, but it is not a szurubooru instance.`, "error");
|
setStatus(`Connected to ${selectedSite.value.domain}, but it is not a szurubooru instance.`, "error");
|
||||||
} else {
|
} else {
|
||||||
setStatus(`Connected to ${info.config.name} at ${domain.value}`);
|
setStatus(`Connected to ${info.config.name} at ${selectedSite.value.domain}`);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// TODO: This error message is not very descriptive.
|
// TODO: This error message is not very descriptive.
|
||||||
console.dir(ex);
|
console.dir(ex);
|
||||||
setStatus("Couldn't connect to " + domain.value + "\n\n" + ex, "error");
|
setStatus("Couldn't connect to " + selectedSite.value.domain + "\n\n" + ex, "error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveSettings() {
|
async function saveSettings() {
|
||||||
let config = await Config.load();
|
let config = await Config.load();
|
||||||
|
|
||||||
// We currently only support one domain
|
config.sites = sites;
|
||||||
config.sites = [
|
|
||||||
{
|
|
||||||
domain: domain.value,
|
|
||||||
username: username.value,
|
|
||||||
authToken: authToken.value,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
config.autoSearchSimilar = autoSearchSimilar.value;
|
config.autoSearchSimilar = autoSearchSimilar.value;
|
||||||
config.loadTagCounts = loadTagCounts.value;
|
config.loadTagCounts = loadTagCounts.value;
|
||||||
config.addPageUrlToSource = addPageUrlToSource.value;
|
config.addPageUrlToSource = addPageUrlToSource.value;
|
||||||
config.useContentTokens = useContentTokens.value;
|
config.useContentTokens = useContentTokens.value;
|
||||||
|
config.selectedSiteId = selectedSiteId.value;
|
||||||
|
|
||||||
await config.save();
|
await config.save();
|
||||||
|
|
||||||
|
|
@ -64,19 +67,38 @@ function setStatus(text: string, type: StatusType = "ok") {
|
||||||
statusType.value = "status-" + type;
|
statusType.value = "status-" + type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addSite() {
|
||||||
|
const site = new SzuruSiteConfig();
|
||||||
|
sites.push(site);
|
||||||
|
selectedSiteId.value = site.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeSelectedSite() {
|
||||||
|
if (selectedSite.value) {
|
||||||
|
const idx = sites.indexOf(selectedSite.value);
|
||||||
|
sites.splice(idx, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
let config = await Config.load();
|
let config = await Config.load();
|
||||||
|
|
||||||
if (config.sites.length > 0) {
|
for (let site of config.sites) {
|
||||||
domain.value = config.sites[0].domain;
|
// Generate IDs for sites which are missing them.
|
||||||
username.value = config.sites[0].username;
|
// This is needed to correctly import old configs.
|
||||||
authToken.value = config.sites[0].authToken;
|
if (!site.id) {
|
||||||
|
site.id = window.crypto.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This somehow makes `site` reactive.
|
||||||
|
sites.push(site);
|
||||||
}
|
}
|
||||||
|
|
||||||
autoSearchSimilar.value = config.autoSearchSimilar;
|
autoSearchSimilar.value = config.autoSearchSimilar;
|
||||||
loadTagCounts.value = config.loadTagCounts;
|
loadTagCounts.value = config.loadTagCounts;
|
||||||
addPageUrlToSource.value = config.addPageUrlToSource;
|
addPageUrlToSource.value = config.addPageUrlToSource;
|
||||||
useContentTokens.value = config.useContentTokens;
|
useContentTokens.value = config.useContentTokens;
|
||||||
|
selectedSiteId.value = config.selectedSiteId;
|
||||||
});
|
});
|
||||||
|
|
||||||
let mode = useColorMode({ emitAuto: true });
|
let mode = useColorMode({ emitAuto: true });
|
||||||
|
|
@ -84,33 +106,62 @@ let mode = useColorMode({ emitAuto: true });
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="content-holder">
|
<div class="content-holder">
|
||||||
<div class="content-wrapper">
|
<div class="content-wrapper flex flex-wrap gap-3">
|
||||||
<strong>SzuruChrome Settings</strong>
|
<div class="flex-fit"><strong>SzuruChrome Settings</strong></div>
|
||||||
|
|
||||||
<p>General settings which apply to all engines.</p>
|
<div class="flex-fit">
|
||||||
|
<div class="fit flex flex-wrap">
|
||||||
|
<div class="flex-fit">
|
||||||
|
<label>Szurubooru Instances</label>
|
||||||
|
<div class="fit flex gapx-1 flex-fit">
|
||||||
|
<select v-model="selectedSiteId">
|
||||||
|
<option v-for="site in sites" :key="site.id" :value="site.id">
|
||||||
|
{{ site.username }} @ {{ site.domain }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
<ul class="input">
|
<button class="primary" @click="addSite">Add</button>
|
||||||
<li class="full-width">
|
<button class="bg-danger" @click="removeSelectedSite">Remove</button>
|
||||||
<label>Szurubooru URL</label>
|
</div>
|
||||||
<input text="Szurubooru URL" type="text" name="domain" v-model="domain" />
|
</div>
|
||||||
</li>
|
|
||||||
<li><label>Username</label><input text="Username" type="text" name="username" v-model="username" /></li>
|
<div v-if="selectedSite" class="flex-fit flex flex-wrap gap-1 border-box pb2">
|
||||||
<li style="min-width: 320px">
|
<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"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="flex: 1 1 12ch">
|
||||||
|
<label>Username</label>
|
||||||
|
<input text="Username" type="text" name="username" v-model="selectedSite.username" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="flex: 1 1 28ch">
|
||||||
<label>Authentication token</label>
|
<label>Authentication token</label>
|
||||||
<input text="Authentication token" type="text" name="token" v-model="authToken" />
|
<input text="Authentication token" type="text" name="token" v-model="selectedSite.authToken" />
|
||||||
</li>
|
</div>
|
||||||
<li>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-fit flex flex-wrap gap-3">
|
||||||
|
<div class="settings-block" style="flex: 1 0 10ch">
|
||||||
<label>Theme</label>
|
<label>Theme</label>
|
||||||
<select v-model="mode">
|
<select v-model="mode">
|
||||||
<option value="auto">System</option>
|
<option value="auto">System</option>
|
||||||
<option value="light">Light</option>
|
<option value="light">Light</option>
|
||||||
<option value="dark">Dark</option>
|
<option value="dark">Dark</option>
|
||||||
</select>
|
</select>
|
||||||
</li>
|
<p class="hint">This setting auto-saves.</p>
|
||||||
</ul>
|
</div>
|
||||||
|
|
||||||
<ul class="input">
|
<div class="settings-block">
|
||||||
<li>
|
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" v-model="autoSearchSimilar" />
|
<input type="checkbox" v-model="autoSearchSimilar" />
|
||||||
Automatically search for similar posts
|
Automatically search for similar posts
|
||||||
|
|
@ -119,8 +170,9 @@ let mode = useColorMode({ emitAuto: true });
|
||||||
Automatically start searching for similar posts when opening the popup. Enabling this option will hide the
|
Automatically start searching for similar posts when opening the popup. Enabling this option will hide the
|
||||||
"Find Similar" button.
|
"Find Similar" button.
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</div>
|
||||||
<li>
|
|
||||||
|
<div class="settings-block">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" v-model="addPageUrlToSource" />
|
<input type="checkbox" v-model="addPageUrlToSource" />
|
||||||
Add page URL to the source list
|
Add page URL to the source list
|
||||||
|
|
@ -130,8 +182,9 @@ let mode = useColorMode({ emitAuto: true });
|
||||||
(e.g. twitter/pixiv/artstation). Note: if the source is empty/not detected then the page URL will always be
|
(e.g. twitter/pixiv/artstation). Note: if the source is empty/not detected then the page URL will always be
|
||||||
used as fallback source.
|
used as fallback source.
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</div>
|
||||||
<li>
|
|
||||||
|
<div class="settings-block">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" v-model="loadTagCounts" />
|
<input type="checkbox" v-model="loadTagCounts" />
|
||||||
Show how often a tag is used in the selected szurubooru instance
|
Show how often a tag is used in the selected szurubooru instance
|
||||||
|
|
@ -140,12 +193,10 @@ let mode = useColorMode({ emitAuto: true });
|
||||||
Shows how often a given tag is used in the selected szurubooru instance. No number will be displayed when
|
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.
|
the tag does not yet exist.
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</div>
|
||||||
</ul>
|
</div>
|
||||||
|
|
||||||
<div class="settings-footer">
|
|
||||||
<span class="status" :class="statusType">{{ statusText }}</span>
|
|
||||||
|
|
||||||
|
<div class="flex-fit flex justify-end gap-1">
|
||||||
<button @click="testConnection">Test connection</button>
|
<button @click="testConnection">Test connection</button>
|
||||||
<button @click="saveSettings" class="primary">Save settings</button>
|
<button @click="saveSettings" class="primary">Save settings</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -160,67 +211,44 @@ let mode = useColorMode({ emitAuto: true });
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
> .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;
|
||||||
|
// gap: 1rem;
|
||||||
&:not(.transparent) {
|
|
||||||
background: #f5f5f5;
|
|
||||||
padding: 1.8em;
|
padding: 1.8em;
|
||||||
}
|
background: #f5f5f5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
html.dark .content-holder > .content-wrapper:not(.transparent) {
|
html.dark .content-wrapper {
|
||||||
background: var(--section-header-bg-color);
|
background: var(--section-header-bg-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-footer {
|
.settings-block {
|
||||||
display: flex;
|
|
||||||
gap: 5px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
|
|
||||||
.status {
|
|
||||||
flex-grow: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
> span.status-ok {
|
|
||||||
color: green;
|
|
||||||
}
|
|
||||||
|
|
||||||
> span.status-error {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.input {
|
|
||||||
list-style-type: none;
|
|
||||||
padding: 0;
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 10px;
|
|
||||||
|
|
||||||
li {
|
|
||||||
flex: 1 0 200px;
|
flex: 1 0 200px;
|
||||||
}
|
|
||||||
|
|
||||||
li.full-width {
|
|
||||||
min-width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: block;
|
padding: 0;
|
||||||
padding: 0.3em 0;
|
margin-bottom: 0.3em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.hint {
|
.hint {
|
||||||
margin-top: 0.2em;
|
margin-top: 0.4em;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
color: var(--secondary-text);
|
color: var(--secondary-text);
|
||||||
font-size: 80%;
|
font-size: 80%;
|
||||||
line-height: 120%;
|
line-height: 120%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
padding: 0.3em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="checkbox"] {
|
||||||
|
margin: 0 3px 0 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,39 @@ import { useDark } from "@vueuse/core";
|
||||||
import axios, { CancelTokenSource } from "axios";
|
import axios, { CancelTokenSource } from "axios";
|
||||||
import { ScrapedPost, ScrapeResults } from "neo-scraper";
|
import { ScrapedPost, ScrapeResults } from "neo-scraper";
|
||||||
import { getUrl, encodeTagName } from "~/utils";
|
import { getUrl, encodeTagName } from "~/utils";
|
||||||
import { BrowserCommand, Message, PostDetails, TagDetails, MessageCategory } from "~/models";
|
import {
|
||||||
|
BrowserCommand,
|
||||||
|
Message,
|
||||||
|
ScrapedPostDetails,
|
||||||
|
TagDetails,
|
||||||
|
MessageCategory,
|
||||||
|
PostUploadCommandData,
|
||||||
|
} from "~/models";
|
||||||
import SzuruWrapper from "~/api";
|
import SzuruWrapper from "~/api";
|
||||||
import { ImageSearchResult, Post } from "~/api/models";
|
import { ImageSearchResult, Post } from "~/api/models";
|
||||||
import { isChrome } from "~/env";
|
import { isChrome } from "~/env";
|
||||||
import { Runtime, WebRequest } from "webextension-polyfill";
|
import { Runtime, WebRequest } from "webextension-polyfill";
|
||||||
import { Ref } from "vue";
|
import { Ref } from "vue";
|
||||||
import { Config, SzuruSiteConfig } from "~/config";
|
import { Config } from "~/config";
|
||||||
|
|
||||||
let config = new Config();
|
let config = new Config();
|
||||||
let activeSite = ref<SzuruSiteConfig | undefined>(undefined);
|
let posts = reactive([] as ScrapedPostDetails[]);
|
||||||
let posts = reactive([] as PostDetails[]);
|
let selectedPost = ref(new ScrapedPostDetails(new ScrapedPost()));
|
||||||
let selectedPost = ref(new PostDetails(new ScrapedPost()));
|
|
||||||
let messages = reactive<Message[]>([]);
|
let messages = reactive<Message[]>([]);
|
||||||
let addTagInput = ref("");
|
let addTagInput = ref("");
|
||||||
let autocompleteShown = ref(false);
|
let autocompleteShown = ref(false);
|
||||||
let autocompleteTags = ref<TagDetails[]>([]);
|
let autocompleteTags = ref<TagDetails[]>([]);
|
||||||
let cancelSource = ref<CancelTokenSource | undefined>(undefined);
|
let cancelSource = ref<CancelTokenSource | undefined>(undefined);
|
||||||
let autocompleteIndex = ref(-1);
|
let autocompleteIndex = ref(-1);
|
||||||
|
let selectedSiteId = ref<string | undefined>(undefined);
|
||||||
|
|
||||||
let szuru = computed(() => {
|
const activeSite = computed(() => {
|
||||||
|
if (selectedSiteId.value) {
|
||||||
|
return config.sites.find((x) => x.id == selectedSiteId.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const szuru = computed(() => {
|
||||||
return activeSite.value ? SzuruWrapper.createFromConfig(activeSite.value) : undefined;
|
return activeSite.value ? SzuruWrapper.createFromConfig(activeSite.value) : undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -30,6 +43,11 @@ watch(selectedPost, () => {
|
||||||
findSimilar(selectedPost);
|
findSimilar(selectedPost);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(selectedSiteId, async (x) => {
|
||||||
|
config.selectedSiteId = x;
|
||||||
|
await config.save();
|
||||||
|
});
|
||||||
|
|
||||||
function openOptionsPage() {
|
function openOptionsPage() {
|
||||||
browser.runtime.openOptionsPage();
|
browser.runtime.openOptionsPage();
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +79,7 @@ async function grabPost() {
|
||||||
|
|
||||||
for (const result of res.results) {
|
for (const result of res.results) {
|
||||||
for (const i in result.posts) {
|
for (const i in result.posts) {
|
||||||
const vm = new PostDetails(result.posts[i]);
|
const vm = new ScrapedPostDetails(result.posts[i]);
|
||||||
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
|
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
|
||||||
|
|
||||||
// Add current pageUrl to the source if either
|
// Add current pageUrl to the source if either
|
||||||
|
|
@ -87,13 +105,19 @@ async function grabPost() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function upload() {
|
async function upload() {
|
||||||
|
if (!selectedSiteId.value) {
|
||||||
|
pushError("No site selected!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
|
|
||||||
// Outsource to background.ts
|
// Outsource to background.ts
|
||||||
|
|
||||||
// TODO: Terrible code.
|
// TODO: Terrible code.
|
||||||
const x = JSON.parse(JSON.stringify(selectedPost.value));
|
const post = JSON.parse(JSON.stringify(selectedPost.value));
|
||||||
const cmd = new BrowserCommand("upload_post", x);
|
const cmdData = new PostUploadCommandData(post, selectedSiteId.value);
|
||||||
|
const cmd = new BrowserCommand("upload_post", cmdData);
|
||||||
await browser.runtime.sendMessage(cmd);
|
await browser.runtime.sendMessage(cmd);
|
||||||
// TODO: Handle errors/status update
|
// TODO: Handle errors/status update
|
||||||
}
|
}
|
||||||
|
|
@ -136,23 +160,23 @@ function getMessageClasses(message: Message) {
|
||||||
|
|
||||||
switch (message.level) {
|
switch (message.level) {
|
||||||
case "error":
|
case "error":
|
||||||
classes.push("message-error");
|
classes.push("bg-danger");
|
||||||
break;
|
break;
|
||||||
case "success":
|
case "success":
|
||||||
classes.push("message-success");
|
classes.push("bg-success");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushInfo(message: string, category?: MessageCategory): Message {
|
function pushInfo(message: string, category: MessageCategory = "none"): Message {
|
||||||
let msg = new Message(message, "info", category);
|
let msg = new Message(message, "info", category);
|
||||||
messages.push(msg);
|
messages.push(msg);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushError(message: string, category?: MessageCategory): Message {
|
function pushError(message: string, category: MessageCategory = "none"): Message {
|
||||||
let msg = new Message(message, "error", category);
|
let msg = new Message(message, "error", category);
|
||||||
messages.push(msg);
|
messages.push(msg);
|
||||||
return msg;
|
return msg;
|
||||||
|
|
@ -203,7 +227,7 @@ async function clickFindSimilar() {
|
||||||
return await findSimilar(selectedPost);
|
return await findSimilar(selectedPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findSimilar(post: Ref<PostDetails | undefined>) {
|
async function findSimilar(post: Ref<ScrapedPostDetails | undefined>) {
|
||||||
if (!post.value || !szuru.value) {
|
if (!post.value || !szuru.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -255,7 +279,7 @@ async function findSimilar(post: Ref<PostDetails | undefined>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPostForUrl(contentUrl: string): PostDetails | undefined {
|
function getPostForUrl(contentUrl: string): ScrapedPostDetails | undefined {
|
||||||
for (const post of posts) {
|
for (const post of posts) {
|
||||||
if (post.contentUrl == contentUrl) return post;
|
if (post.contentUrl == contentUrl) return post;
|
||||||
}
|
}
|
||||||
|
|
@ -368,14 +392,10 @@ async function autocompletePopulator(input: string) {
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
config = await Config.load();
|
config = await Config.load();
|
||||||
|
selectedSiteId.value = config.selectedSiteId;
|
||||||
|
|
||||||
activeSite.value = config.sites.length > 0 ? config.sites[0] : undefined;
|
if (config.sites.length == 0) {
|
||||||
|
|
||||||
if (!activeSite.value) {
|
|
||||||
pushError("No szurubooru server configured!", "persistent");
|
pushError("No szurubooru server configured!", "persistent");
|
||||||
} else {
|
|
||||||
// TODO: We can probably delete this code, because of the computed(() => ...);
|
|
||||||
// szuru = SzuruWrapper.createFromConfig(this.activeSite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener((cmd: BrowserCommand, _sender: Runtime.MessageSender) => {
|
browser.runtime.onMessage.addListener((cmd: BrowserCommand, _sender: Runtime.MessageSender) => {
|
||||||
|
|
@ -527,8 +547,10 @@ useDark();
|
||||||
|
|
||||||
<div class="popup-section">
|
<div class="popup-section">
|
||||||
<div class="section-row">
|
<div class="section-row">
|
||||||
<select disabled>
|
<select v-model="selectedSiteId">
|
||||||
<option>{{ activeSite ? activeSite.domain : "(no site available)" }}</option>
|
<option v-for="site in config.sites" :key="site.id" :value="site.id">
|
||||||
|
{{ site.domain }}
|
||||||
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,50 @@
|
||||||
|
@use "sass:color";
|
||||||
|
|
||||||
|
@import "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);
|
||||||
|
}
|
||||||
|
|
||||||
/* open-sans-regular - latin */
|
/* open-sans-regular - latin */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Open Sans";
|
font-family: "Open Sans";
|
||||||
|
|
@ -11,14 +58,21 @@ body {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$primary-color: #24aadd;
|
||||||
|
$danger-color: #f44336;
|
||||||
|
|
||||||
|
$primary-color-dark: color.scale($primary-color, $lightness: -40%);
|
||||||
|
$danger-color-dark: color.scale($danger-color, $lightness: -50%);
|
||||||
|
// TODO: Darker success color
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--button-bg-color: #a2a2a2;
|
--button-bg-color: #a2a2a2;
|
||||||
--primary-color: #24aadd;
|
--primary-color: #{$primary-color};
|
||||||
--bg-main-color: #fff;
|
--bg-main-color: #fff;
|
||||||
--bg-secondary-color: #fafafa;
|
--bg-secondary-color: #fafafa;
|
||||||
--border-color: #eee;
|
--border-color: #eee;
|
||||||
--secondary-text: #888;
|
--secondary-text: #888;
|
||||||
--error-color: #f44336;
|
--danger-color: #{$danger-color};
|
||||||
--success-color: #4caf50;
|
--success-color: #4caf50;
|
||||||
--section-header-fg-color: #4c4c4c;
|
--section-header-fg-color: #4c4c4c;
|
||||||
--section-header-bg-color: #eee;
|
--section-header-bg-color: #eee;
|
||||||
|
|
@ -27,10 +81,11 @@ body {
|
||||||
|
|
||||||
html.dark {
|
html.dark {
|
||||||
--button-bg-color: #666;
|
--button-bg-color: #666;
|
||||||
--primary-color: #1b87b0;
|
--primary-color: #{$primary-color-dark};
|
||||||
--bg-main-color: #1a1a1a;
|
--bg-main-color: #1a1a1a;
|
||||||
--bg-secondary-color: #3e3e3e;
|
--bg-secondary-color: #3e3e3e;
|
||||||
--border-color: #474747;
|
--border-color: #474747;
|
||||||
|
--danger-color: #{$danger-color-dark};
|
||||||
--section-header-fg-color: #d9d9d9;
|
--section-header-fg-color: #d9d9d9;
|
||||||
--section-header-bg-color: #272727;
|
--section-header-bg-color: #272727;
|
||||||
--text-color: #e6e6e6;
|
--text-color: #e6e6e6;
|
||||||
|
|
@ -207,10 +262,10 @@ a.remove-tag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-error {
|
.bg-danger {
|
||||||
background: var(--error-color) !important;
|
background: var(--danger-color) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-success {
|
.bg-success {
|
||||||
background: var(--success-color) !important;
|
background: var(--success-color) !important;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue