Add Zerochan + small fixes
parent
01022802c1
commit
b20db79a95
|
|
@ -1014,9 +1014,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"commander": {
|
"commander": {
|
||||||
"version": "2.20.0",
|
"version": "2.20.3",
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz",
|
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
||||||
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==",
|
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
|
@ -2206,9 +2206,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"handlebars": {
|
"handlebars": {
|
||||||
"version": "4.2.1",
|
"version": "4.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.1.tgz",
|
||||||
"integrity": "sha512-bqPIlDk06UWbVEIFoYj+LVo42WhK96J+b25l7hbFDpxrOXMphFM3fNIm+cluwg4Pk2jiLjWU5nHQY7igGE75NQ==",
|
"integrity": "sha512-C29UoFzHe9yM61lOsIlCE5/mQVGrnIOrOq7maQl76L7tYPCgC1og0Ajt6uWnX4ZTxBPnjw+CUvawphwCfJgUnA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"neo-async": "^2.6.0",
|
"neo-async": "^2.6.0",
|
||||||
|
|
@ -4744,13 +4744,13 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"uglify-js": {
|
"uglify-js": {
|
||||||
"version": "3.6.0",
|
"version": "3.6.8",
|
||||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.8.tgz",
|
||||||
"integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==",
|
"integrity": "sha512-XhHJ3S3ZyMwP8kY1Gkugqx3CJh2C3O0y8NPiSxtm1tyD/pktLAkFZsFGpuNfTZddKDQ/bbDBLAd2YyA1pbi8HQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"commander": "~2.20.0",
|
"commander": "~2.20.3",
|
||||||
"source-map": "~0.6.1"
|
"source-map": "~0.6.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "neo-scraper",
|
"name": "neo-scraper",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"description": "Scrape a booru-like post object from the DOM.",
|
"description": "Scrape a booru-like post object from the DOM.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.js",
|
"types": "dist/index.d.js",
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ export default class NeoScraper {
|
||||||
new engines.Moebooru(),
|
new engines.Moebooru(),
|
||||||
new engines.Reddit(),
|
new engines.Reddit(),
|
||||||
new engines.Shimmie2(),
|
new engines.Shimmie2(),
|
||||||
new engines.Twitter()
|
new engines.Twitter(),
|
||||||
|
new engines.Zerochan(),
|
||||||
);
|
);
|
||||||
this.fallbackEngine = new engines.Fallback();
|
this.fallbackEngine = new engines.Fallback();
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +31,7 @@ export default class NeoScraper {
|
||||||
|
|
||||||
if (allowFallbackEngine) {
|
if (allowFallbackEngine) {
|
||||||
if (!this.fallbackEngine) {
|
if (!this.fallbackEngine) {
|
||||||
console.error("this.fallbackEngine is unset!");
|
console.error("NeoScraper.fallbackEngine is unset!");
|
||||||
} else {
|
} else {
|
||||||
res.results.push(this.fallbackEngine.scrapeDocument(document));
|
res.results.push(this.fallbackEngine.scrapeDocument(document));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,7 @@ export default class Twitter implements ScrapeEngine {
|
||||||
name = "twitter";
|
name = "twitter";
|
||||||
|
|
||||||
canImport(url: Location): boolean {
|
canImport(url: Location): boolean {
|
||||||
return (
|
return url.host == "twitter.com";
|
||||||
url.host == "danbooru.donmai.us" ||
|
|
||||||
url.host == "safebooru.donmai.us"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scrapeDocument(document: Document): ScrapeResult {
|
scrapeDocument(document: Document): ScrapeResult {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
import { ScrapeEngine, ScrapeResult, ScrapedPost, ScrapedTag } from "../ScrapeEngine";
|
||||||
|
import { TagCategory } from "../BooruTypes";
|
||||||
|
|
||||||
|
export default class Zerochan implements ScrapeEngine {
|
||||||
|
name = "zerochan";
|
||||||
|
|
||||||
|
canImport(url: Location): boolean {
|
||||||
|
return url.host.endsWith("zerochan.net");
|
||||||
|
}
|
||||||
|
|
||||||
|
scrapeDocument(document: Document): ScrapeResult {
|
||||||
|
let result = new ScrapeResult(this.name);
|
||||||
|
let post = new ScrapedPost();
|
||||||
|
post.source = document.location.href;
|
||||||
|
|
||||||
|
// Set image url
|
||||||
|
const previewElements = document.getElementsByClassName("preview");
|
||||||
|
if (previewElements.length > 0) {
|
||||||
|
post.imageUrl = (previewElements[0] as HTMLAnchorElement).href;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set rating
|
||||||
|
post.rating = "safe";
|
||||||
|
|
||||||
|
// Set tags
|
||||||
|
const tagElements = Array.from(document.getElementById("tags")!.children);
|
||||||
|
|
||||||
|
for (const tagElement of tagElements) {
|
||||||
|
// Get tag name from url, because some longer tags are shortened.
|
||||||
|
// Eg. "Tate no Yuusha no Nariagari" -> "Tate no Yuusha no Nariaga..."
|
||||||
|
// (ironically this is longer, but you get the idea)
|
||||||
|
const tagUrl = (tagElement.children[0] as HTMLAnchorElement).pathname.substr(1);
|
||||||
|
const tagName = decodeURIComponent(tagUrl.replace(/\+/g, '_')).toLowerCase();
|
||||||
|
|
||||||
|
let tagType = "";
|
||||||
|
if (tagElement.childNodes.length > 1 && tagElement.childNodes[1].textContent)
|
||||||
|
tagType = tagElement.childNodes[1].textContent.trim().toLowerCase();
|
||||||
|
|
||||||
|
let category: TagCategory | undefined;
|
||||||
|
switch (tagType) {
|
||||||
|
case "game":
|
||||||
|
case "series":
|
||||||
|
category = "copyright";
|
||||||
|
break;
|
||||||
|
case "character":
|
||||||
|
category = "character";
|
||||||
|
break;
|
||||||
|
case "mangaka":
|
||||||
|
category = "artist";
|
||||||
|
break;
|
||||||
|
case "source":
|
||||||
|
// Skip these type of tags, because they are not 'booru-like'
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tagName) {
|
||||||
|
let tag = new ScrapedTag(tagName, category);
|
||||||
|
post.tags.push(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (post.imageUrl) {
|
||||||
|
result.posts.push(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,3 +5,4 @@ export { default as Moebooru } from "./Moebooru";
|
||||||
export { default as Reddit } from "./Reddit";
|
export { default as Reddit } from "./Reddit";
|
||||||
export { default as Shimmie2 } from "./Shimmie2";
|
export { default as Shimmie2 } from "./Shimmie2";
|
||||||
export { default as Twitter } from "./Twitter";
|
export { default as Twitter } from "./Twitter";
|
||||||
|
export { default as Zerochan } from "./Zerochan";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue