Run prettier
parent
381dac72d4
commit
a0a0a591bc
|
|
@ -8,7 +8,7 @@ export class TagDetails {
|
||||||
public names: string[],
|
public names: string[],
|
||||||
public category?: string,
|
public category?: string,
|
||||||
public usages?: number,
|
public usages?: number,
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return this.names[0];
|
return this.names[0];
|
||||||
|
|
@ -38,7 +38,7 @@ export class PoolDetails {
|
||||||
public names: string[],
|
public names: string[],
|
||||||
public category?: string,
|
public category?: string,
|
||||||
public postCount?: number,
|
public postCount?: number,
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return this.names[0];
|
return this.names[0];
|
||||||
|
|
@ -109,7 +109,7 @@ export class SimilarPostInfo {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly id: number,
|
public readonly id: number,
|
||||||
public readonly percentage: number,
|
public readonly percentage: number,
|
||||||
) { }
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PostUploadState = "uploading" | "uploaded" | "error";
|
export type PostUploadState = "uploading" | "uploaded" | "error";
|
||||||
|
|
@ -149,7 +149,7 @@ export class PostUploadCommandData {
|
||||||
public readonly post: ScrapedPostDetails,
|
public readonly post: ScrapedPostDetails,
|
||||||
public readonly selectedSite: SzuruSiteConfig,
|
public readonly selectedSite: SzuruSiteConfig,
|
||||||
public readonly sendNotifications: boolean,
|
public readonly sendNotifications: boolean,
|
||||||
) { }
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetPostUploadInfoData {
|
export class SetPostUploadInfoData {
|
||||||
|
|
@ -157,7 +157,7 @@ export class SetPostUploadInfoData {
|
||||||
public instanceId: string,
|
public instanceId: string,
|
||||||
public postId: string,
|
public postId: string,
|
||||||
public info: PostUploadInfo,
|
public info: PostUploadInfo,
|
||||||
) { }
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetExactPostId {
|
export class SetExactPostId {
|
||||||
|
|
@ -165,7 +165,7 @@ export class SetExactPostId {
|
||||||
public readonly instanceId: string,
|
public readonly instanceId: string,
|
||||||
public readonly postId: string,
|
public readonly postId: string,
|
||||||
public readonly exactPostId: number,
|
public readonly exactPostId: number,
|
||||||
) { }
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PostUpdateCommandData {
|
export class PostUpdateCommandData {
|
||||||
|
|
@ -173,14 +173,14 @@ export class PostUpdateCommandData {
|
||||||
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 url: string,
|
||||||
public readonly options: RequestInit | undefined = undefined,
|
public readonly options: RequestInit | undefined = undefined,
|
||||||
) { }
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SzuruSiteConfig {
|
export class SzuruSiteConfig {
|
||||||
|
|
@ -194,7 +194,7 @@ export class TagCategoryColor {
|
||||||
constructor(
|
constructor(
|
||||||
public name: string,
|
public name: string,
|
||||||
public color: string,
|
public color: string,
|
||||||
) { }
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getDefaultTagCategories = () => [
|
export const getDefaultTagCategories = () => [
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,7 @@ async function getSelectedTabIds(): Promise<number[]> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (selectedTabs.length > 0 && selectedTabs[0].id) {
|
if (selectedTabs.length > 0 && selectedTabs[0].id) {
|
||||||
return selectedTabs
|
return selectedTabs.filter((tab) => tab.id).map((tab) => tab.id as number);
|
||||||
.filter(tab => tab.id)
|
|
||||||
.map(tab => tab.id as number)
|
|
||||||
}
|
}
|
||||||
throw new Error("No active tab.");
|
throw new Error("No active tab.");
|
||||||
}
|
}
|
||||||
|
|
@ -92,16 +90,16 @@ async function grabPost() {
|
||||||
const selectedTabIds = await getSelectedTabIds();
|
const selectedTabIds = await getSelectedTabIds();
|
||||||
|
|
||||||
let scrapeResults: ScrapeResults = new ScrapeResults();
|
let scrapeResults: ScrapeResults = new ScrapeResults();
|
||||||
for(const selectedTabId of selectedTabIds) {
|
for (const selectedTabId of selectedTabIds) {
|
||||||
// Send 'grab_post' to the content script on the active tabs
|
// Send 'grab_post' to the content script on the active tabs
|
||||||
const x = await browser.tabs.sendMessage(selectedTabId, new BrowserCommand("grab_post"));
|
const x = await browser.tabs.sendMessage(selectedTabId, new BrowserCommand("grab_post"));
|
||||||
// We need to create a new ScrapeResults object and fill it with our data, because the get_posts()
|
// We need to create a new ScrapeResults object and fill it with our data, because the get_posts()
|
||||||
// method gets 'lost' when sent from the contentscript to the popup (it gets JSON.stringified and any prototype defines are lost there)
|
// 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);
|
const results: ScrapeResults = Object.assign(new ScrapeResults(), x);
|
||||||
|
|
||||||
for(const result of results.results) {
|
for (const result of results.results) {
|
||||||
const res = scrapeResults.results.find((r) => r.engine === result.engine);
|
const res = scrapeResults.results.find((r) => r.engine === result.engine);
|
||||||
if(res) res.posts.push(...result.posts);
|
if (res) res.posts.push(...result.posts);
|
||||||
else scrapeResults.results.push(result);
|
else scrapeResults.results.push(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -140,9 +138,11 @@ async function grabPost() {
|
||||||
|
|
||||||
// Remove ignored tags
|
// Remove ignored tags
|
||||||
// The complexity for this is quite bad but all the other ways I tried were even worse
|
// 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(
|
vm.tags = vm.tags.filter((tag) =>
|
||||||
ignoredTag => tag.name != ignoredTag.names[0] // no getters after deserializing
|
cfg.value.tagIgnores.every(
|
||||||
));
|
(ignoredTag) => tag.name != ignoredTag.names[0], // no getters after deserializing
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
pop.posts.push(vm);
|
pop.posts.push(vm);
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +190,11 @@ async function upload() {
|
||||||
await ensurePostHasContentToken(szuru.value!, post, cfg);
|
await ensurePostHasContentToken(szuru.value!, post, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const cmdData = new PostUploadCommandData(post, <SzuruSiteConfig>cloneDeep(selectedSite.value), cfg.value.sendUploadNotifications);
|
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) {
|
||||||
|
|
@ -321,7 +325,7 @@ async function loadTagCounts() {
|
||||||
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));
|
const postTag = post.tags.find((postTag) => tag.names.includes(postTag.name));
|
||||||
if(postTag) postTag.usages = tag.usages;
|
if (postTag) postTag.usages = tag.usages;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue