Add support for multiple sources
- Add the "Add page URL to the source list" optionnext
parent
b899d2b794
commit
136087d83e
11
package.json
11
package.json
|
|
@ -7,12 +7,13 @@
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "https://github.com/neobooru/SzuruChrome"
|
"url": "https://github.com/neobooru/SzuruChrome"
|
||||||
},
|
},
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack --config webpack.prod.js",
|
"build": "webpack --config webpack.prod.cjs",
|
||||||
"build:dev": "webpack --config webpack.dev.js",
|
"build:dev": "webpack --config webpack.dev.cjs",
|
||||||
"build-zip": "node scripts/build-zip.js",
|
"build-zip": "node scripts/build-zip.cjs",
|
||||||
"sign-xpi": "node scripts/sign-xpi.js",
|
"sign-xpi": "node scripts/sign-xpi.cjs",
|
||||||
"watch": "webpack --watch --config webpack.dev.js",
|
"watch": "webpack --watch --config webpack.dev.cjs",
|
||||||
"lint": "eslint src"
|
"lint": "eslint src"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ export class Config {
|
||||||
importExistingTags = true;
|
importExistingTags = true;
|
||||||
importAllTags = false;
|
importAllTags = false;
|
||||||
importCommentary = false;
|
importCommentary = false;
|
||||||
useOriginalSource = true;
|
addPageUrlToSource = true;
|
||||||
autoSearchSimilar = false;
|
autoSearchSimilar = false;
|
||||||
loadTagCounts = true;
|
loadTagCounts = true;
|
||||||
useContentTokens = true;
|
useContentTokens = true;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ export class TagViewModel {
|
||||||
const x = new TagViewModel(tag.names[0], <BooruTypes.TagCategory>tag.category, tag.usages);
|
const x = new TagViewModel(tag.names[0], <BooruTypes.TagCategory>tag.category, tag.usages);
|
||||||
|
|
||||||
if (tag.implications) {
|
if (tag.implications) {
|
||||||
x.implications = tag.implications.map(y => TagViewModel.fromMicroTag(y));
|
x.implications = tag.implications.map((y) => TagViewModel.fromMicroTag(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
|
|
@ -34,7 +34,7 @@ export class PostViewModel {
|
||||||
pageUrl: string;
|
pageUrl: string;
|
||||||
contentType: ContentType;
|
contentType: ContentType;
|
||||||
rating: BooruTypes.SafetyRating;
|
rating: BooruTypes.SafetyRating;
|
||||||
source: string | undefined;
|
source = "";
|
||||||
referrer: string | undefined;
|
referrer: string | undefined;
|
||||||
resolution: [number, number] | undefined;
|
resolution: [number, number] | undefined;
|
||||||
|
|
||||||
|
|
@ -43,9 +43,15 @@ export class PostViewModel {
|
||||||
this.pageUrl = post.pageUrl;
|
this.pageUrl = post.pageUrl;
|
||||||
this.contentType = post.contentType;
|
this.contentType = post.contentType;
|
||||||
this.rating = post.rating;
|
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.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.notes = post.notes;
|
||||||
this.resolution = post.resolution;
|
this.resolution = post.resolution;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,17 +21,30 @@ button.primary {
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="text"] {
|
input[type="text"] {
|
||||||
|
height: 26px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"],
|
||||||
|
textarea {
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
border: 1px solid #eee;
|
border: 1px solid #eee;
|
||||||
height: 26px;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="text"]:focus {
|
input[type="text"]:focus,
|
||||||
|
textarea:focus {
|
||||||
outline: #24aadd solid 2px;
|
outline: #24aadd solid 2px;
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
white-space: pre;
|
||||||
|
overflow-wrap: normal;
|
||||||
|
overflow-x: scroll;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,13 @@
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" v-model="useOriginalSource" />
|
<input type="checkbox" v-model="addPageUrlToSource" />
|
||||||
Use original image source when available
|
Add page URL to the source list
|
||||||
</label>
|
</label>
|
||||||
<p class="hint">
|
<p class="hint">
|
||||||
Use the original image source when available. Usually this will mean a Twitter, DeviantArt, ArtStation, or
|
This will add the current page URL (e.g. the booru link) to the source list in addition to the actual source
|
||||||
Pixiv page.
|
(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>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
@ -74,7 +75,7 @@ export default Vue.extend({
|
||||||
authToken: "",
|
authToken: "",
|
||||||
autoSearchSimilar: false,
|
autoSearchSimilar: false,
|
||||||
loadTagCounts: false,
|
loadTagCounts: false,
|
||||||
useOriginalSource: false,
|
addPageUrlToSource: false,
|
||||||
useContentTokens: false,
|
useContentTokens: false,
|
||||||
statusText: "",
|
statusText: "",
|
||||||
statusType: "",
|
statusType: "",
|
||||||
|
|
@ -114,7 +115,7 @@ export default Vue.extend({
|
||||||
config.sites = [siteConfig];
|
config.sites = [siteConfig];
|
||||||
config.autoSearchSimilar = this.autoSearchSimilar;
|
config.autoSearchSimilar = this.autoSearchSimilar;
|
||||||
config.loadTagCounts = this.loadTagCounts;
|
config.loadTagCounts = this.loadTagCounts;
|
||||||
config.useOriginalSource = this.useOriginalSource;
|
config.addPageUrlToSource = this.addPageUrlToSource;
|
||||||
config.useContentTokens = this.useContentTokens;
|
config.useContentTokens = this.useContentTokens;
|
||||||
|
|
||||||
await config.save();
|
await config.save();
|
||||||
|
|
@ -140,7 +141,7 @@ export default Vue.extend({
|
||||||
|
|
||||||
this.autoSearchSimilar = config.autoSearchSimilar;
|
this.autoSearchSimilar = config.autoSearchSimilar;
|
||||||
this.loadTagCounts = config.loadTagCounts;
|
this.loadTagCounts = config.loadTagCounts;
|
||||||
this.useOriginalSource = config.useOriginalSource;
|
this.addPageUrlToSource = config.addPageUrlToSource;
|
||||||
this.useContentTokens = config.useContentTokens;
|
this.useContentTokens = config.useContentTokens;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
|
|
||||||
<div class="section-row">
|
<div class="section-row">
|
||||||
<span class="section-label">Source</span>
|
<span class="section-label">Source</span>
|
||||||
<input type="text" v-model="selectedPost.source" />
|
<textarea v-model="selectedPost.source" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
@click="onClickAutocompleteTagItem(tag)"
|
@click="onClickAutocompleteTagItem(tag)"
|
||||||
:key="tag.name"
|
:key="tag.name"
|
||||||
:class="{
|
:class="{
|
||||||
active: idx == autocompleteIndex
|
active: idx == autocompleteIndex,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<span :class="getTagClasses(tag)">{{ tag.name }}</span>
|
<span :class="getTagClasses(tag)">{{ tag.name }}</span>
|
||||||
|
|
@ -158,7 +158,7 @@ export default Vue.extend({
|
||||||
cancelSource: null as CancelTokenSource | null,
|
cancelSource: null as CancelTokenSource | null,
|
||||||
autocompleteIndex: -1,
|
autocompleteIndex: -1,
|
||||||
showTagUsages: false,
|
showTagUsages: false,
|
||||||
showFindSimilarButton: true
|
showFindSimilarButton: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
|
@ -167,13 +167,13 @@ export default Vue.extend({
|
||||||
// No need to check if any vars are unset, findSimilar does that internally
|
// No need to check if any vars are unset, findSimilar does that internally
|
||||||
this.findSimilar();
|
this.findSimilar();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async getActiveTabId() {
|
async getActiveTabId() {
|
||||||
const activeTabs = await browser.tabs.query({
|
const activeTabs = await browser.tabs.query({
|
||||||
active: true,
|
active: true,
|
||||||
currentWindow: true
|
currentWindow: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (activeTabs.length > 0) return activeTabs[0].id!;
|
if (activeTabs.length > 0) return activeTabs[0].id!;
|
||||||
|
|
@ -198,8 +198,11 @@ export default Vue.extend({
|
||||||
const vm = new PostViewModel(result.posts[i]);
|
const vm = new PostViewModel(result.posts[i]);
|
||||||
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
|
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
|
||||||
|
|
||||||
if (!this.config?.useOriginalSource || vm.source == undefined) {
|
// Add current pageUrl to the source if either
|
||||||
vm.source = vm.pageUrl;
|
// 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);
|
this.posts.push(vm);
|
||||||
|
|
@ -308,7 +311,7 @@ export default Vue.extend({
|
||||||
addTag(tag: TagViewModel) {
|
addTag(tag: TagViewModel) {
|
||||||
if (this.selectedPost) {
|
if (this.selectedPost) {
|
||||||
// Only add tag if it doesn't already exist
|
// 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);
|
this.selectedPost.tags.push(tag);
|
||||||
|
|
||||||
// Add implications for the tag
|
// Add implications for the tag
|
||||||
|
|
@ -375,12 +378,12 @@ export default Vue.extend({
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
async loadTagCounts() {
|
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) {
|
for (let i = 0; i < allTags.length; i += 100) {
|
||||||
const query = allTags
|
const query = allTags
|
||||||
.slice(i, i + 101)
|
.slice(i, i + 101)
|
||||||
.map(x => encodeTagName(x.name))
|
.map((x) => encodeTagName(x.name))
|
||||||
.join();
|
.join();
|
||||||
const resp = await this.szuru?.getTags(query);
|
const resp = await this.szuru?.getTags(query);
|
||||||
|
|
||||||
|
|
@ -467,9 +470,9 @@ export default Vue.extend({
|
||||||
this.cancelSource.token
|
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;
|
if (this.autocompleteTags.length > 0) this.autocompleteShown = true;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
this.config = await Config.load();
|
this.config = await Config.load();
|
||||||
|
|
@ -520,7 +523,7 @@ export default Vue.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
return <WebRequest.BlockingResponse>{
|
return <WebRequest.BlockingResponse>{
|
||||||
requestHeaders
|
requestHeaders,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{ urls: ["<all_urls>"] },
|
{ urls: ["<all_urls>"] },
|
||||||
|
|
@ -529,7 +532,7 @@ export default Vue.extend({
|
||||||
|
|
||||||
// Always call grabPost, even when there is no activeSite
|
// Always call grabPost, even when there is no activeSite
|
||||||
await this.grabPost();
|
await this.grabPost();
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { BrowserCommand } from "../Common";
|
||||||
|
|
||||||
function grabPost(): ScrapeResults {
|
function grabPost(): ScrapeResults {
|
||||||
const scraper = new NeoScraper();
|
const scraper = new NeoScraper();
|
||||||
return scraper.scrapeDocument(document, undefined, true);
|
return scraper.scrapeDocument(document, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function messageHandler(cmd: BrowserCommand): Promise<any> {
|
async function messageHandler(cmd: BrowserCommand): Promise<any> {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
const { merge } = require("webpack-merge");
|
const { merge } = require("webpack-merge");
|
||||||
const ExtensionReloader = require("webpack-ext-reloader");
|
const ExtensionReloader = require("webpack-ext-reloader");
|
||||||
const common = require("./webpack.common.js");
|
const common = require("./webpack.common.cjs");
|
||||||
|
|
||||||
module.exports = merge(common, {
|
module.exports = merge(common, {
|
||||||
mode: "development",
|
mode: "development",
|
||||||
devtool: "inline-source-map",
|
devtool: "inline-source-map",
|
||||||
plugins: [
|
// plugins: [
|
||||||
...common.plugins,
|
// ...common.plugins,
|
||||||
new ExtensionReloader({
|
// new ExtensionReloader({
|
||||||
manifest: __dirname + "/src/manifest.json"
|
// manifest: __dirname + "/src/manifest.json"
|
||||||
})
|
// })
|
||||||
]
|
// ]
|
||||||
});
|
});
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const { merge } = require("webpack-merge");
|
const { merge } = require("webpack-merge");
|
||||||
const common = require("./webpack.common.js");
|
const common = require("./webpack.common.cjs");
|
||||||
|
|
||||||
module.exports = merge(common, {
|
module.exports = merge(common, {
|
||||||
mode: "production"
|
mode: "production"
|
||||||
|
|
@ -1937,7 +1937,7 @@ neo-async@^2.6.2:
|
||||||
|
|
||||||
"neo-scraper@git+https://github.com/neobooru/neo-scraper.git":
|
"neo-scraper@git+https://github.com/neobooru/neo-scraper.git":
|
||||||
version "0.5.5"
|
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:
|
dependencies:
|
||||||
turndown "^7.1.1"
|
turndown "^7.1.1"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue