Cleanup + fix issue where zerochan sometimes couldn't find the image
parent
26b257824e
commit
abda647335
|
|
@ -26,6 +26,7 @@ export default class NeoScraper {
|
|||
|
||||
for (const engine of this.engines) {
|
||||
if (ignoreCanImport || engine.canImport(document.location)) {
|
||||
console.log("Using engine: " + engine.name);
|
||||
res.results.push(engine.scrapeDocument(document));
|
||||
}
|
||||
}
|
||||
|
|
@ -34,10 +35,13 @@ export default class NeoScraper {
|
|||
if (!this.fallbackEngine) {
|
||||
console.error("NeoScraper.fallbackEngine is unset!");
|
||||
} else {
|
||||
console.log("Using fallback engine");
|
||||
res.results.push(this.fallbackEngine.scrapeDocument(document));
|
||||
}
|
||||
}
|
||||
|
||||
console.dir(res);
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,14 @@ export class ScrapeResult {
|
|||
constructor(engine: string) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
tryAddPost(post: ScrapedPost) {
|
||||
if (!post.imageUrl) {
|
||||
console.log(`[${this.engine}] Not adding post because imageUrl is unset!`);
|
||||
} else {
|
||||
this.posts.push(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ScrapeResults {
|
||||
|
|
|
|||
|
|
@ -78,9 +78,7 @@ export default class Danbooru implements ScrapeEngine {
|
|||
}
|
||||
}
|
||||
|
||||
if (post.imageUrl) {
|
||||
result.posts.push(post);
|
||||
}
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,9 +135,7 @@ export default class Gelbooru implements ScrapeEngine {
|
|||
}
|
||||
}
|
||||
|
||||
if (post.imageUrl) {
|
||||
result.posts.push(post);
|
||||
}
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,10 +88,7 @@ export default class Moebooru implements ScrapeEngine {
|
|||
post.tags.push(tag);
|
||||
}
|
||||
|
||||
|
||||
if (post.imageUrl) {
|
||||
result.posts.push(post);
|
||||
}
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,7 @@ export default class Reddit implements ScrapeEngine {
|
|||
post.imageUrl = (newLinkElements[0] as HTMLAnchorElement).href;
|
||||
}
|
||||
|
||||
if (post.imageUrl) {
|
||||
result.posts.push(post);
|
||||
}
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,9 +74,7 @@ export default class SankakuComplex implements ScrapeEngine {
|
|||
}
|
||||
}
|
||||
|
||||
if (post.imageUrl) {
|
||||
result.posts.push(post);
|
||||
}
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,7 @@ export default class Shimmie2 implements ScrapeEngine {
|
|||
.map(x => (x as HTMLAnchorElement).innerText.toLowerCase())
|
||||
.map(x => new ScrapedTag(x));
|
||||
|
||||
if (post.imageUrl) {
|
||||
result.posts.push(post);
|
||||
}
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ export default class Twitter implements ScrapeEngine {
|
|||
post.imageUrl = getOriginalImageUrl((mediaImageElements[0] as HTMLImageElement).src);
|
||||
}
|
||||
|
||||
if (post.imageUrl) {
|
||||
result.posts.push(post);
|
||||
}
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,14 @@ export default class Zerochan implements ScrapeEngine {
|
|||
// Set image url
|
||||
const previewElements = document.getElementsByClassName("preview");
|
||||
if (previewElements.length > 0) {
|
||||
// The preview element only exists when there is a larger size available. Preview's img element contains a downscaled version.
|
||||
post.imageUrl = (previewElements[0] as HTMLAnchorElement).href;
|
||||
} else {
|
||||
// When there is no larger version available just use the displayed version.
|
||||
const imgElement = document.querySelector("img[title='No larger size available']") as HTMLImageElement;
|
||||
if (imgElement) {
|
||||
post.imageUrl = imgElement.src;
|
||||
}
|
||||
}
|
||||
|
||||
// Set rating
|
||||
|
|
@ -59,9 +66,7 @@ export default class Zerochan implements ScrapeEngine {
|
|||
}
|
||||
}
|
||||
|
||||
if (post.imageUrl) {
|
||||
result.posts.push(post);
|
||||
}
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue