Add support for multiple sources

- Add the "Add page URL to the source list" option
next
neobooru 2022-08-12 00:39:24 +02:00
parent b899d2b794
commit 136087d83e
13 changed files with 67 additions and 43 deletions

View File

@ -7,12 +7,13 @@
"repository": {
"url": "https://github.com/neobooru/SzuruChrome"
},
"type": "module",
"scripts": {
"build": "webpack --config webpack.prod.js",
"build:dev": "webpack --config webpack.dev.js",
"build-zip": "node scripts/build-zip.js",
"sign-xpi": "node scripts/sign-xpi.js",
"watch": "webpack --watch --config webpack.dev.js",
"build": "webpack --config webpack.prod.cjs",
"build:dev": "webpack --config webpack.dev.cjs",
"build-zip": "node scripts/build-zip.cjs",
"sign-xpi": "node scripts/sign-xpi.cjs",
"watch": "webpack --watch --config webpack.dev.cjs",
"lint": "eslint src"
},
"dependencies": {

View File

@ -10,7 +10,7 @@ export class Config {
importExistingTags = true;
importAllTags = false;
importCommentary = false;
useOriginalSource = true;
addPageUrlToSource = true;
autoSearchSimilar = false;
loadTagCounts = true;
useContentTokens = true;

View File

@ -10,7 +10,7 @@ export class TagViewModel {
const x = new TagViewModel(tag.names[0], <BooruTypes.TagCategory>tag.category, tag.usages);
if (tag.implications) {
x.implications = tag.implications.map(y => TagViewModel.fromMicroTag(y));
x.implications = tag.implications.map((y) => TagViewModel.fromMicroTag(y));
}
return x;
@ -34,7 +34,7 @@ export class PostViewModel {
pageUrl: string;
contentType: ContentType;
rating: BooruTypes.SafetyRating;
source: string | undefined;
source = "";
referrer: string | undefined;
resolution: [number, number] | undefined;
@ -43,9 +43,15 @@ export class PostViewModel {
this.pageUrl = post.pageUrl;
this.contentType = post.contentType;
this.rating = post.rating;
this.source = post.source;
if (post.sources.length > 0) {
// Add extra newline at the end for user convenience. This allows the user to click below the last source line to add something.
// But we only do this if there is at least one source, otherwise we get a blank line when there are zero sources.
this.source = post.sources.join("\n") + "\n";
}
this.referrer = post.referrer;
this.tags = post.tags.map(x => TagViewModel.fromScapedTag(x));
this.tags = post.tags.map((x) => TagViewModel.fromScapedTag(x));
this.notes = post.notes;
this.resolution = post.resolution;
}

View File

@ -21,17 +21,30 @@ button.primary {
}
input[type="text"] {
height: 26px;
}
input[type="text"],
textarea {
background-color: #fafafa;
border: 1px solid #eee;
height: 26px;
width: 100%;
}
input[type="text"]:focus {
input[type="text"]:focus,
textarea:focus {
outline: #24aadd solid 2px;
box-sizing: content-box;
}
textarea {
white-space: pre;
overflow-wrap: normal;
overflow-x: scroll;
text-overflow: ellipsis;
resize: vertical;
}
img {
max-width: 100%;
max-height: 100%;

View File

@ -29,12 +29,13 @@
</li>
<li>
<label>
<input type="checkbox" v-model="useOriginalSource" />
Use original image source when available
<input type="checkbox" v-model="addPageUrlToSource" />
Add page URL to the source list
</label>
<p class="hint">
Use the original image source when available. Usually this will mean a Twitter, DeviantArt, ArtStation, or
Pixiv page.
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>
</li>
<li>
@ -74,7 +75,7 @@ export default Vue.extend({
authToken: "",
autoSearchSimilar: false,
loadTagCounts: false,
useOriginalSource: false,
addPageUrlToSource: false,
useContentTokens: false,
statusText: "",
statusType: "",
@ -114,7 +115,7 @@ export default Vue.extend({
config.sites = [siteConfig];
config.autoSearchSimilar = this.autoSearchSimilar;
config.loadTagCounts = this.loadTagCounts;
config.useOriginalSource = this.useOriginalSource;
config.addPageUrlToSource = this.addPageUrlToSource;
config.useContentTokens = this.useContentTokens;
await config.save();
@ -140,7 +141,7 @@ export default Vue.extend({
this.autoSearchSimilar = config.autoSearchSimilar;
this.loadTagCounts = config.loadTagCounts;
this.useOriginalSource = config.useOriginalSource;
this.addPageUrlToSource = config.addPageUrlToSource;
this.useContentTokens = config.useContentTokens;
},
});

View File

@ -43,7 +43,7 @@
<div class="section-row">
<span class="section-label">Source</span>
<input type="text" v-model="selectedPost.source" />
<textarea v-model="selectedPost.source" />
</div>
</div>
@ -70,7 +70,7 @@
@click="onClickAutocompleteTagItem(tag)"
:key="tag.name"
:class="{
active: idx == autocompleteIndex
active: idx == autocompleteIndex,
}"
>
<span :class="getTagClasses(tag)">{{ tag.name }}</span>
@ -158,7 +158,7 @@ export default Vue.extend({
cancelSource: null as CancelTokenSource | null,
autocompleteIndex: -1,
showTagUsages: false,
showFindSimilarButton: true
showFindSimilarButton: true,
};
},
watch: {
@ -167,13 +167,13 @@ export default Vue.extend({
// No need to check if any vars are unset, findSimilar does that internally
this.findSimilar();
}
}
},
},
methods: {
async getActiveTabId() {
const activeTabs = await browser.tabs.query({
active: true,
currentWindow: true
currentWindow: true,
});
if (activeTabs.length > 0) return activeTabs[0].id!;
@ -198,8 +198,11 @@ export default Vue.extend({
const vm = new PostViewModel(result.posts[i]);
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
if (!this.config?.useOriginalSource || vm.source == undefined) {
vm.source = vm.pageUrl;
// Add current pageUrl to the source if either
// a. source is empty
// b. user has addPageUrlToSource set to true
if (this.config?.addPageUrlToSource || vm.source == "") {
vm.source += vm.pageUrl + "\n";
}
this.posts.push(vm);
@ -308,7 +311,7 @@ export default Vue.extend({
addTag(tag: TagViewModel) {
if (this.selectedPost) {
// Only add tag if it doesn't already exist
if (tag.name.length > 0 && this.selectedPost.tags.find(x => x.name == tag.name) == undefined) {
if (tag.name.length > 0 && this.selectedPost.tags.find((x) => x.name == tag.name) == undefined) {
this.selectedPost.tags.push(tag);
// Add implications for the tag
@ -375,12 +378,12 @@ export default Vue.extend({
return undefined;
},
async loadTagCounts() {
const allTags = this.posts.flatMap(x => x.tags);
const allTags = this.posts.flatMap((x) => x.tags);
for (let i = 0; i < allTags.length; i += 100) {
const query = allTags
.slice(i, i + 101)
.map(x => encodeTagName(x.name))
.map((x) => encodeTagName(x.name))
.join();
const resp = await this.szuru?.getTags(query);
@ -467,9 +470,9 @@ export default Vue.extend({
this.cancelSource.token
);
this.autocompleteTags = resp!.results.map(x => TagViewModel.fromTag(x));
this.autocompleteTags = resp!.results.map((x) => TagViewModel.fromTag(x));
if (this.autocompleteTags.length > 0) this.autocompleteShown = true;
}
},
},
async mounted() {
this.config = await Config.load();
@ -520,7 +523,7 @@ export default Vue.extend({
}
return <WebRequest.BlockingResponse>{
requestHeaders
requestHeaders,
};
},
{ urls: ["<all_urls>"] },
@ -529,7 +532,7 @@ export default Vue.extend({
// Always call grabPost, even when there is no activeSite
await this.grabPost();
}
},
});
</script>

View File

@ -4,7 +4,7 @@ import { BrowserCommand } from "../Common";
function grabPost(): ScrapeResults {
const scraper = new NeoScraper();
return scraper.scrapeDocument(document, undefined, true);
return scraper.scrapeDocument(document, true);
}
async function messageHandler(cmd: BrowserCommand): Promise<any> {

View File

@ -1,14 +1,14 @@
const { merge } = require("webpack-merge");
const ExtensionReloader = require("webpack-ext-reloader");
const common = require("./webpack.common.js");
const common = require("./webpack.common.cjs");
module.exports = merge(common, {
mode: "development",
devtool: "inline-source-map",
plugins: [
...common.plugins,
new ExtensionReloader({
manifest: __dirname + "/src/manifest.json"
})
]
// plugins: [
// ...common.plugins,
// new ExtensionReloader({
// manifest: __dirname + "/src/manifest.json"
// })
// ]
});

View File

@ -1,5 +1,5 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
const common = require("./webpack.common.cjs");
module.exports = merge(common, {
mode: "production"

View File

@ -1937,7 +1937,7 @@ neo-async@^2.6.2:
"neo-scraper@git+https://github.com/neobooru/neo-scraper.git":
version "0.5.5"
resolved "git+https://github.com/neobooru/neo-scraper.git#d127ec755b4b9b718508ce4b2cba66e900b6022d"
resolved "git+https://github.com/neobooru/neo-scraper.git#75f5c201b4a4779928002d8cbb0c2dac03786353"
dependencies:
turndown "^7.1.1"