Compare commits
4 Commits
master
...
gh-actions
| Author | SHA1 | Date |
|---|---|---|
|
|
82dfc45e3b | |
|
|
530e3fc8d8 | |
|
|
c1f6686d2a | |
|
|
160b59a9a3 |
|
|
@ -23,7 +23,5 @@ module.exports = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
"eol-last": ["error", "always"],
|
|
||||||
"comma-dangle": ["error", "always-multiline"],
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,25 +14,23 @@ runs:
|
||||||
- name: Determine Version
|
- name: Determine Version
|
||||||
uses: gittools/actions/gitversion/execute@v0
|
uses: gittools/actions/gitversion/execute@v0
|
||||||
id: version
|
id: version
|
||||||
with:
|
|
||||||
useConfigFile: true
|
|
||||||
|
|
||||||
- name: Use the version
|
- name: Use the version
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
echo VITE_SZ_VERSION="${{ steps.version.outputs.AssemblySemFileVer }}" >> $GITHUB_ENV
|
echo SZ_VERSION="${{ steps.version.outputs.AssemblySemFileVer }}" >> $GITHUB_ENV
|
||||||
echo VITE_SZ_VERSION_INFO="${{ steps.version.outputs.InformationalVersion }}" >> $GITHUB_ENV
|
echo SZ_VERSION_NAME="${{ steps.version.outputs.InformationalVersion }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v2
|
- uses: pnpm/action-setup@v2
|
||||||
name: Install pnpm
|
name: Install pnpm
|
||||||
id: pnpm-install
|
id: pnpm-install
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 7
|
||||||
run_install: false
|
run_install: false
|
||||||
|
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: "20"
|
node-version: "16"
|
||||||
cache: "pnpm"
|
cache: "pnpm"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,9 @@
|
||||||
name: Build release
|
name: Build release
|
||||||
on:
|
on: [push]
|
||||||
push:
|
|
||||||
paths:
|
|
||||||
- src/**
|
|
||||||
- extension/**
|
|
||||||
- package.json
|
|
||||||
- pnpm-lock.yaml
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
publish_amo_listed:
|
|
||||||
description: "Publish to AMO"
|
|
||||||
required: false
|
|
||||||
type: boolean
|
|
||||||
jobs:
|
jobs:
|
||||||
build_chrome:
|
build_chrome:
|
||||||
name: "Build Chrome Extension"
|
name: "Build Chrome Extension"
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
@ -30,17 +18,17 @@ jobs:
|
||||||
- name: Pack ZIP
|
- name: Pack ZIP
|
||||||
run: pnpm pack:zip
|
run: pnpm pack:zip
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: Chrome Extension (Unsigned)
|
name: Chrome Extension (Unsigned)
|
||||||
path: extension.zip
|
path: extension.zip
|
||||||
|
|
||||||
build_unlisted_firefox:
|
build_firefox:
|
||||||
name: "Build Unlisted Firefox Extension"
|
name: "Build Firefox Extension"
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-20.04
|
||||||
# Doesn't really need the Chrome build, but we can reuse its cache.
|
# Doesn't really need the Chrome build, but we can reuse its cache.
|
||||||
needs: build_chrome
|
needs: build_chrome
|
||||||
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
|
if: github.ref == 'refs/heads/master'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
@ -55,41 +43,12 @@ jobs:
|
||||||
SZ_GECKO_ID: 13372607-2257-4360-8f51-5ce66fa73350
|
SZ_GECKO_ID: 13372607-2257-4360-8f51-5ce66fa73350
|
||||||
|
|
||||||
- name: Sign XPI
|
- name: Sign XPI
|
||||||
run: pnpm sign:firefox --channel unlisted
|
run: pnpm sign:firefox
|
||||||
env:
|
env:
|
||||||
WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
|
WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
|
||||||
WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}
|
WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}
|
||||||
|
|
||||||
- name: Rename XPI
|
- uses: actions/upload-artifact@v3
|
||||||
run: rename.ul szuruchrome_gh- SzuruChrome-v web-ext-artifacts/*.xpi
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
with:
|
||||||
name: Firefox Extension (Signed)
|
name: Firefox Extension (Signed)
|
||||||
path: web-ext-artifacts/*.xpi
|
path: web-ext-artifacts/*.xpi
|
||||||
|
|
||||||
build_amo_firefox:
|
|
||||||
name: "Build Firefox Extension for AMO"
|
|
||||||
runs-on: ubuntu-24.04
|
|
||||||
# Doesn't really need the Chrome build, but we can reuse its cache.
|
|
||||||
needs: build_chrome
|
|
||||||
# Only run (on master branch && if tagged) or (manually dispatching).
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.publish_amo_listed == true
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- uses: ./.github/actions/setup-for-build
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: pnpm build
|
|
||||||
env:
|
|
||||||
SZ_GECKO_ID: 18365332-8485-4c04-9498-2843a41ab620
|
|
||||||
|
|
||||||
- name: Sign XPI and upload to AMO
|
|
||||||
run: pnpm sign:firefox --channel listed
|
|
||||||
env:
|
|
||||||
WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
|
|
||||||
WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{
|
{
|
||||||
"printWidth": 120,
|
"printWidth": 120,
|
||||||
"tabWidth": 2
|
"tabWidth": 2
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
{
|
{
|
||||||
"recommendations": ["vue.volar", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
|
"recommendations": [
|
||||||
|
"vue.volar",
|
||||||
|
"dbaeumer.vscode-eslint",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"typescript.tsdk": "node_modules/typescript/lib",
|
"typescript.tsdk": "node_modules/typescript/lib",
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": "explicit"
|
"source.fixAll.eslint": true
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
42
README.md
42
README.md
|
|
@ -2,22 +2,39 @@
|
||||||
|
|
||||||
Chrome/Firefox extension which can import media from various sites into a [szurubooru](https://github.com/rr-/szurubooru) instance.
|
Chrome/Firefox extension which can import media from various sites into a [szurubooru](https://github.com/rr-/szurubooru) instance.
|
||||||
|
|
||||||

|
## Supported sites
|
||||||
|
|
||||||
|
| Engine | Sites | Features | Notes |
|
||||||
|
| -------------- | ------------------------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------- |
|
||||||
|
| animepictures | anime-pictures.net | content, resolution, tags, tag_category | Rating is assumed to be safe. |
|
||||||
|
| danbooru | danbooru.donmai.us, safebooru.donmai.us | content, rating, resolution, tags, tag_category, source, notes | |
|
||||||
|
| e621 | e621.net, e926.net | content, rating, resolution, tags, tag_category, source | |
|
||||||
|
| furaffinity | www.furaffinity.net | content, rating, resolution, tags, tag_category | |
|
||||||
|
| gelbooru | safebooru.org, gelbooru.com, rule34.xxx, tbib.org, xbooru.com | content, rating, resolution, tags, tag_category, source, notes | Supported features might vary between hosts. |
|
||||||
|
| inkbunny | inkbunny.net | content, rating, resolution, tags | |
|
||||||
|
| moebooru | yande.re, konachan.com | content, rating, resolution, tags, tag_category, source, notes | |
|
||||||
|
| pixiv | pixiv.net, www.pixiv.net | content | |
|
||||||
|
| reddit | reddit.com, new.reddit.com, old.reddit.com | content | |
|
||||||
|
| rule34us | rule34.us | content, resolution, tags, tag_category | Rating is assumed to be unsafe. |
|
||||||
|
| sankakucomplex | chan.sankakucomplex.com | content, rating, tags, tag_category, notes | Hotlink protection currently prevents szurubooru from importing from this site. |
|
||||||
|
| shimmie2 | rule34.paheal.net, rule34hentai.net | content, tags, source | Rating is assumed to be unsafe. |
|
||||||
|
| shuushuu | e-shuushuu.net | content, rating, resolution, tags, tag_category | Rating is assumed to be safe. |
|
||||||
|
| twitter | twitter.com, mobile.twitter.com | content | |
|
||||||
|
| zerochan | www.zerochan.net | content, resolution, tags, tag_category | Rating is assumed to be safe. |
|
||||||
|
| fallback | | content | Tries to find the largest image or video on the current page. |
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
For development see [build/debug](#Builddebug).
|
||||||
|
|
||||||
### Firefox
|
### Firefox
|
||||||
|
|
||||||
I am experimenting with publishing the extension to Firefox Add-ons. You can find it [here](https://addons.mozilla.org/en-US/firefox/addon/szuruchrome/). This version will automatically update.
|
Just download the .xpi from [release tab](https://github.com/neobooru/SzuruChrome/releases) and install it.
|
||||||
|
|
||||||
You can also download the .xpi from the [release tab](https://github.com/neobooru/SzuruChrome/releases) and manually install it. This version will not automatically update.
|
|
||||||
|
|
||||||
Both versions can be installed side by side, as they do not affect each other. This also means that you need to configure both of them independently.
|
|
||||||
|
|
||||||
### Chrome
|
### Chrome
|
||||||
|
|
||||||
I can't create a valid .crx file, which means that you'll have to use [Chrome's "Load unpacked extension"](https://developer.chrome.com/docs/extensions/mv3/getstarted/#unpacked) feature.
|
I can't create a valid .crx file, which means that you'll have to use [Chrome's "Load unpacked extension"](https://developer.chrome.com/docs/extensions/mv3/getstarted/#unpacked) feature.
|
||||||
You can download a .zip containing the needed files from the [release tab](https://github.com/neobooru/SzuruChrome/releases). Check [this Stack Overflow answer](https://stackoverflow.com/a/38011386) if you want to get rid of the developer extension popup.
|
You can download a .zip containing the needed files from the [release tab](https://github.com/neobooru/SzuruChrome/releases). Check [this stackoverflow answer](https://stackoverflow.com/a/38011386) if you want to get rid of the developer extension popup.
|
||||||
|
|
||||||
## Build/debug
|
## Build/debug
|
||||||
|
|
||||||
|
|
@ -36,4 +53,13 @@ After this you can load them in your browser.
|
||||||
Chrome: `chrome://extensions/` → "Load unpacked" → Select `./dist` folder
|
Chrome: `chrome://extensions/` → "Load unpacked" → Select `./dist` folder
|
||||||
Firefox: `about:debugging` → "Load Temporary Add-on..." → Select any file in the `./dist` folder (it will load all files)
|
Firefox: `about:debugging` → "Load Temporary Add-on..." → Select any file in the `./dist` folder (it will load all files)
|
||||||
|
|
||||||
See [the developer notes](https://github.com/neobooru/SzuruChrome/wiki/Developer-notes) for more information.
|
See [the developer docs](./docs/DEVELOPER.md) for more information.
|
||||||
|
|
||||||
|
## Planned features
|
||||||
|
|
||||||
|
These are some things I might work on. Though honestly I don't expect this extension to change much anytime soon.
|
||||||
|
|
||||||
|
- Finishing the initial version of this add-on (see visual design doc for all features)
|
||||||
|
- Right click any image on a page to import it
|
||||||
|
- Configurable list of tags to always ignore (e.g. tagme, highres)
|
||||||
|
- [low priority] Import artist commentary
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 350 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 306 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 293 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 33 KiB |
87
package.json
87
package.json
|
|
@ -4,6 +4,7 @@
|
||||||
"description": "Import media from various sites into szurubooru.",
|
"description": "Import media from various sites into szurubooru.",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"packageManager": "pnpm@7.8.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "npm run clear && cross-env NODE_ENV=development run-p dev:*",
|
"dev": "npm run clear && cross-env NODE_ENV=development run-p dev:*",
|
||||||
"dev:prepare": "esno scripts/prepare.ts",
|
"dev:prepare": "esno scripts/prepare.ts",
|
||||||
|
|
@ -19,63 +20,59 @@
|
||||||
"pack:xpi": "cross-env WEB_EXT_ARTIFACTS_DIR=./ web-ext build --source-dir ./extension --filename extension.xpi --overwrite-dest",
|
"pack:xpi": "cross-env WEB_EXT_ARTIFACTS_DIR=./ web-ext build --source-dir ./extension --filename extension.xpi --overwrite-dest",
|
||||||
"start:chromium": "web-ext run --source-dir ./extension --target=chromium",
|
"start:chromium": "web-ext run --source-dir ./extension --target=chromium",
|
||||||
"start:firefox": "web-ext run --source-dir ./extension --target=firefox-desktop",
|
"start:firefox": "web-ext run --source-dir ./extension --target=firefox-desktop",
|
||||||
"sign:firefox": "web-ext sign --source-dir ./extension",
|
"sign:firefox": "web-ext sign --use-submission-api --source-dir ./extension --channel unlisted",
|
||||||
"clear": "rimraf extension/dist extension/manifest.json extension.*",
|
"clear": "rimraf extension/dist extension/manifest.json extension.*",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"extlint": "web-ext lint -s extension",
|
"test": "vitest test"
|
||||||
"test": "vitest test",
|
|
||||||
"pretty": "prettier -w ."
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.19.0",
|
"axios": "^1.2.2",
|
||||||
"byte-size": "^8.2.1",
|
"basscss": "^8.1.0",
|
||||||
|
"byte-size": "^8.1.1",
|
||||||
"deepmerge": "^4.3.1",
|
"deepmerge": "^4.3.1",
|
||||||
"lodash": "^4.18.1",
|
"lodash": "^4.17.21",
|
||||||
"markdown-it": "^14.3.0",
|
"markdown-it": "^13.0.1",
|
||||||
"neo-scraper": "^0.11.1",
|
"neo-scraper": "^0.7.1",
|
||||||
"normalize.css": "^8.0.1",
|
"normalize.css": "^8.0.1",
|
||||||
"pinia": "^2.3.1",
|
"pinia": "^2.0.36",
|
||||||
"primeflex": "^3.3.1",
|
"vue-router": "4"
|
||||||
"primevue": "3.45.0",
|
|
||||||
"vue-router": "^4.6.4"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ffflorian/jszip-cli": "^3.16.5",
|
"@ffflorian/jszip-cli": "^3.1.6",
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
"@fortawesome/fontawesome-svg-core": "^6.2.1",
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
"@fortawesome/free-solid-svg-icons": "^6.2.1",
|
||||||
"@fortawesome/vue-fontawesome": "^3.3.3",
|
"@fortawesome/vue-fontawesome": "^3.0.3",
|
||||||
"@types/byte-size": "^8.1.2",
|
"@types/byte-size": "^8.1.0",
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/lodash": "^4.17.25",
|
"@types/lodash": "^4.14.194",
|
||||||
"@types/markdown-it": "^13.0.9",
|
"@types/markdown-it": "^12.2.3",
|
||||||
"@types/node": "^20.19.43",
|
"@types/node": "^18.11.9",
|
||||||
"@types/webextension-polyfill": "^0.10.7",
|
"@types/webextension-polyfill": "^0.9.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
||||||
"@vitejs/plugin-vue": "^5.2.4",
|
"@vitejs/plugin-vue": "^3.2.0",
|
||||||
"@vue/compiler-sfc": "^3.5.41",
|
"@vue/compiler-sfc": "^3.2.45",
|
||||||
"@vue/test-utils": "^2.4.11",
|
"@vue/test-utils": "^2.2.4",
|
||||||
"@vueuse/core": "^10.11.1",
|
"@vueuse/core": "^9.6.0",
|
||||||
"chokidar": "^3.6.0",
|
"chokidar": "^3.5.3",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"crx": "^5.0.1",
|
"crx": "^5.0.1",
|
||||||
"eslint": "^8.57.1",
|
"eslint": "^8.32.0",
|
||||||
"eslint-plugin-vue": "^9.33.0",
|
"eslint-plugin-vue": "^9.9.0",
|
||||||
"esno": "^4.8.0",
|
"esno": "^0.16.3",
|
||||||
"fs-extra": "^11.4.0",
|
"fs-extra": "^10.1.0",
|
||||||
"jsdom": "^23.2.0",
|
"jsdom": "^20.0.3",
|
||||||
"kolorist": "^1.8.0",
|
"kolorist": "^1.6.0",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"prettier": "^3.9.6",
|
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"sass": "^1.102.0",
|
"sass": "^1.57.1",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^4.9.3",
|
||||||
"unplugin-auto-import": "^0.17.8",
|
"unplugin-auto-import": "^0.12.2",
|
||||||
"unplugin-vue-components": "^0.26.0",
|
"unplugin-vue-components": "^0.23.0",
|
||||||
"vite": "^5.4.21",
|
"vite": "^3.2.4",
|
||||||
"vitest": "^1.6.1",
|
"vitest": "^0.25.3",
|
||||||
"vue": "^3.5.41",
|
"vue": "^3.2.45",
|
||||||
"vue-eslint-parser": "^9.4.3",
|
"vue-eslint-parser": "^9.1.0",
|
||||||
"web-ext": "^8.10.0",
|
"web-ext": "^7.5.0",
|
||||||
"webextension-polyfill": "^0.10.0"
|
"webextension-polyfill": "^0.10.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10999
pnpm-lock.yaml
10999
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -1,9 +1,9 @@
|
||||||
import { resolve } from "path";
|
import { resolve } from 'path';
|
||||||
import { bgCyan, black } from "kolorist";
|
import { bgCyan, black } from 'kolorist';
|
||||||
|
|
||||||
export const port = parseInt(process.env.PORT || "") || 3303;
|
export const port = parseInt(process.env.PORT || '') || 3303;
|
||||||
export const r = (...args: string[]) => resolve(__dirname, "..", ...args);
|
export const r = (...args: string[]) => resolve(__dirname, '..', ...args);
|
||||||
export const isDev = process.env.NODE_ENV !== "production";
|
export const isDev = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
export function log(name: string, message: string) {
|
export function log(name: string, message: string) {
|
||||||
console.log(black(bgCyan(` ${name} `)), message);
|
console.log(black(bgCyan(` ${name} `)), message);
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,9 @@ import {
|
||||||
TagFields,
|
TagFields,
|
||||||
TemporaryFileUploadResult,
|
TemporaryFileUploadResult,
|
||||||
UpdatePostRequest,
|
UpdatePostRequest,
|
||||||
PoolsResult,
|
|
||||||
PoolFields,
|
|
||||||
Pool,
|
|
||||||
UpdatePoolRequest,
|
|
||||||
} from "./models";
|
} from "./models";
|
||||||
import { ScrapedPostDetails, SzuruSiteConfig } from "~/models";
|
import { ScrapedPostDetails } from "~/models";
|
||||||
import { UploadMode } from "neo-scraper";
|
import { SzuruSiteConfig } from "~/config";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 1:1 wrapper around the szurubooru API.
|
* A 1:1 wrapper around the szurubooru API.
|
||||||
|
|
@ -68,7 +64,7 @@ export default class SzurubooruApi {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
limit = 100,
|
limit = 100,
|
||||||
fields?: TagFields[],
|
fields?: TagFields[],
|
||||||
cancelToken?: CancelToken,
|
cancelToken?: CancelToken
|
||||||
): Promise<TagsResult> {
|
): Promise<TagsResult> {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.append("offset", offset.toString());
|
params.append("offset", offset.toString());
|
||||||
|
|
@ -104,40 +100,6 @@ export default class SzurubooruApi {
|
||||||
return (await this.apiPost("posts", obj)).data;
|
return (await this.apiPost("posts", obj)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPool(name: string, category: string, posts?: number[]): Promise<Pool> {
|
|
||||||
const obj = <any>{
|
|
||||||
names: [name],
|
|
||||||
category,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (posts) {
|
|
||||||
obj.posts = posts;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (await this.apiPost("pool", obj)).data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPools(
|
|
||||||
query?: string,
|
|
||||||
offset = 0,
|
|
||||||
limit = 100,
|
|
||||||
fields?: PoolFields[],
|
|
||||||
cancelToken?: CancelToken,
|
|
||||||
): Promise<PoolsResult> {
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("offset", offset.toString());
|
|
||||||
params.append("limit", limit.toString());
|
|
||||||
|
|
||||||
if (fields && fields.length > 0) params.append("fields", fields.join());
|
|
||||||
if (query) params.append("query", query);
|
|
||||||
|
|
||||||
return (await this.apiGet("pools?" + params.toString(), {}, cancelToken)).data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async updatePool(id: number, updateRequest: UpdatePoolRequest): Promise<Pool> {
|
|
||||||
return (await this.apiPut("pool/" + id, updateRequest)).data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async reverseSearch(contentUrl: string): Promise<ImageSearchResult> {
|
async reverseSearch(contentUrl: string): Promise<ImageSearchResult> {
|
||||||
const obj = { contentUrl };
|
const obj = { contentUrl };
|
||||||
return (await this.apiPost("posts/reverse-search", obj)).data;
|
return (await this.apiPost("posts/reverse-search", obj)).data;
|
||||||
|
|
@ -148,42 +110,11 @@ export default class SzurubooruApi {
|
||||||
return (await this.apiPost("posts/reverse-search", obj)).data;
|
return (await this.apiPost("posts/reverse-search", obj)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadTempFile(contentUrl: string, uploadMode: UploadMode): Promise<TemporaryFileUploadResult> {
|
async uploadTempFile(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
||||||
// For some sources we need to download the image to the client and then upload it to szurubooru.
|
|
||||||
// We can't just pass the contentUrl because that would trigger the bot/hotlink protection.
|
|
||||||
|
|
||||||
if (uploadMode == "content") {
|
|
||||||
console.log("Upload from content");
|
|
||||||
return this.uploadTempFileFromContent(contentUrl);
|
|
||||||
} else {
|
|
||||||
console.log("Upload from URL");
|
|
||||||
return this.uploadTempFileFromUrl(contentUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async uploadTempFileFromUrl(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
|
||||||
const obj = { contentUrl };
|
const obj = { contentUrl };
|
||||||
return (await this.apiPost("uploads", obj)).data;
|
return (await this.apiPost("uploads", obj)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadTempFileFromContent(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
|
||||||
const content = await (await fetch(contentUrl)).blob();
|
|
||||||
|
|
||||||
const fullUrl = this.apiUrl + "uploads";
|
|
||||||
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("content", content);
|
|
||||||
|
|
||||||
const config: AxiosRequestConfig = {
|
|
||||||
method: "POST",
|
|
||||||
url: fullUrl,
|
|
||||||
data: formData,
|
|
||||||
};
|
|
||||||
|
|
||||||
config.headers = { ...this.baseHeaders, "Content-Type": "multipart/form-data" };
|
|
||||||
return (await this.execute(config)).data;
|
|
||||||
}
|
|
||||||
|
|
||||||
static createFromConfig(siteConfig: SzuruSiteConfig): SzurubooruApi {
|
static createFromConfig(siteConfig: SzuruSiteConfig): SzurubooruApi {
|
||||||
return new SzurubooruApi(siteConfig.domain, siteConfig.username, siteConfig.authToken);
|
return new SzurubooruApi(siteConfig.domain, siteConfig.username, siteConfig.authToken);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type Safety = "safe" | "sketchy" | "unsafe";
|
export type Safety = "safe" | "sketchy" | "unsafe";
|
||||||
export type TagFields = "version" | "names" | "category" | "usages" | "implications";
|
export type TagFields = "names" | "category" | "usages" | "implications";
|
||||||
export type PoolFields = "version" | "id" | "names" | "category" | "description" | "postCount" | "posts";
|
|
||||||
|
|
||||||
export type TagsResult = PagedSearchResult<Tag>;
|
export type TagsResult = PagedSearchResult<Tag>;
|
||||||
export type PoolsResult = PagedSearchResult<Pool>;
|
|
||||||
export type TagCategoriesResult = UnpagedSearchResult<TagCategory>;
|
export type TagCategoriesResult = UnpagedSearchResult<TagCategory>;
|
||||||
|
|
||||||
export interface SzuruError {
|
export interface SzuruError {
|
||||||
|
|
@ -39,28 +37,18 @@ export interface MicroTag {
|
||||||
usages: number;
|
usages: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Tag extends MicroTag {
|
export interface Tag {
|
||||||
|
names: string[];
|
||||||
|
category: string;
|
||||||
version: number;
|
version: number;
|
||||||
description?: string; // Markdown
|
description?: string; // Markdown
|
||||||
creationTime: Date;
|
creationTime: Date;
|
||||||
lastEditTime?: Date;
|
lastEditTime?: Date;
|
||||||
|
usages: number;
|
||||||
suggestions: MicroTag[];
|
suggestions: MicroTag[];
|
||||||
implications: MicroTag[];
|
implications: MicroTag[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* All fields can be optional.
|
|
||||||
*/
|
|
||||||
export interface Pool {
|
|
||||||
id: number;
|
|
||||||
names: string[];
|
|
||||||
category: string;
|
|
||||||
version: number;
|
|
||||||
description: null;
|
|
||||||
postCount: number;
|
|
||||||
posts: MicroPost[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TagCategory {
|
export interface TagCategory {
|
||||||
name: string;
|
name: string;
|
||||||
version: number;
|
version: number;
|
||||||
|
|
@ -74,12 +62,8 @@ export interface MicroUser {
|
||||||
avatarUrl: string;
|
avatarUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MicroPost {
|
export interface Post {
|
||||||
id: number;
|
id: number;
|
||||||
thumbnailUrl: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Post extends MicroPost {
|
|
||||||
version: number;
|
version: number;
|
||||||
creationTime: Date;
|
creationTime: Date;
|
||||||
lastEditTime?: Date;
|
lastEditTime?: Date;
|
||||||
|
|
@ -92,6 +76,7 @@ export interface Post extends MicroPost {
|
||||||
canvasWidth: number;
|
canvasWidth: number;
|
||||||
canvasHeight: number;
|
canvasHeight: number;
|
||||||
contentUrl: string;
|
contentUrl: string;
|
||||||
|
thumbnailUrl: string;
|
||||||
flags: string[];
|
flags: string[];
|
||||||
tags: MicroTag[];
|
tags: MicroTag[];
|
||||||
relations: any[]; // MicroPost resource
|
relations: any[]; // MicroPost resource
|
||||||
|
|
@ -142,9 +127,3 @@ export interface UpdatePostRequest {
|
||||||
contentUrl: string | undefined;
|
contentUrl: string | undefined;
|
||||||
contentToken: string | undefined;
|
contentToken: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdatePoolRequest {
|
|
||||||
version: number;
|
|
||||||
// names?: string[];
|
|
||||||
posts: number[];
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { encodeTagName, getErrorMessage, getUrl } from "~/utils";
|
import { encodeTagName, getErrorMessage } from "~/utils";
|
||||||
import {
|
import {
|
||||||
BrowserCommand,
|
BrowserCommand,
|
||||||
PostUploadCommandData,
|
PostUploadCommandData,
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
PostUpdateCommandData,
|
PostUpdateCommandData,
|
||||||
FetchCommandData,
|
FetchCommandData,
|
||||||
} from "~/models";
|
} from "~/models";
|
||||||
import { PostAlreadyUploadedError, UpdatePoolRequest } from "~/api/models";
|
import { PostAlreadyUploadedError } from "~/api/models";
|
||||||
import SzurubooruApi from "~/api";
|
import SzurubooruApi from "~/api";
|
||||||
|
|
||||||
// Only on dev mode
|
// Only on dev mode
|
||||||
|
|
@ -19,13 +19,6 @@ if (import.meta.hot) {
|
||||||
import("./contentScriptHMR");
|
import("./contentScriptHMR");
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.notifications.onClicked.addListener((url) => {
|
|
||||||
if (url) {
|
|
||||||
browser.tabs.create({ url });
|
|
||||||
browser.notifications.clear(url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async function uploadPost(data: PostUploadCommandData) {
|
async function uploadPost(data: PostUploadCommandData) {
|
||||||
const info: PostUploadInfo = {
|
const info: PostUploadInfo = {
|
||||||
state: "uploading",
|
state: "uploading",
|
||||||
|
|
@ -33,7 +26,7 @@ async function uploadPost(data: PostUploadCommandData) {
|
||||||
|
|
||||||
const pushInfo = () =>
|
const pushInfo = () =>
|
||||||
browser.runtime.sendMessage(
|
browser.runtime.sendMessage(
|
||||||
new BrowserCommand("set_post_upload_info", new SetPostUploadInfoData(data.selectedSite.id, data.post.id, info)),
|
new BrowserCommand("set_post_upload_info", new SetPostUploadInfoData(data.selectedSite.id, data.post.id, info))
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -43,12 +36,6 @@ async function uploadPost(data: PostUploadCommandData) {
|
||||||
pushInfo();
|
pushInfo();
|
||||||
|
|
||||||
const contentToken = data.post.instanceSpecificData[data.selectedSite.id]?.contentToken;
|
const contentToken = data.post.instanceSpecificData[data.selectedSite.id]?.contentToken;
|
||||||
|
|
||||||
if (!contentToken) {
|
|
||||||
// TODO: If donmai URL is the source then we need to do the uploadTempFileFromContent here!
|
|
||||||
console.log("contentToken is undefined. This could be a problem for some sources!");
|
|
||||||
}
|
|
||||||
|
|
||||||
const createdPost = await szuru.createPost(data.post, contentToken);
|
const createdPost = await szuru.createPost(data.post, contentToken);
|
||||||
|
|
||||||
info.state = "uploaded";
|
info.state = "uploaded";
|
||||||
|
|
@ -86,7 +73,7 @@ async function uploadPost(data: PostUploadCommandData) {
|
||||||
categoriesChangedCount++;
|
categoriesChangedCount++;
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
`Not adding the '${wantedCategory}' category to the tag '${tags[i].names[0]}' because the szurubooru instance does not have this category.`,
|
`Not adding the '${wantedCategory}' category to the tag '${tags[i].names[0]}' because the szurubooru instance does not have this category.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -97,49 +84,11 @@ async function uploadPost(data: PostUploadCommandData) {
|
||||||
pushInfo();
|
pushInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This code shouldn't all be in the same try catch.
|
|
||||||
// Add post to pools
|
|
||||||
for (const scrapedPool of data.post.pools) {
|
|
||||||
// Attention! Don't use the .name getter as it does not exist. Just use names[0].
|
|
||||||
const existingPools = await szuru.getPools(encodeTagName(scrapedPool.names[0]), 0, 1, ["id", "posts", "version"]);
|
|
||||||
|
|
||||||
if (existingPools.results.length == 0) {
|
|
||||||
// Pool does not exist. Create a new pool and add the post to it in one API call.
|
|
||||||
console.log(`Creating new pool ${scrapedPool.names[0]} and adding post ${createdPost.id}.`);
|
|
||||||
await szuru.createPool(scrapedPool.names[0], "default", [createdPost.id]);
|
|
||||||
} else {
|
|
||||||
// Pool exists, so add it to the existing pool.
|
|
||||||
const existingPool = existingPools.results[0];
|
|
||||||
const posts = existingPool.posts.map((x) => x.id);
|
|
||||||
posts.push(createdPost.id);
|
|
||||||
|
|
||||||
console.log(`Adding post ${createdPost.id} to existing pool ${existingPool.id}`);
|
|
||||||
|
|
||||||
const updateRequest = <UpdatePoolRequest>{
|
|
||||||
version: existingPool.version,
|
|
||||||
posts,
|
|
||||||
};
|
|
||||||
|
|
||||||
await szuru.updatePool(existingPool.id, updateRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.sendNotifications && browser.notifications) {
|
|
||||||
const createdPostUrl = getUrl(data.selectedSite.domain, "post", createdPost.id.toString());
|
|
||||||
browser.notifications.create(createdPostUrl, {
|
|
||||||
type: "basic",
|
|
||||||
iconUrl: browser.runtime.getURL("assets/icon-128.png"),
|
|
||||||
title: data.selectedSite.domain,
|
|
||||||
message: `Uploaded ${data.post.contentUrl}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.error(ex);
|
|
||||||
if (ex.name && ex.name == "PostAlreadyUploadedError") {
|
if (ex.name && ex.name == "PostAlreadyUploadedError") {
|
||||||
const otherPostId = (ex as PostAlreadyUploadedError).otherPostId;
|
const otherPostId = (ex as PostAlreadyUploadedError).otherPostId;
|
||||||
browser.runtime.sendMessage(
|
browser.runtime.sendMessage(
|
||||||
new BrowserCommand("set_exact_post_id", new SetExactPostId(data.selectedSite.id, data.post.id, otherPostId)),
|
new BrowserCommand("set_exact_post_id", new SetExactPostId(data.selectedSite.id, data.post.id, otherPostId))
|
||||||
);
|
);
|
||||||
// We don't set an error message, because we have a different message for posts that are already uploaded.
|
// We don't set an error message, because we have a different message for posts that are already uploaded.
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -161,8 +110,8 @@ async function updatePost(data: PostUpdateCommandData) {
|
||||||
browser.runtime.sendMessage(
|
browser.runtime.sendMessage(
|
||||||
new BrowserCommand(
|
new BrowserCommand(
|
||||||
"set_post_update_info",
|
"set_post_update_info",
|
||||||
new SetPostUploadInfoData(data.selectedSite.id, `merge-${data.postId}`, info),
|
new SetPostUploadInfoData(data.selectedSite.id, `merge-${data.postId}`, info)
|
||||||
),
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -175,7 +124,6 @@ async function updatePost(data: PostUpdateCommandData) {
|
||||||
info.state = "uploaded";
|
info.state = "uploaded";
|
||||||
pushInfo();
|
pushInfo();
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.error(ex);
|
|
||||||
info.state = "error";
|
info.state = "error";
|
||||||
info.error = getErrorMessage(ex);
|
info.error = getErrorMessage(ex);
|
||||||
pushInfo();
|
pushInfo();
|
||||||
|
|
|
||||||
|
|
@ -1,154 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import axios, { CancelTokenSource } from "axios";
|
|
||||||
|
|
||||||
const inputText = ref("");
|
|
||||||
const autocompleteShown = ref(false);
|
|
||||||
const cancelSource = ref<CancelTokenSource | undefined>(undefined);
|
|
||||||
const autocompleteIndex = ref(-1);
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
autocompleteItems: {
|
|
||||||
type: Array<any>,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const emit = defineEmits(["addItem", "addFromCurrentInput", "autocompletePopulator"]);
|
|
||||||
|
|
||||||
function addItem(item: any) {
|
|
||||||
emit("addItem", item);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onAddItemKeyUp(e: KeyboardEvent) {
|
|
||||||
await autocompletePopulator((<HTMLInputElement>e.target).value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addItemFromCurrentInput() {
|
|
||||||
emit("addFromCurrentInput", inputText.value);
|
|
||||||
inputText.value = ""; // Reset input
|
|
||||||
|
|
||||||
// Only needed when the button is clicked
|
|
||||||
// When this is triggered by the enter key the `onAddItemKeyUp` will internally also hide the autocomplete.
|
|
||||||
// Though hiding it twice doesn't hurt so we don't care.
|
|
||||||
hideAutocomplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onAddItemKeyDown(e: KeyboardEvent) {
|
|
||||||
if (e.code == "ArrowDown") {
|
|
||||||
e.preventDefault();
|
|
||||||
if (autocompleteIndex.value < props.autocompleteItems.length - 1) {
|
|
||||||
autocompleteIndex.value++;
|
|
||||||
}
|
|
||||||
} else if (e.code == "ArrowUp") {
|
|
||||||
e.preventDefault();
|
|
||||||
if (autocompleteIndex.value >= 0) {
|
|
||||||
autocompleteIndex.value--;
|
|
||||||
}
|
|
||||||
} else if (e.code == "Enter") {
|
|
||||||
if (autocompleteIndex.value == -1) {
|
|
||||||
addItemFromCurrentInput();
|
|
||||||
} else {
|
|
||||||
// Add auto completed item
|
|
||||||
const itemToAdd = props.autocompleteItems[autocompleteIndex.value];
|
|
||||||
addItem(itemToAdd);
|
|
||||||
inputText.value = ""; // Reset input
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onClickAutocompleteItem(item: any) {
|
|
||||||
addItem(item);
|
|
||||||
inputText.value = ""; // Reset input
|
|
||||||
autocompleteShown.value = false; // Hide autocomplete list
|
|
||||||
}
|
|
||||||
|
|
||||||
function hideAutocomplete() {
|
|
||||||
autocompleteIndex.value = -1;
|
|
||||||
autocompleteShown.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function autocompletePopulator(input: string) {
|
|
||||||
// Based on https://www.w3schools.com/howto/howto_js_autocomplete.asp
|
|
||||||
|
|
||||||
// Hide autocomplete when the input is empty, and don't do anything else.
|
|
||||||
if (input.length == 0) {
|
|
||||||
hideAutocomplete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel previous request, not sure if this still works after the refactor.
|
|
||||||
if (cancelSource.value) {
|
|
||||||
cancelSource.value.cancel();
|
|
||||||
}
|
|
||||||
cancelSource.value = axios.CancelToken.source();
|
|
||||||
|
|
||||||
emit("autocompletePopulator", inputText.value, cancelSource.value.token);
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(props, (newValue) => {
|
|
||||||
if (newValue.autocompleteItems.length > 0) {
|
|
||||||
autocompleteShown.value = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div style="display: flex; flex-direction: column">
|
|
||||||
<div style="display: flex">
|
|
||||||
<input type="text" v-model="inputText" @keyup="onAddItemKeyUp" @keydown="onAddItemKeyDown" autocomplete="off" />
|
|
||||||
<button class="primary" style="margin-left: 5px" @click="addItemFromCurrentInput">Add</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="autocomplete-items" v-bind:class="{ show: autocompleteShown }">
|
|
||||||
<div
|
|
||||||
v-for="(item, idx) in autocompleteItems"
|
|
||||||
@click="onClickAutocompleteItem(item)"
|
|
||||||
:key="item.name"
|
|
||||||
:class="{
|
|
||||||
active: idx == autocompleteIndex,
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<slot :item="item"></slot>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.autocomplete-items {
|
|
||||||
position: absolute;
|
|
||||||
z-index: 10;
|
|
||||||
background-color: var(--bg-main-color);
|
|
||||||
border: 2px solid var(--primary-color);
|
|
||||||
margin-top: 34px;
|
|
||||||
display: none;
|
|
||||||
|
|
||||||
&.show {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
> div {
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 2px 4px;
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5em;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: var(--primary-color);
|
|
||||||
|
|
||||||
> span {
|
|
||||||
color: var(--text-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> div.active {
|
|
||||||
background: var(--primary-color);
|
|
||||||
|
|
||||||
> span {
|
|
||||||
color: var(--text-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import type { PropType } from "vue";
|
|
||||||
import type { PoolDetails } from "~/models";
|
|
||||||
import { breakTagName } from "~/utils";
|
|
||||||
|
|
||||||
defineProps({
|
|
||||||
pools: Array as PropType<PoolDetails[]>,
|
|
||||||
showPostCount: Boolean,
|
|
||||||
showRemovePool: Boolean,
|
|
||||||
});
|
|
||||||
defineEmits(["removePool"]);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<ul class="compact-pools">
|
|
||||||
<li v-for="pool in pools" :key="pool.name">
|
|
||||||
<a v-if="showRemovePool" class="remove-tag" @click="$emit('removePool', pool)">x</a>
|
|
||||||
<span class="tag-general" v-html="breakTagName(pool.name)"></span>
|
|
||||||
<span v-if="showPostCount" class="tag-usages tag-usages-reserve-space">{{
|
|
||||||
pool.postCount ? pool.postCount : ""
|
|
||||||
}}</span>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
/* Hacky way to stop the layout from resizing when we lazy load the usage count. */
|
|
||||||
.tag-usages-reserve-space {
|
|
||||||
min-width: 5ch;
|
|
||||||
/* 5 character width */
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
@ -24,8 +24,7 @@ defineEmits(["removeTag"]);
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
/* 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. */
|
||||||
.tag-usages-reserve-space {
|
.tag-usages-reserve-space {
|
||||||
min-width: 5ch;
|
min-width: 5ch; /* 5 character width */
|
||||||
/* 5 character width */
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import { PropType } from "vue";
|
|
||||||
import { PoolDetails } from "~/models";
|
|
||||||
import { encodeTagName, getTagClasses } from "~/utils";
|
|
||||||
import SzurubooruApi from "~/api";
|
|
||||||
import { CancelToken } from "axios";
|
|
||||||
|
|
||||||
const autocompleteItems = ref<PoolDetails[]>([]);
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
szuru: Object as PropType<SzurubooruApi>,
|
|
||||||
});
|
|
||||||
const emit = defineEmits(["addPool"]);
|
|
||||||
|
|
||||||
function addPool(tag: PoolDetails) {
|
|
||||||
emit("addPool", tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addPoolFromCurrentInput(input: string) {
|
|
||||||
addPool(new PoolDetails([input]));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function autocompletePopulator(input: string, ct: CancelToken) {
|
|
||||||
const query = decodeURIComponent(`*${encodeTagName(input)}*`);
|
|
||||||
const res = await props.szuru?.getPools(query, 0, 100, ["id", "names", "category", "description", "postCount"], ct);
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
// TODO: Maybe search on hamming distance or something?
|
|
||||||
autocompleteItems.value = res.results.map((x) => PoolDetails.fromPool(x));
|
|
||||||
} else {
|
|
||||||
autocompleteItems.value = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<AutocompleteInput
|
|
||||||
:autocomplete-items="autocompleteItems"
|
|
||||||
@add-item="addPool"
|
|
||||||
@add-from-current-input="addPoolFromCurrentInput"
|
|
||||||
@autocomplete-populator="autocompletePopulator"
|
|
||||||
v-slot="slotProps"
|
|
||||||
>
|
|
||||||
<span :class="getTagClasses(slotProps.item)">{{ slotProps.item.name }}</span>
|
|
||||||
<span class="tag-usages">{{ slotProps.item.usages ? slotProps.item.usages : "" }}</span>
|
|
||||||
</AutocompleteInput>
|
|
||||||
</template>
|
|
||||||
|
|
@ -2,10 +2,7 @@
|
||||||
import { ScrapedNote } from "neo-scraper";
|
import { ScrapedNote } from "neo-scraper";
|
||||||
|
|
||||||
class Point {
|
class Point {
|
||||||
constructor(
|
constructor(public x: any, public y: any) {}
|
||||||
public x: any,
|
|
||||||
public y: any,
|
|
||||||
) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK: Copied from old client
|
// HACK: Copied from old client
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import axios, { CancelTokenSource } from "axios";
|
||||||
import { PropType } from "vue";
|
import { PropType } from "vue";
|
||||||
|
import SzurubooruApi from "~/api";
|
||||||
import { TagDetails } from "~/models";
|
import { TagDetails } from "~/models";
|
||||||
import { encodeTagName, getTagClasses } from "~/utils";
|
import { encodeTagName, getTagClasses } from "~/utils";
|
||||||
import SzurubooruApi from "~/api";
|
|
||||||
import { CancelToken } from "axios";
|
|
||||||
|
|
||||||
const autocompleteItems = ref<TagDetails[]>([]);
|
const addTagInput = ref("");
|
||||||
|
const autocompleteShown = ref(false);
|
||||||
|
const autocompleteTags = ref<TagDetails[]>([]);
|
||||||
|
const cancelSource = ref<CancelTokenSource | undefined>(undefined);
|
||||||
|
const autocompleteIndex = ref(-1);
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
szuru: Object as PropType<SzurubooruApi>,
|
szuru: Object as PropType<SzurubooruApi>,
|
||||||
|
|
@ -16,33 +20,148 @@ function addTag(tag: TagDetails) {
|
||||||
emit("addTag", tag);
|
emit("addTag", tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTagFromCurrentInput(input: string) {
|
async function onAddTagKeyUp(e: KeyboardEvent) {
|
||||||
addTag(new TagDetails([input]));
|
await autocompletePopulator((<HTMLInputElement>e.target).value);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function autocompletePopulator(input: string, ct: CancelToken) {
|
function addTagFromCurrentInput() {
|
||||||
|
addTag(new TagDetails([addTagInput.value]));
|
||||||
|
addTagInput.value = ""; // Reset input
|
||||||
|
|
||||||
|
// Only needed when the button is clicked
|
||||||
|
// When this is triggered by the enter key the `onAddTagKeyUp` will internally also hide the autocomplete.
|
||||||
|
// Though hiding it twice doesn't hurt so we don't care.
|
||||||
|
hideAutocomplete();
|
||||||
|
|
||||||
|
// TODO: Do we also want to add the implications?
|
||||||
|
// Answer: Probably not, because if the user wanted to have implications they should've clicked/selected the autocomplete entry.
|
||||||
|
}
|
||||||
|
|
||||||
|
function onAddTagKeyDown(e: KeyboardEvent) {
|
||||||
|
if (e.code == "ArrowDown") {
|
||||||
|
e.preventDefault();
|
||||||
|
if (autocompleteIndex.value < autocompleteTags.value.length - 1) {
|
||||||
|
autocompleteIndex.value++;
|
||||||
|
}
|
||||||
|
} else if (e.code == "ArrowUp") {
|
||||||
|
e.preventDefault();
|
||||||
|
if (autocompleteIndex.value >= 0) {
|
||||||
|
autocompleteIndex.value--;
|
||||||
|
}
|
||||||
|
} else if (e.code == "Enter") {
|
||||||
|
if (autocompleteIndex.value == -1) {
|
||||||
|
addTagFromCurrentInput();
|
||||||
|
} else {
|
||||||
|
// Add auto completed tag
|
||||||
|
const tagToAdd = autocompleteTags.value[autocompleteIndex.value];
|
||||||
|
addTag(tagToAdd);
|
||||||
|
addTagInput.value = ""; // Reset input
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onClickAutocompleteTagItem(tag: TagDetails) {
|
||||||
|
addTag(tag);
|
||||||
|
addTagInput.value = ""; // Reset input
|
||||||
|
autocompleteShown.value = false; // Hide autocomplete list
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideAutocomplete() {
|
||||||
|
autocompleteIndex.value = -1;
|
||||||
|
autocompleteShown.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function autocompletePopulator(input: string) {
|
||||||
|
// Based on https://www.w3schools.com/howto/howto_js_autocomplete.asp
|
||||||
|
|
||||||
|
// Hide autocomplete when the input is empty, and don't do anything else.
|
||||||
|
if (input.length == 0) {
|
||||||
|
hideAutocomplete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel previous request
|
||||||
|
if (cancelSource.value) {
|
||||||
|
cancelSource.value.cancel();
|
||||||
|
}
|
||||||
|
cancelSource.value = axios.CancelToken.source();
|
||||||
|
|
||||||
const query = decodeURIComponent(`*${encodeTagName(input)}* sort:usages`);
|
const query = decodeURIComponent(`*${encodeTagName(input)}* sort:usages`);
|
||||||
const res = await props.szuru?.getTags(query, 0, 100, ["names", "category", "usages", "implications"], ct);
|
const res = await props.szuru?.getTags(
|
||||||
|
query,
|
||||||
|
0,
|
||||||
|
100,
|
||||||
|
["names", "category", "usages", "implications"],
|
||||||
|
cancelSource.value.token
|
||||||
|
);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
// TODO: Maybe search on hamming distance or something?
|
// TODO: Maybe search on hamming distance or something?
|
||||||
autocompleteItems.value = res.results.map((x) => TagDetails.fromTag(x));
|
autocompleteTags.value = res.results.map((x) => TagDetails.fromTag(x));
|
||||||
console.dir(autocompleteItems.value);
|
if (autocompleteTags.value.length > 0) autocompleteShown.value = true;
|
||||||
} else {
|
} else {
|
||||||
autocompleteItems.value = [];
|
autocompleteTags.value = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<AutocompleteInput
|
<div style="display: flex; flex-direction: column">
|
||||||
:autocomplete-items="autocompleteItems"
|
<div style="display: flex">
|
||||||
@add-item="addTag"
|
<input type="text" v-model="addTagInput" @keyup="onAddTagKeyUp" @keydown="onAddTagKeyDown" autocomplete="off" />
|
||||||
@add-from-current-input="addTagFromCurrentInput"
|
<button class="primary" style="margin-left: 5px" @click="addTagFromCurrentInput">Add</button>
|
||||||
@autocomplete-populator="autocompletePopulator"
|
</div>
|
||||||
v-slot="slotProps"
|
|
||||||
>
|
<div class="autocomplete-items" v-bind:class="{ show: autocompleteShown }">
|
||||||
<span :class="getTagClasses(slotProps.item)">{{ slotProps.item.name }}</span>
|
<div
|
||||||
<span class="tag-usages">{{ slotProps.item.usages ? slotProps.item.usages : "" }}</span>
|
v-for="(tag, idx) in autocompleteTags"
|
||||||
</AutocompleteInput>
|
@click="onClickAutocompleteTagItem(tag)"
|
||||||
|
:key="tag.name"
|
||||||
|
:class="{
|
||||||
|
active: idx == autocompleteIndex,
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<span :class="getTagClasses(tag)">{{ tag.name }}</span>
|
||||||
|
<span class="tag-usages">{{ tag.usages ? tag.usages : "" }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.autocomplete-items {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 10;
|
||||||
|
background-color: var(--bg-main-color);
|
||||||
|
border: 2px solid var(--primary-color);
|
||||||
|
margin-top: 34px;
|
||||||
|
display: none;
|
||||||
|
|
||||||
|
&.show {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
> div {
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 2px 4px;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5em;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: var(--primary-color);
|
||||||
|
> span {
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
> div.active {
|
||||||
|
background: var(--primary-color);
|
||||||
|
> span {
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,15 @@ const storageLocal: StorageLikeAsync = {
|
||||||
},
|
},
|
||||||
|
|
||||||
setItem(key: string, value: string) {
|
setItem(key: string, value: string) {
|
||||||
|
console.log("setItem");
|
||||||
|
console.dir(value);
|
||||||
return storage.local.set({ [key]: value });
|
return storage.local.set({ [key]: value });
|
||||||
},
|
},
|
||||||
|
|
||||||
async getItem(key: string) {
|
async getItem(key: string) {
|
||||||
|
console.log("getItem");
|
||||||
const item = (await storage.local.get(key))[key];
|
const item = (await storage.local.get(key))[key];
|
||||||
|
console.dir(item);
|
||||||
return item;
|
return item;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -20,5 +24,5 @@ const storageLocal: StorageLikeAsync = {
|
||||||
export const useStorageLocal = <T>(
|
export const useStorageLocal = <T>(
|
||||||
key: string,
|
key: string,
|
||||||
initialValue: MaybeRef<T>,
|
initialValue: MaybeRef<T>,
|
||||||
options?: UseStorageAsyncOptions<T>,
|
options?: UseStorageAsyncOptions<T>
|
||||||
): RemovableRef<T> => useStorageAsync(key, initialValue, storageLocal, options);
|
): RemovableRef<T> => useStorageAsync(key, initialValue, storageLocal, options);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
export class SzuruSiteConfig {
|
||||||
|
id = window.crypto.randomUUID();
|
||||||
|
domain = "https://example.com";
|
||||||
|
username = "user";
|
||||||
|
authToken = "";
|
||||||
|
}
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
import { TagCategoryColor } from "./models";
|
|
||||||
|
|
||||||
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 (const category of tagCategories) {
|
|
||||||
const ruleName = makeCssName("tag", category.name);
|
|
||||||
|
|
||||||
if (styleElement.sheet) {
|
|
||||||
styleElement.sheet.insertRule(`.${ruleName} { color: ${category.color} }`, styleElement.sheet.cssRules.length);
|
|
||||||
} else {
|
|
||||||
console.error("styleElement.sheet is undefined. This should never happen!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return styleElement;
|
|
||||||
}
|
|
||||||
|
|
@ -11,7 +11,7 @@ export async function getManifest() {
|
||||||
const manifest: Manifest.WebExtensionManifest = {
|
const manifest: Manifest.WebExtensionManifest = {
|
||||||
name: pkg.displayName,
|
name: pkg.displayName,
|
||||||
description: pkg.description,
|
description: pkg.description,
|
||||||
version: process.env.VITE_SZ_VERSION || pkg.version,
|
version: process.env.SZ_VERSION || pkg.version,
|
||||||
manifest_version: 2,
|
manifest_version: 2,
|
||||||
icons: {
|
icons: {
|
||||||
16: "./assets/icon-128.png",
|
16: "./assets/icon-128.png",
|
||||||
|
|
@ -31,26 +31,19 @@ export async function getManifest() {
|
||||||
page: "./dist/background/index.html",
|
page: "./dist/background/index.html",
|
||||||
// persistent: false,
|
// persistent: false,
|
||||||
},
|
},
|
||||||
permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "notifications", "<all_urls>"],
|
permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "<all_urls>"],
|
||||||
content_scripts: [
|
content_scripts: [
|
||||||
{
|
{
|
||||||
matches: ["http://*/*", "https://*/*"],
|
matches: ["http://*/*", "https://*/*"],
|
||||||
js: ["./dist/contentScripts/index.global.js"],
|
js: ["./dist/contentScripts/index.global.js"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
browser_specific_settings: {
|
||||||
|
|
||||||
if (process.env.SZ_GECKO_ID) {
|
|
||||||
manifest.browser_specific_settings = {
|
|
||||||
gecko: {
|
gecko: {
|
||||||
id: `{${process.env.SZ_GECKO_ID}}`,
|
id: "{13372607-2257-4360-8f51-5ce66fa73350}",
|
||||||
strict_min_version: "113.0",
|
|
||||||
},
|
},
|
||||||
gecko_android: {
|
},
|
||||||
strict_min_version: "113.0",
|
};
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
// for content script, as browsers will cache them for each reload,
|
// for content script, as browsers will cache them for each reload,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
import { BooruTypes, ContentType, ScrapedNote, ScrapedPost, ScrapedTag, UploadMode } from "neo-scraper";
|
import { BooruTypes, ContentType, ScrapedNote, ScrapedPost, ScrapedTag } from "neo-scraper";
|
||||||
import { MicroTag, Pool, Tag, UpdatePostRequest } from "~/api/models";
|
import { MicroTag, Tag, UpdatePostRequest } from "~/api/models";
|
||||||
|
import { SzuruSiteConfig } from "~/config";
|
||||||
|
|
||||||
export class TagDetails {
|
export class TagDetails {
|
||||||
public implications: TagDetails[] = [];
|
public implications: TagDetails[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(public names: string[], public category?: string, public usages?: number) {}
|
||||||
public names: string[],
|
|
||||||
public category?: string,
|
|
||||||
public usages?: number,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return this.names[0];
|
return this.names[0];
|
||||||
|
|
@ -33,22 +30,6 @@ export class TagDetails {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PoolDetails {
|
|
||||||
constructor(
|
|
||||||
public names: string[],
|
|
||||||
public category?: string,
|
|
||||||
public postCount?: number,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
get name() {
|
|
||||||
return this.names[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
static fromPool(pool: Pool) {
|
|
||||||
return new PoolDetails(pool.names, pool.category, pool.postCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class InstanceSpecificData {
|
export class InstanceSpecificData {
|
||||||
contentToken?: string;
|
contentToken?: string;
|
||||||
genericError?: string;
|
genericError?: string;
|
||||||
|
|
@ -64,7 +45,6 @@ export class ScrapedPostDetails {
|
||||||
id = window.crypto.randomUUID();
|
id = window.crypto.randomUUID();
|
||||||
name = "";
|
name = "";
|
||||||
tags: TagDetails[] = [];
|
tags: TagDetails[] = [];
|
||||||
pools: PoolDetails[] = [];
|
|
||||||
notes: ScrapedNote[];
|
notes: ScrapedNote[];
|
||||||
contentUrl: string;
|
contentUrl: string;
|
||||||
extraContentUrl: string | undefined;
|
extraContentUrl: string | undefined;
|
||||||
|
|
@ -73,8 +53,7 @@ export class ScrapedPostDetails {
|
||||||
contentType: ContentType;
|
contentType: ContentType;
|
||||||
contentSubType: string | undefined;
|
contentSubType: string | undefined;
|
||||||
rating: BooruTypes.SafetyRating;
|
rating: BooruTypes.SafetyRating;
|
||||||
source;
|
source = "";
|
||||||
uploadMode: UploadMode;
|
|
||||||
referrer?: string;
|
referrer?: string;
|
||||||
resolution?: [number, number];
|
resolution?: [number, number];
|
||||||
instanceSpecificData: MappedInstanceSpecificData = {};
|
instanceSpecificData: MappedInstanceSpecificData = {};
|
||||||
|
|
@ -91,7 +70,6 @@ export class ScrapedPostDetails {
|
||||||
this.tags = post.tags.map((x) => TagDetails.fromScapedTag(x));
|
this.tags = post.tags.map((x) => TagDetails.fromScapedTag(x));
|
||||||
this.notes = post.notes;
|
this.notes = post.notes;
|
||||||
this.resolution = post.resolution;
|
this.resolution = post.resolution;
|
||||||
this.uploadMode = post.uploadMode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,10 +84,7 @@ export interface SimpleSimilarPost {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SimilarPostInfo {
|
export class SimilarPostInfo {
|
||||||
constructor(
|
constructor(public readonly id: number, public readonly percentage: number) {}
|
||||||
public readonly id: number,
|
|
||||||
public readonly percentage: number,
|
|
||||||
) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PostUploadState = "uploading" | "uploaded" | "error";
|
export type PostUploadState = "uploading" | "uploaded" | "error";
|
||||||
|
|
@ -145,26 +120,18 @@ export class BrowserCommand<T = any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PostUploadCommandData {
|
export class PostUploadCommandData {
|
||||||
constructor(
|
constructor(public readonly post: ScrapedPostDetails, public readonly selectedSite: SzuruSiteConfig) {}
|
||||||
public readonly post: ScrapedPostDetails,
|
|
||||||
public readonly selectedSite: SzuruSiteConfig,
|
|
||||||
public readonly sendNotifications: boolean,
|
|
||||||
) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetPostUploadInfoData {
|
export class SetPostUploadInfoData {
|
||||||
constructor(
|
constructor(public instanceId: string, public postId: string, public info: PostUploadInfo) {}
|
||||||
public instanceId: string,
|
|
||||||
public postId: string,
|
|
||||||
public info: PostUploadInfo,
|
|
||||||
) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetExactPostId {
|
export class SetExactPostId {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly instanceId: string,
|
public readonly instanceId: string,
|
||||||
public readonly postId: string,
|
public readonly postId: string,
|
||||||
public readonly exactPostId: number,
|
public readonly exactPostId: number
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,34 +139,10 @@ export class PostUpdateCommandData {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly postId: number,
|
public readonly postId: number,
|
||||||
public readonly updateRequest: UpdatePostRequest,
|
public readonly updateRequest: UpdatePostRequest,
|
||||||
public readonly selectedSite: SzuruSiteConfig,
|
public readonly selectedSite: SzuruSiteConfig
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FetchCommandData {
|
export class FetchCommandData {
|
||||||
constructor(
|
constructor(public readonly url: string, public readonly options: RequestInit | undefined = undefined) {}
|
||||||
public readonly url: string,
|
|
||||||
public readonly options: RequestInit | undefined = undefined,
|
|
||||||
) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SzuruSiteConfig {
|
|
||||||
id = window.crypto.randomUUID();
|
|
||||||
domain = "https://example.com";
|
|
||||||
username = "user";
|
|
||||||
authToken = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TagCategoryColor {
|
|
||||||
constructor(
|
|
||||||
public name: string,
|
|
||||||
public color: string,
|
|
||||||
) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getDefaultTagCategories = () => [
|
|
||||||
new TagCategoryColor("copyright", "#a0a"),
|
|
||||||
new TagCategoryColor("character", "#0a0"),
|
|
||||||
new TagCategoryColor("artist", "#a00"),
|
|
||||||
new TagCategoryColor("meta", "#f80"),
|
|
||||||
];
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,12 @@
|
||||||
<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 { cfg } from "~/stores";
|
import { cfg } from "~/stores";
|
||||||
import { getErrorMessage } from "~/utils";
|
import { getErrorMessage } from "~/utils";
|
||||||
|
|
||||||
import TabView from "primevue/tabview";
|
let statusText = ref("Version " + browser.runtime.getManifest().version);
|
||||||
import TabPanel from "primevue/tabpanel";
|
let statusType = ref("status-quiet");
|
||||||
import DataTable from "primevue/datatable";
|
|
||||||
import Column from "primevue/column";
|
|
||||||
import { TagDetails, SzuruSiteConfig, TagCategoryColor, getDefaultTagCategories } from "~/models";
|
|
||||||
import SzurubooruApi from "~/api";
|
|
||||||
|
|
||||||
type StatusType = "success" | "error" | "quiet";
|
|
||||||
|
|
||||||
const statusText = ref("");
|
|
||||||
const statusType = ref("status-quiet");
|
|
||||||
const versionInfo = "Version: " + (import.meta.env.VITE_SZ_VERSION ?? 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) {
|
||||||
|
|
@ -28,7 +14,7 @@ const selectedSite = computed(() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const mode = useColorMode({ emitAuto: true });
|
type StatusType = "success" | "error" | "quiet";
|
||||||
|
|
||||||
async function testConnection() {
|
async function testConnection() {
|
||||||
if (
|
if (
|
||||||
|
|
@ -79,306 +65,126 @@ function removeSelectedSite() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetTagCategories() {
|
let mode = useColorMode({ emitAuto: true });
|
||||||
cfg.value.tagCategories.splice(0);
|
|
||||||
cfg.value.tagCategories.push(...getDefaultTagCategories());
|
|
||||||
}
|
|
||||||
|
|
||||||
function addTagCategory() {
|
|
||||||
cfg.value.tagCategories.push(new TagCategoryColor("category", "#abcdef"));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importTagCategoriesFromInstance() {
|
|
||||||
const szuruConfig = cfg.value.sites.find((x) => x.id == cfg.value.selectedSiteId)!;
|
|
||||||
const szuru = SzurubooruApi.createFromConfig(szuruConfig);
|
|
||||||
const cats = (await szuru.getTagCategories()).results;
|
|
||||||
|
|
||||||
for (const cat of cats) {
|
|
||||||
if (cat.name == "default") continue;
|
|
||||||
|
|
||||||
if (!cfg.value.tagCategories.find((x) => x.name == cat.name)) {
|
|
||||||
cfg.value.tagCategories.push(new TagCategoryColor(cat.name, cat.color));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addTagIgnore() {
|
|
||||||
cfg.value.tagIgnores.push(new TagDetails([""]));
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetTagIgnores() {
|
|
||||||
cfg.value.tagIgnores.splice(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// For debugging
|
|
||||||
const wnd = window as any;
|
|
||||||
wnd.szc_get_config = () => JSON.parse(JSON.stringify(cfg.value));
|
|
||||||
wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="content-holder">
|
<div class="content-holder">
|
||||||
<div class="content-wrapper flex flex-auto flex-column gap-3">
|
<div class="content-wrapper flex flex-wrap gap-3">
|
||||||
<div><strong>SzuruChrome Settings</strong></div>
|
<div class="flex-fit"><strong>SzuruChrome Settings</strong></div>
|
||||||
|
|
||||||
<TabView>
|
<div class="flex-fit">
|
||||||
<TabPanel header="General">
|
<div class="fit flex flex-wrap">
|
||||||
<div class="grid">
|
<div class="flex-fit">
|
||||||
<div class="col-12 md:col-6">
|
<label>Szurubooru Instances</label>
|
||||||
<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">
|
<!-- This isn't perfectly responsive for very small devices. -->
|
||||||
<label>
|
<div class="fit flex gap-1 flex-fit">
|
||||||
<input type="checkbox" v-model="cfg.addAllParsedTags" />
|
<select v-model="cfg.selectedSiteId">
|
||||||
Automatically import all tags on supported pages
|
<option v-for="site in cfg.sites" :key="site.id" :value="site.id">
|
||||||
</label>
|
{{ site.username }} @ {{ site.domain }}
|
||||||
<p class="hint">
|
</option>
|
||||||
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.alwaysUploadAsContent" />
|
|
||||||
Always upload as content
|
|
||||||
</label>
|
|
||||||
<p class="hint">This will always upload the image content directly, instead of as an URL</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-12 md:col-6">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" v-model="cfg.sendUploadNotifications" />
|
|
||||||
Send browser notifications after uploading
|
|
||||||
</label>
|
|
||||||
<p class="hint">
|
|
||||||
This will send a browser notification after a successful upload. Clicking the notification will open the
|
|
||||||
uploaded post in a new tab.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<span class="col-12 status-quiet">{{ versionInfo }}</span>
|
|
||||||
</div>
|
|
||||||
</TabPanel>
|
|
||||||
|
|
||||||
<TabPanel header="Interface">
|
|
||||||
<div class="grid">
|
|
||||||
<div class="col-12 md:col-6 mb-2">
|
|
||||||
<label>Theme</label>
|
|
||||||
<select v-model="mode">
|
|
||||||
<option value="auto">System</option>
|
|
||||||
<option value="light">Light</option>
|
|
||||||
<option value="dark">Dark</option>
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<button class="primary" @click="addSite">Add</button>
|
||||||
|
<button class="bg-danger" @click="removeSelectedSite">Remove</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid">
|
<div v-if="selectedSite" class="flex-fit flex flex-wrap gap-1 border-box pb2">
|
||||||
<div class="col-12 md:col-6">
|
<div style="flex: 1 1 20ch">
|
||||||
<label>
|
<label>URL</label>
|
||||||
<input type="checkbox" v-model="cfg.autoSearchSimilar" />
|
<input
|
||||||
Automatically search for similar posts
|
v-if="selectedSite"
|
||||||
</label>
|
text="Szurubooru URL"
|
||||||
<p class="hint">
|
type="text"
|
||||||
Automatically start searching for similar posts when opening the popup. Enabling this option will hide
|
name="domain"
|
||||||
the "Find Similar" button.
|
v-model.lazy="selectedSite.domain"
|
||||||
</p>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 md:col-6">
|
<div style="flex: 1 1 12ch">
|
||||||
<label>
|
<label>Username</label>
|
||||||
<input type="checkbox" v-model="cfg.loadTagCounts" />
|
<input text="Username" type="text" name="username" v-model="selectedSite.username" />
|
||||||
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="col-12 md:col-6">
|
<div style="flex: 1 1 28ch">
|
||||||
<label>
|
<label>Authentication token</label>
|
||||||
<input type="checkbox" v-model="cfg.popup.showSource" />
|
<input text="Authentication token" type="text" name="token" v-model="selectedSite.authToken" />
|
||||||
Show source textbox in popup
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-12 md:col-6">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" v-model="cfg.popup.showPools" />
|
|
||||||
Show pools in popup
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-12 md:col-6">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" v-model="cfg.popup.showInstancePicker" />
|
|
||||||
Show instance picker in popup
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabPanel>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<TabPanel header="Instances">
|
<div class="flex-fit flex flex-wrap gap-3">
|
||||||
<div class="formgrid grid">
|
<div class="settings-block" style="flex: 1 0 10ch">
|
||||||
<div class="field col-12">
|
<label>Theme</label>
|
||||||
<label>Selected Szurubooru Instance</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>
|
||||||
|
|
||||||
<div class="flex gap-1">
|
<div class="settings-block">
|
||||||
<select v-model="cfg.selectedSiteId">
|
<label>
|
||||||
<option v-for="site in cfg.sites" :key="site.id" :value="site.id">
|
<input type="checkbox" v-model="cfg.autoSearchSimilar" />
|
||||||
{{ site.username }} @ {{ site.domain }}
|
Automatically search for similar posts
|
||||||
</option>
|
</label>
|
||||||
</select>
|
<p class="hint">
|
||||||
|
Automatically start searching for similar posts when opening the popup. Enabling this option will hide the
|
||||||
|
"Find Similar" button.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button class="primary" @click="addSite">Add</button>
|
<div class="settings-block">
|
||||||
<button class="bg-danger" @click="removeSelectedSite">Remove</button>
|
<label>
|
||||||
</div>
|
<input type="checkbox" v-model="cfg.addPageUrlToSource" />
|
||||||
</div>
|
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>
|
||||||
|
|
||||||
<template v-if="selectedSite">
|
<div class="settings-block">
|
||||||
<div class="field col-12">
|
<label>
|
||||||
<label>URL</label>
|
<input type="checkbox" v-model="cfg.loadTagCounts" />
|
||||||
<input
|
Show how often a tag is used in the selected szurubooru instance
|
||||||
v-if="selectedSite"
|
</label>
|
||||||
text="Szurubooru URL"
|
<p class="hint">
|
||||||
type="text"
|
Shows how often a given tag is used in the selected szurubooru instance. No number will be displayed when
|
||||||
name="domain"
|
the tag does not yet exist.
|
||||||
v-model="selectedSite.domain"
|
</p>
|
||||||
/>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field col-12 md:col-6">
|
<div class="flex-fit flex flex-wrap justify-between gap-3">
|
||||||
<label>Username</label>
|
<span class="status" :class="statusType">{{ statusText }}</span>
|
||||||
<input text="Username" type="text" name="username" v-model="selectedSite.username" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field col-12 md:col-6">
|
<div class="flex gap-1">
|
||||||
<label>Authentication token</label>
|
<button @click="testConnection">Test connection</button>
|
||||||
<input text="Authentication token" type="text" name="token" v-model="selectedSite.authToken" />
|
<!-- <button @click="saveSettings" class="primary">Save settings</button> -->
|
||||||
</div>
|
</div>
|
||||||
|
</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>
|
|
||||||
</TabPanel>
|
|
||||||
|
|
||||||
<TabPanel header="Tags">
|
|
||||||
<div class="separated-content">
|
|
||||||
<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 @click="importTagCategoriesFromInstance">Import from active instance</button>
|
|
||||||
<button class="bg-danger sm:ml-auto" @click="resetTagCategories">Reset to default</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- TODO: Tag category colors -->
|
|
||||||
|
|
||||||
<div class="grid">
|
|
||||||
<DataTable :value="cfg.tagIgnores" table-class="col-12" style="width: 100%">
|
|
||||||
<Column field="names" header="Tags to ignore">
|
|
||||||
<template #body="{ data, field }">
|
|
||||||
<input type="text" :name="field" v-model="data[field][0]" />
|
|
||||||
</template>
|
|
||||||
</Column>
|
|
||||||
|
|
||||||
<Column field="remove">
|
|
||||||
<template #body="{ index }">
|
|
||||||
<a class="color-primary cursor-pointer" @click="() => cfg.tagIgnores.splice(index, 1)">Remove</a>
|
|
||||||
</template>
|
|
||||||
</Column>
|
|
||||||
</DataTable>
|
|
||||||
|
|
||||||
<div class="col-12 flex flex-wrap grid grid-nogutter gap-1">
|
|
||||||
<button class="primary" @click="addTagIgnore">Add tag</button>
|
|
||||||
<button class="bg-danger sm:ml-auto" @click="resetTagIgnores">Clear</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- TODO: Category ignore list -->
|
|
||||||
</div>
|
|
||||||
</TabPanel>
|
|
||||||
|
|
||||||
<!-- <TabPanel header="About">
|
|
||||||
<div class="grid">
|
|
||||||
<div v-for="engine in scraper.engines" :key="engine.name" class="col-12 md:col-4 flex flex-column">
|
|
||||||
<span class="font-bold">{{ engine.name }}</span>
|
|
||||||
<span>Features: {{ engine.features.join(", ") }}</span>
|
|
||||||
<span>Hosts: {{ engine.supportedHosts.join(", ") }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</TabPanel> -->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<TabPanel header="Developer">
|
|
||||||
<div class="flex flex-column gap-2">
|
|
||||||
<b>Config</b>
|
|
||||||
<Textarea v-model="configText" autoResize rows="16" />
|
|
||||||
|
|
||||||
<div class="flex flex-wrap gap-1">
|
|
||||||
<button class="primary" @click="showConfig">Show config</button>
|
|
||||||
<button class="bg-danger" @click="importConfig">Import config</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</TabPanel>
|
|
||||||
-->
|
|
||||||
</TabView>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
@use "~/styles/main.scss";
|
||||||
|
|
||||||
.content-holder {
|
.content-holder {
|
||||||
padding: 1.5em;
|
padding: 1.5em;
|
||||||
display: flex;
|
display: flex;
|
||||||
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;
|
||||||
|
|
@ -392,6 +198,15 @@ html.dark .content-wrapper {
|
||||||
background: var(--section-header-bg-color);
|
background: var(--section-header-bg-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.settings-block {
|
||||||
|
flex: 1 0 200px;
|
||||||
|
|
||||||
|
label {
|
||||||
|
padding: 0;
|
||||||
|
margin-bottom: 0.3em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.hint {
|
.hint {
|
||||||
margin-top: 0.4em;
|
margin-top: 0.4em;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
|
|
@ -416,6 +231,11 @@ html.dark .content-wrapper {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
padding: 0.3em 0;
|
||||||
|
}
|
||||||
|
|
||||||
input[type="checkbox"] {
|
input[type="checkbox"] {
|
||||||
margin: 0 3px 0 0;
|
margin: 0 3px 0 0;
|
||||||
}
|
}
|
||||||
|
|
@ -429,31 +249,4 @@ 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>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<base target="_blank" />
|
<base target="_blank" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>SzuruChrome Settings</title>
|
<title>Options</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
||||||
import { createApp } from "vue";
|
import { createApp } from "vue";
|
||||||
import PrimeVue from "primevue/config";
|
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
import { setupApp } from "~/logic/common-setup";
|
import { setupApp } from "~/logic/common-setup";
|
||||||
|
|
||||||
import "../styles/main.scss";
|
|
||||||
import "../styles/primevue.scss";
|
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
setupApp(app);
|
setupApp(app);
|
||||||
app.use(PrimeVue);
|
|
||||||
app.mount("#app");
|
app.mount("#app");
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,11 @@ 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 { cfg, useMergeStore, usePopupStore } from "~/stores";
|
import { 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:");
|
||||||
|
|
@ -93,7 +83,7 @@ onMounted(() => {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{ urls: ["<all_urls>"] },
|
{ urls: ["<all_urls>"] },
|
||||||
extraInfoSpec,
|
extraInfoSpec
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,12 @@ import { Post, UpdatePostRequest } from "~/api/models";
|
||||||
import { isMobile } from "~/env";
|
import { isMobile } from "~/env";
|
||||||
import { BrowserCommand, PostUpdateCommandData, TagDetails } from "~/models";
|
import { BrowserCommand, PostUpdateCommandData, TagDetails } from "~/models";
|
||||||
import { cfg, useMergeStore, usePopupStore } from "~/stores";
|
import { cfg, useMergeStore, usePopupStore } from "~/stores";
|
||||||
import { emptyPost, ensurePostHasContentToken, getUrl } from "~/utils";
|
import { emptyPost, getUrl } from "~/utils";
|
||||||
|
|
||||||
const props = defineProps(["siteId", "postId"]);
|
const props = defineProps(["siteId", "postId"]);
|
||||||
const merge = useMergeStore();
|
const merge = useMergeStore();
|
||||||
const pop = usePopupStore();
|
const pop = usePopupStore();
|
||||||
|
|
||||||
// Why is this cloneDeep needed? Or maybe it isn't?
|
|
||||||
const szuruConfig = cloneDeep(cfg.value.sites.find((x) => x.id == props.siteId))!;
|
const szuruConfig = cloneDeep(cfg.value.sites.find((x) => x.id == props.siteId))!;
|
||||||
const szuru = SzurubooruApi.createFromConfig(szuruConfig);
|
const szuru = SzurubooruApi.createFromConfig(szuruConfig);
|
||||||
|
|
||||||
|
|
@ -129,7 +128,7 @@ async function mergeChanges() {
|
||||||
if (
|
if (
|
||||||
!isEqual(
|
!isEqual(
|
||||||
newTags,
|
newTags,
|
||||||
existingPostRo.tags.map((x) => x.names[0]),
|
existingPostRo.tags.map((x) => x.names[0])
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
req.tags = newTags;
|
req.tags = newTags;
|
||||||
|
|
@ -140,10 +139,7 @@ async function mergeChanges() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageToKeep.value == "new") {
|
if (imageToKeep.value == "new") {
|
||||||
// In practice this should not be needed, because finding similar posts requires the use of content tokens.
|
req.contentUrl = scrapedPost?.contentUrl;
|
||||||
// So if a similar post is found, it means that a contentToken has already been set.
|
|
||||||
await ensurePostHasContentToken(szuru, scrapedPost, cfg);
|
|
||||||
req.contentToken = scrapedPost.instanceSpecificData[cfg.value.selectedSiteId!].contentToken!;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.safety && !req.source && !(req.contentUrl || req.contentToken) && req.tags === undefined) {
|
if (!req.safety && !req.source && !(req.contentUrl || req.contentToken) && req.tags === undefined) {
|
||||||
|
|
@ -168,7 +164,7 @@ watch(
|
||||||
// TODO: Implement this.
|
// TODO: Implement this.
|
||||||
sourcesAdded.value = 0;
|
sourcesAdded.value = 0;
|
||||||
sourcesRemoved.value = 0;
|
sourcesRemoved.value = 0;
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -179,7 +175,7 @@ watch(
|
||||||
} else if (existingPostRo) {
|
} else if (existingPostRo) {
|
||||||
tagsToAdd.splice(0);
|
tagsToAdd.splice(0);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -190,7 +186,7 @@ watch(
|
||||||
} else if (existingPostRo) {
|
} else if (existingPostRo) {
|
||||||
post.value.source = existingPostRo.source;
|
post.value.source = existingPostRo.source;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -201,7 +197,7 @@ watch(
|
||||||
} else if (existingPostRo) {
|
} else if (existingPostRo) {
|
||||||
post.value.safety = existingPostRo.safety;
|
post.value.safety = existingPostRo.safety;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
import { useDark } from "@vueuse/core";
|
import { useDark } from "@vueuse/core";
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
import { ScrapeResults } from "neo-scraper";
|
import { ScrapeResults } from "neo-scraper";
|
||||||
import { getUrl, encodeTagName, getErrorMessage, getPostInfoSummary, ensurePostHasContentToken } from "~/utils";
|
import { getUrl, encodeTagName, getErrorMessage, getPostInfoSummary } from "~/utils";
|
||||||
import {
|
import {
|
||||||
BrowserCommand,
|
BrowserCommand,
|
||||||
ScrapedPostDetails,
|
ScrapedPostDetails,
|
||||||
|
|
@ -11,12 +11,12 @@ import {
|
||||||
SimpleSimilarPost,
|
SimpleSimilarPost,
|
||||||
SimpleImageSearchResult,
|
SimpleImageSearchResult,
|
||||||
PostUploadCommandData,
|
PostUploadCommandData,
|
||||||
SzuruSiteConfig,
|
|
||||||
PoolDetails,
|
|
||||||
} from "~/models";
|
} from "~/models";
|
||||||
|
import { ImageSearchResult } from "~/api/models";
|
||||||
import { isMobile } from "~/env";
|
import { isMobile } from "~/env";
|
||||||
import { DeepReadonly } from "vue";
|
import { DeepReadonly } from "vue";
|
||||||
import { cfg, usePopupStore } from "~/stores";
|
import { cfg, usePopupStore } from "~/stores";
|
||||||
|
import { SzuruSiteConfig } from "~/config";
|
||||||
import SzurubooruApi from "~/api";
|
import SzurubooruApi from "~/api";
|
||||||
|
|
||||||
const pop = usePopupStore();
|
const pop = usePopupStore();
|
||||||
|
|
@ -40,7 +40,7 @@ const instanceSpecificData = readonly(
|
||||||
if (pop.selectedPost && cfg.value.selectedSiteId) {
|
if (pop.selectedPost && cfg.value.selectedSiteId) {
|
||||||
return pop.selectedPost.instanceSpecificData[cfg.value.selectedSiteId];
|
return pop.selectedPost.instanceSpecificData[cfg.value.selectedSiteId];
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -51,7 +51,7 @@ watch(
|
||||||
let selectedPost = pop.posts.find((x) => x.id == value);
|
let selectedPost = pop.posts.find((x) => x.id == value);
|
||||||
if (selectedPost) findSimilar(selectedPost);
|
if (selectedPost) findSimilar(selectedPost);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -66,62 +66,42 @@ watch(
|
||||||
findSimilar(pop.selectedPost);
|
findSimilar(pop.selectedPost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
function openOptionsPage() {
|
function openOptionsPage() {
|
||||||
browser.runtime.openOptionsPage();
|
browser.runtime.openOptionsPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSelectedTabIds(): Promise<number[]> {
|
async function getActiveTabId(): Promise<number> {
|
||||||
const selectedTabs = await browser.tabs.query({
|
const activeTabs = await browser.tabs.query({
|
||||||
highlighted: true,
|
active: true,
|
||||||
currentWindow: true,
|
currentWindow: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (selectedTabs.length > 0 && selectedTabs[0].id) {
|
if (activeTabs.length > 0 && activeTabs[0].id) return activeTabs[0].id;
|
||||||
return selectedTabs.filter((tab) => tab.id).map((tab) => tab.id as number);
|
|
||||||
}
|
|
||||||
throw new Error("No active tab.");
|
throw new Error("No active tab.");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function grabPost() {
|
async function grabPost() {
|
||||||
// Get active tab
|
// Get active tab
|
||||||
const selectedTabIds = await getSelectedTabIds();
|
const activeTabId = await getActiveTabId();
|
||||||
|
|
||||||
let scrapeResults: ScrapeResults = new ScrapeResults();
|
// Send 'grab_post' to the content script on the active tab
|
||||||
for (const selectedTabId of selectedTabIds) {
|
const x = await browser.tabs.sendMessage(activeTabId, new BrowserCommand("grab_post"));
|
||||||
// Send 'grab_post' to the content script on the active tabs
|
// We need to create a new ScrapeResults object and fill it with our data, because the get_posts()
|
||||||
const x = await browser.tabs.sendMessage(selectedTabId, new BrowserCommand("grab_post"));
|
// method gets 'lost' when sent from the contentscript to the popup (it gets JSON.stringified and any prototype defines are lost there)
|
||||||
// We need to create a new ScrapeResults object and fill it with our data, because the get_posts()
|
const res = Object.assign(new ScrapeResults(), x);
|
||||||
// method gets 'lost' when sent from the contentscript to the popup (it gets JSON.stringified and any prototype defines are lost there)
|
|
||||||
const results: ScrapeResults = Object.assign(new ScrapeResults(), x);
|
|
||||||
|
|
||||||
for (const result of results.results) {
|
console.dir(res);
|
||||||
const res = scrapeResults.results.find((r) => r.engine === result.engine);
|
|
||||||
if (res) res.posts.push(...result.posts);
|
|
||||||
else scrapeResults.results.push(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.dir(scrapeResults);
|
|
||||||
|
|
||||||
// Clear current posts array
|
// Clear current posts array
|
||||||
pop.posts.splice(0);
|
pop.posts.splice(0);
|
||||||
|
|
||||||
for (const result of scrapeResults.results) {
|
for (const result of res.results) {
|
||||||
for (const i in result.posts) {
|
for (const i in result.posts) {
|
||||||
const vm = new ScrapedPostDetails(result.posts[i]);
|
const vm = new ScrapedPostDetails(result.posts[i]);
|
||||||
const name = result.posts[i].name ?? `Post ${parseInt(i) + 1}`; // parseInt() is required!
|
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
|
||||||
vm.name = `[${result.engine}] ${name}`;
|
|
||||||
|
|
||||||
if (!cfg.value.addAllParsedTags) {
|
|
||||||
vm.tags.splice(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cfg.value.alwaysUploadAsContent && vm.name !== "[fallback] Upload as URL") {
|
|
||||||
vm.uploadMode = "content";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add current pageUrl to the source if either
|
// Add current pageUrl to the source if either
|
||||||
// a. user has addPageUrlToSource set to true
|
// a. user has addPageUrlToSource set to true
|
||||||
|
|
@ -136,14 +116,6 @@ async function grabPost() {
|
||||||
vm.instanceSpecificData[site.id] = {};
|
vm.instanceSpecificData[site.id] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove ignored tags
|
|
||||||
// The complexity for this is quite bad but all the other ways I tried were even worse
|
|
||||||
vm.tags = vm.tags.filter((tag) =>
|
|
||||||
cfg.value.tagIgnores.every(
|
|
||||||
(ignoredTag) => tag.name != ignoredTag.names[0], // no getters after deserializing
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
pop.posts.push(vm);
|
pop.posts.push(vm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +132,7 @@ async function grabPost() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.value.fetchPostInfo) {
|
if (cfg.value.fetchPostInfo) {
|
||||||
await fetchPostsInfo();
|
await fetchPostInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delayed call to findSimilar, as fetchPostInfo might change the post's contentUrl.
|
// Delayed call to findSimilar, as fetchPostInfo might change the post's contentUrl.
|
||||||
|
|
@ -183,18 +155,8 @@ async function upload() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const post: ScrapedPostDetails = cloneDeep(pop.selectedPost)!;
|
const post: any = cloneDeep(pop.selectedPost);
|
||||||
|
const cmdData = new PostUploadCommandData(post, <SzuruSiteConfig>cloneDeep(selectedSite.value));
|
||||||
// uploadMode "content" requires a content token to work. So ensure it is set.
|
|
||||||
if (post.uploadMode === "content") {
|
|
||||||
await ensurePostHasContentToken(szuru.value!, post, cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
const cmdData = new PostUploadCommandData(
|
|
||||||
post,
|
|
||||||
<SzuruSiteConfig>cloneDeep(selectedSite.value),
|
|
||||||
cfg.value.sendUploadNotifications,
|
|
||||||
);
|
|
||||||
const cmd = new BrowserCommand("upload_post", cmdData);
|
const cmd = new BrowserCommand("upload_post", cmdData);
|
||||||
await browser.runtime.sendMessage(cmd);
|
await browser.runtime.sendMessage(cmd);
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
|
|
@ -215,15 +177,6 @@ function removeTag(tag: TagDetails) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removePool(pool: PoolDetails) {
|
|
||||||
if (pop.selectedPost) {
|
|
||||||
const idx = pop.selectedPost.pools.indexOf(pool);
|
|
||||||
if (idx != -1) {
|
|
||||||
pop.selectedPost.pools.splice(idx, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getActiveSitePostUrl(postId: number): string {
|
function getActiveSitePostUrl(postId: number): string {
|
||||||
if (!selectedSite.value) return "";
|
if (!selectedSite.value) return "";
|
||||||
return getUrl(selectedSite.value.domain, "post", postId.toString());
|
return getUrl(selectedSite.value.domain, "post", postId.toString());
|
||||||
|
|
@ -259,15 +212,6 @@ function addTag(tag: TagDetails) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPool(pool: PoolDetails) {
|
|
||||||
if (pop.selectedPost) {
|
|
||||||
// Only add pool if it doesn't already exist
|
|
||||||
if (pool.name.length > 0 && pop.selectedPost.pools.find((x) => x.name == pool.name) == undefined) {
|
|
||||||
pop.selectedPost.pools.push(pool);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function clickFindSimilar() {
|
async function clickFindSimilar() {
|
||||||
if (pop.selectedPost) return await findSimilar(pop.selectedPost);
|
if (pop.selectedPost) return await findSimilar(pop.selectedPost);
|
||||||
}
|
}
|
||||||
|
|
@ -276,10 +220,6 @@ async function findSimilar(post: ScrapedPostDetails | undefined) {
|
||||||
if (!post || !szuru.value || !cfg.value.selectedSiteId) return;
|
if (!post || !szuru.value || !cfg.value.selectedSiteId) return;
|
||||||
|
|
||||||
// TODO: This code might not work.
|
// TODO: This code might not work.
|
||||||
// Why is toRaw used?
|
|
||||||
// I guess it could happen that the selectedInstance changes halfway during this function?
|
|
||||||
// And in that case toRaw would ensure we have the original selected instance (as it was at the start of this function).
|
|
||||||
// In theory this sounds correct, but idk if it is needed in practice.
|
|
||||||
const selectedInstance = toRaw(szuru.value); // Get current object, and not reactive.
|
const selectedInstance = toRaw(szuru.value); // Get current object, and not reactive.
|
||||||
let instanceSpecificData = post.instanceSpecificData[cfg.value.selectedSiteId];
|
let instanceSpecificData = post.instanceSpecificData[cfg.value.selectedSiteId];
|
||||||
|
|
||||||
|
|
@ -289,14 +229,23 @@ async function findSimilar(post: ScrapedPostDetails | undefined) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't load this again if it is already loaded.
|
// Don't load this again if it is already loaded.
|
||||||
if (instanceSpecificData.reverseSearchResult) return;
|
if (instanceSpecificData?.reverseSearchResult) return;
|
||||||
|
|
||||||
isSearchingForSimilarPosts.value++;
|
isSearchingForSimilarPosts.value++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ensurePostHasContentToken(selectedInstance, post, cfg);
|
let res: ImageSearchResult | undefined;
|
||||||
|
|
||||||
const res = await selectedInstance.reverseSearchToken(instanceSpecificData.contentToken!);
|
if (cfg.value.useContentTokens) {
|
||||||
|
let tmpRes = await selectedInstance.uploadTempFile(post.contentUrl);
|
||||||
|
// TODO: Error handling?
|
||||||
|
// Save contentToken in PostViewModel so that we can reuse it when creating/uploading the post.
|
||||||
|
instanceSpecificData.contentToken = tmpRes.token;
|
||||||
|
|
||||||
|
res = await selectedInstance.reverseSearchToken(tmpRes.token);
|
||||||
|
} else {
|
||||||
|
res = await selectedInstance.reverseSearch(post.contentUrl);
|
||||||
|
}
|
||||||
|
|
||||||
instanceSpecificData.reverseSearchResult = {
|
instanceSpecificData.reverseSearchResult = {
|
||||||
exactPostId: res.exactPost?.id,
|
exactPostId: res.exactPost?.id,
|
||||||
|
|
@ -323,66 +272,43 @@ async function loadTagCounts() {
|
||||||
// Not the best code, but it works I guess?
|
// Not the best code, but it works I guess?
|
||||||
if (resp) {
|
if (resp) {
|
||||||
for (let post of pop.posts)
|
for (let post of pop.posts)
|
||||||
for (let tag of resp.results) {
|
for (let tag of resp.results)
|
||||||
const postTag = post.tags.find((postTag) => tag.names.includes(postTag.name));
|
for (let postTag of post.tags)
|
||||||
if (postTag) postTag.usages = tag.usages;
|
if (postTag.name == tag.names[0]) {
|
||||||
}
|
postTag.usages = tag.usages;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updatePostWithRemoteInfo(post: ScrapedPostDetails, contentUrl: string) {
|
async function fetchPostInfo() {
|
||||||
// We are missing cookies/etc which means that the request might fail.
|
|
||||||
// If you want access to the cookies/session/etc then you need to execute this code inside the content script.
|
|
||||||
try {
|
|
||||||
// This request follows redirects.
|
|
||||||
const res = await fetch(contentUrl, { method: "HEAD" });
|
|
||||||
const size = res.headers.get("Content-Length");
|
|
||||||
const type = res.headers.get("Content-Type");
|
|
||||||
|
|
||||||
if (type) {
|
|
||||||
if (type.indexOf("text/html") != -1) {
|
|
||||||
// If we get a HTML page back it usually means that the request failed.
|
|
||||||
// Not all sites (e.g. e-hentai) reply with a 403.
|
|
||||||
throw new Error(
|
|
||||||
"Received a text/html content type. This probably means that we don't have permission to access the resource.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [_main, sub] = type.split("/");
|
|
||||||
if (sub) post.contentSubType = sub.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This should be after the type check, because the type check also checks whether the response we get is valid/unsable.
|
|
||||||
if (size) post.contentSize = parseInt(size);
|
|
||||||
|
|
||||||
// Update url if it changes. The url can change when:
|
|
||||||
// a. the extraContentUrl was successfully loaded
|
|
||||||
// b. because of redirects
|
|
||||||
if (res.url != post.contentUrl) {
|
|
||||||
// The developer needs to make sure that the remote server can load this URL if `post.uploadMode == 'url'`!
|
|
||||||
console.log(`Updating post.contentUrl to '${res.url}'`);
|
|
||||||
post.contentUrl = res.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (ex) {
|
|
||||||
console.error(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchPostsInfo() {
|
|
||||||
for (const post of pop.posts) {
|
for (const post of pop.posts) {
|
||||||
if (!post.contentSize || post.extraContentUrl) {
|
if (!post.contentSize || post.extraContentUrl) {
|
||||||
let ok = false;
|
// We are missing cookies/etc which means that the request might fail.
|
||||||
if (post.extraContentUrl) {
|
// If you want access to the cookies/session/etc then you need to execute this code inside the content script.
|
||||||
// Prioritize info from extraContentUrl.
|
try {
|
||||||
ok = await updatePostWithRemoteInfo(post, post.extraContentUrl);
|
const contentUrl = post.extraContentUrl ?? post.contentUrl;
|
||||||
}
|
|
||||||
if (!ok) {
|
// TODO: Check whether we need to call this in the background page, or if it is fine to call it from the popup.
|
||||||
// Fall back to normal contentUrl if we can't get the data from the extraContentUrl.
|
const res = await fetch(contentUrl, { method: "HEAD" });
|
||||||
await updatePostWithRemoteInfo(post, post.contentUrl);
|
const size = res.headers.get("Content-Length");
|
||||||
|
const type = res.headers.get("Content-Type");
|
||||||
|
|
||||||
|
if (size) post.contentSize = parseInt(size);
|
||||||
|
|
||||||
|
if (type) {
|
||||||
|
const [_main, sub] = type.split("/");
|
||||||
|
if (sub) post.contentSubType = sub.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve extraContentUrl redirects.
|
||||||
|
if (post.extraContentUrl && res.url != post.contentUrl) {
|
||||||
|
post.contentUrl = res.url;
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
// TODO: Maybe display an error in the UI.
|
||||||
|
console.error(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -394,8 +320,7 @@ function getUpdatedTagsText(count: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onResolutionLoaded(res: any) {
|
function onResolutionLoaded(res: any) {
|
||||||
// This no longer checks for `!pop.selectedPost.resolution` because the resolution can change if the contentUrl is updated.
|
if (pop.selectedPost && !pop.selectedPost.resolution) {
|
||||||
if (pop.selectedPost) {
|
|
||||||
pop.selectedPost.resolution = res;
|
pop.selectedPost.resolution = res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -412,7 +337,7 @@ useDark();
|
||||||
<template>
|
<template>
|
||||||
<div class="popup-messages">
|
<div class="popup-messages">
|
||||||
<div class="messages">
|
<div class="messages">
|
||||||
<!--
|
<!--
|
||||||
Error messages
|
Error messages
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
@ -446,10 +371,7 @@ useDark();
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--
|
<!-- Only show error when it's not undefined and not empty. -->
|
||||||
Only show error when it's not undefined and not empty.
|
|
||||||
TODO: Maybe remove this in favor of genericError?
|
|
||||||
-->
|
|
||||||
<div v-if="instanceSpecificData?.uploadState?.error?.length" class="bg-danger">
|
<div v-if="instanceSpecificData?.uploadState?.error?.length" class="bg-danger">
|
||||||
<span>Couldn't upload post. {{ instanceSpecificData.uploadState.error }}</span>
|
<span>Couldn't upload post. {{ instanceSpecificData.uploadState.error }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -580,13 +502,13 @@ useDark();
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="cfg.popup.showSource" class="section-row">
|
<div class="section-row">
|
||||||
<span class="section-label">Source</span>
|
<span class="section-label">Source</span>
|
||||||
<textarea v-model="pop.selectedPost.source"></textarea>
|
<textarea v-model="pop.selectedPost.source"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</PopupSection>
|
</PopupSection>
|
||||||
|
|
||||||
<PopupSection header="Tags" toggleable v-model="cfg.popup.expandTags">
|
<PopupSection header="Tags">
|
||||||
<div class="section-row">
|
<div class="section-row">
|
||||||
<TagInput :szuru="szuru" @add-tag="addTag" />
|
<TagInput :szuru="szuru" @add-tag="addTag" />
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -601,22 +523,7 @@ useDark();
|
||||||
</div>
|
</div>
|
||||||
</PopupSection>
|
</PopupSection>
|
||||||
|
|
||||||
<PopupSection v-if="cfg.popup.showPools" header="Pools" toggleable v-model="cfg.popup.expandPools">
|
<div class="popup-section">
|
||||||
<div class="section-row">
|
|
||||||
<PoolInput :szuru="szuru" @add-pool="addPool" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="section-row">
|
|
||||||
<CompactPools
|
|
||||||
:pools="pop.selectedPost.pools"
|
|
||||||
:show-remove-pool="true"
|
|
||||||
show-post-count
|
|
||||||
@remove-pool="removePool"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</PopupSection>
|
|
||||||
|
|
||||||
<div v-if="cfg.popup.showInstancePicker" class="popup-section">
|
|
||||||
<div class="section-row">
|
<div class="section-row">
|
||||||
<select v-model="cfg.selectedSiteId">
|
<select v-model="cfg.selectedSiteId">
|
||||||
<option v-for="site in cfg.sites" :key="site.id" :value="site.id">
|
<option v-for="site in cfg.sites" :key="site.id" :value="site.id">
|
||||||
|
|
@ -655,7 +562,7 @@ useDark();
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="p-3 flex items-center gap-3">
|
<div v-else class="p3 flex items-center gap-3">
|
||||||
<span>No content found</span>
|
<span>No content found</span>
|
||||||
<font-awesome-icon icon="fa-solid fa-cog" class="cursor-pointer" @click="openOptionsPage" />
|
<font-awesome-icon icon="fa-solid fa-cog" class="cursor-pointer" @click="openOptionsPage" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,13 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import deepMerge from "deepmerge";
|
import deepMerge from "deepmerge";
|
||||||
import {
|
import { SzuruSiteConfig } from "~/config";
|
||||||
type TagDetails,
|
import type { ScrapedPostDetails, SetPostUploadInfoData } from "~/models";
|
||||||
getDefaultTagCategories,
|
|
||||||
type ScrapedPostDetails,
|
|
||||||
type SetPostUploadInfoData,
|
|
||||||
type SzuruSiteConfig,
|
|
||||||
type TagCategoryColor,
|
|
||||||
} from "~/models";
|
|
||||||
import { useStorageLocal } from "~/composables/useStorageLocal";
|
import { useStorageLocal } from "~/composables/useStorageLocal";
|
||||||
|
|
||||||
export const cfg = useStorageLocal(
|
export const cfg = useStorageLocal(
|
||||||
"config",
|
"config",
|
||||||
{
|
{
|
||||||
version: 0,
|
|
||||||
addPageUrlToSource: true,
|
addPageUrlToSource: true,
|
||||||
alwaysUploadAsContent: false,
|
|
||||||
sendUploadNotifications: false,
|
|
||||||
autoSearchSimilar: false,
|
autoSearchSimilar: false,
|
||||||
loadTagCounts: true,
|
loadTagCounts: true,
|
||||||
fetchPostInfo: true,
|
fetchPostInfo: true,
|
||||||
|
|
@ -24,7 +15,6 @@ export const cfg = useStorageLocal(
|
||||||
sites: [] as Array<SzuruSiteConfig>,
|
sites: [] as Array<SzuruSiteConfig>,
|
||||||
selectedSiteId: undefined as string | undefined,
|
selectedSiteId: undefined as string | undefined,
|
||||||
addTagImplications: true,
|
addTagImplications: true,
|
||||||
addAllParsedTags: true,
|
|
||||||
merge: {
|
merge: {
|
||||||
expandOptions: true,
|
expandOptions: true,
|
||||||
expandExistingTags: false,
|
expandExistingTags: false,
|
||||||
|
|
@ -33,41 +23,10 @@ export const cfg = useStorageLocal(
|
||||||
appendSource: true,
|
appendSource: true,
|
||||||
mergeSafety: true,
|
mergeSafety: true,
|
||||||
},
|
},
|
||||||
popup: {
|
|
||||||
expandTags: true,
|
|
||||||
expandPools: false,
|
|
||||||
showSource: true,
|
|
||||||
showPools: true,
|
|
||||||
showInstancePicker: true,
|
|
||||||
},
|
|
||||||
tagCategories: [] as Array<TagCategoryColor>,
|
|
||||||
tagIgnores: [] as Array<TagDetails>,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mergeDefaults(storageValue, defaults) {
|
mergeDefaults: (storageValue, defaults) => deepMerge(defaults, storageValue),
|
||||||
const cfg = deepMerge(defaults, storageValue);
|
}
|
||||||
const oldVersion = cfg.version;
|
|
||||||
|
|
||||||
// Crappy config migration.
|
|
||||||
switch (cfg.version) {
|
|
||||||
case 0:
|
|
||||||
cfg.version++;
|
|
||||||
|
|
||||||
// Don't clear the existing tagCategories and don't add duplicates.
|
|
||||||
for (const cat of getDefaultTagCategories()) {
|
|
||||||
if (!cfg.tagCategories.find((x) => x.name == cat.name)) {
|
|
||||||
cfg.tagCategories.push(cat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldVersion != cfg.version) {
|
|
||||||
console.log(`Migrated config from version ${oldVersion} to ${cfg.version}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cfg;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export const usePopupStore = defineStore("popup", {
|
export const usePopupStore = defineStore("popup", {
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,56 @@
|
||||||
@use "sass:color";
|
@use "sass:color";
|
||||||
|
|
||||||
@use "primeflex/primeflex.scss";
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
/* open-sans-regular - latin */
|
/* open-sans-regular - latin */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Open Sans";
|
font-family: "Open Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
src:
|
src: local(""), url("/assets/open-sans-v34-latin-regular.woff2") format("woff2");
|
||||||
local(""),
|
|
||||||
url("/assets/open-sans-v34-latin-regular.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
|
|
||||||
*,
|
|
||||||
*:before,
|
|
||||||
*:after {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
|
@ -42,7 +77,6 @@ $danger-color-dark: color.scale($danger-color, $lightness: -50%);
|
||||||
--section-header-fg-color: #4c4c4c;
|
--section-header-fg-color: #4c4c4c;
|
||||||
--section-header-bg-color: #eee;
|
--section-header-bg-color: #eee;
|
||||||
--text-color: #111;
|
--text-color: #111;
|
||||||
--tab-color: rgba(0, 0, 0, 0.06);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html.dark {
|
html.dark {
|
||||||
|
|
@ -55,7 +89,6 @@ html.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;
|
||||||
--tab-color: rgba(255, 255, 255, 0.06);
|
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
background-color: var(--bg-main-color);
|
background-color: var(--bg-main-color);
|
||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
|
|
@ -96,10 +129,10 @@ 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: 2px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
|
|
||||||
padding: 0.2em 0.3em;
|
padding: 0.2em 0.3em;
|
||||||
// box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
|
@ -115,7 +148,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: 2px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
overflow-wrap: normal;
|
overflow-wrap: normal;
|
||||||
|
|
@ -125,7 +158,7 @@ textarea {
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
outline: var(--primary-color) solid 2px;
|
outline: var(--primary-color) solid 2px;
|
||||||
// box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,7 +171,6 @@ img {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED: Replace with primeflex w-full
|
|
||||||
.full {
|
.full {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
@ -149,8 +181,7 @@ ul.compact {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.compact-tags,
|
.compact-tags {
|
||||||
.compact-pools {
|
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
display: inline;
|
display: inline;
|
||||||
|
|
@ -167,6 +198,30 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
@ -228,49 +283,3 @@ a.remove-tag {
|
||||||
.cursor-pointer {
|
.cursor-pointer {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-primary {
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.separated-content > * + * {
|
|
||||||
padding-top: 1rem;
|
|
||||||
margin-top: 1.5rem;
|
|
||||||
border-top: 3px solid #333;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.popup-section {
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
video {
|
video {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
@ -33,3 +37,35 @@ label {
|
||||||
margin: 3px 3px 0 0;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
describe("Demo", () => {
|
describe('Demo', () => {
|
||||||
it("should work", () => {
|
it('should work', () => {
|
||||||
expect(1 + 1).toBe(2);
|
expect(1 + 1).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
26
src/utils.ts
26
src/utils.ts
|
|
@ -1,7 +1,6 @@
|
||||||
import byteSize from "byte-size";
|
import byteSize from "byte-size";
|
||||||
import { MicroUser, Post } from "./api/models";
|
import { MicroUser, Post } from "./api/models";
|
||||||
import { ScrapedPostDetails, TagDetails } from "./models";
|
import { ScrapedPostDetails, TagDetails } from "./models";
|
||||||
import SzurubooruApi from "./api";
|
|
||||||
|
|
||||||
export function getUrl(root: string, ...parts: string[]): string {
|
export function getUrl(root: string, ...parts: string[]): string {
|
||||||
let url = root.replace(/\/+$/, "");
|
let url = root.replace(/\/+$/, "");
|
||||||
|
|
@ -103,28 +102,3 @@ export function getPostInfoSummary(post: ScrapedPostDetails) {
|
||||||
}
|
}
|
||||||
return parts.join(" / ");
|
return parts.join(" / ");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function ensurePostHasContentToken(selectedInstance: SzurubooruApi, post: ScrapedPostDetails, cfg: any) {
|
|
||||||
if (!selectedInstance || !cfg.value.selectedSiteId) return;
|
|
||||||
|
|
||||||
const instanceSpecificData = post.instanceSpecificData[cfg.value.selectedSiteId];
|
|
||||||
|
|
||||||
if (!instanceSpecificData) {
|
|
||||||
console.error("instanceSpecificData is undefined. This should never happen!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (instanceSpecificData.contentToken) {
|
|
||||||
console.log("[ensurePostHasContentToken] contentToken is already set.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const tmpRes = await selectedInstance.uploadTempFile(post.contentUrl, post.uploadMode);
|
|
||||||
// Save contentToken in PostViewModel so that we can reuse it when creating/uploading the post.
|
|
||||||
instanceSpecificData.contentToken = tmpRes.token;
|
|
||||||
} catch (ex) {
|
|
||||||
instanceSpecificData.genericError = "Couldn't upload content. " + getErrorMessage(ex);
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,10 @@
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"target": "es2016",
|
"target": "es2016",
|
||||||
"lib": ["DOM", "ESNext"],
|
"lib": [
|
||||||
|
"DOM",
|
||||||
|
"ESNext"
|
||||||
|
],
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"incremental": false,
|
"incremental": false,
|
||||||
|
|
@ -13,10 +16,17 @@
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"types": ["vite/client"],
|
"types": [
|
||||||
|
"vite/client"
|
||||||
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"~/*": ["src/*"]
|
"~/*": [
|
||||||
|
"src/*"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exclude": ["dist", "node_modules"]
|
"exclude": [
|
||||||
|
"dist",
|
||||||
|
"node_modules"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
updates.json
12
updates.json
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"addons": {
|
|
||||||
"suzuruchrome@goblincave": {
|
|
||||||
"updates": [
|
|
||||||
{
|
|
||||||
"version": "0.1.4",
|
|
||||||
"update_link": "https://gitea.goblincave.synology.me/Nes/SzuruChrome/releases/download/mod-v0.1.X/SzuruChrome_v0.1.4.xpi"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue