This repository has been archived by the owner on Jun 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Akuqt/core
new extension (zahard) [skip ci]
- Loading branch information
Showing
13 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "zahard", | ||
"version": "1.0.0", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Chapter, Details, GetContent, Parser } from "types"; | ||
import { decodeRoute, encodeRoute } from "utils"; | ||
|
||
export const _details = (content: GetContent, parser: Parser) => { | ||
return async (route: string): Promise<Details> => { | ||
console.log(route); | ||
|
||
const url = "https://zahard.xyz/" + decodeRoute(route); | ||
const { innerHTML } = await content(url); | ||
const $ = parser(innerHTML); | ||
const genders: string[] = []; | ||
const chapters: Chapter[] = []; | ||
const base = $("body .container-fluid .row:nth-of-type(2) .col-sm-12"); | ||
const base1 = base.find(".row:first-of-type"); | ||
const base2 = base1.find(".col-sm-8 .dl-horizontal"); | ||
const title = base.find("h2.widget-title:first-of-type").text().trim(); | ||
const img = base1.find(".col-sm-4 .boxed img").attr("src")?.trim() || ""; | ||
const status = base2.find("dd:nth-of-type(2) span").text().trim(); | ||
const description = base | ||
.find(".row:nth-of-type(2) .col-lg-12 .well p") | ||
.text() | ||
.trim(); | ||
base2.find("dd a[href*=category]").each((_i, el) => { | ||
const gender = $(el).text().trim(); | ||
genders.push(gender); | ||
}); | ||
base | ||
.find(".row:nth-of-type(4) .col-lg-12 ul.chapters li h5 a") | ||
.each((_i, el) => { | ||
const ctitle = $(el).text().trim(); | ||
const id_ = $(el).attr("href")?.trim().split(".xyz/")[1] || ""; | ||
chapters.push({ | ||
title: ctitle, | ||
links: [ | ||
{ | ||
src: "zahard", | ||
id: encodeRoute(id_), | ||
}, | ||
], | ||
}); | ||
}); | ||
return { | ||
title, | ||
img, | ||
status, | ||
type: "Manga", | ||
description, | ||
genders, | ||
chapters, | ||
score: "", | ||
subtitle: "", | ||
demography: "", | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Home, GetContent, Parser, HomeBase } from "types"; | ||
import { encodeRoute } from "utils"; | ||
|
||
export const _home = (content: GetContent, parser: Parser) => { | ||
return async (): Promise<Home> => { | ||
const { innerHTML } = await content("https://zahard.xyz/manga-list"); | ||
const $ = parser(innerHTML); | ||
const popular: HomeBase[] = []; | ||
$( | ||
"body .container-fluid .row:nth-child(3) .col-sm-8 .col-sm-12 .type-content .row .content .media" | ||
).each((_i, el) => { | ||
const base = $(el).find(".media-body h5.media-heading a.chart-title"); | ||
const img = $(el).find(".media-left a img").attr("src")?.trim() || ""; | ||
const title = base.text().trim(); | ||
const route = base.attr("href")?.trim().split(".xyz/")[1] || ""; | ||
popular.push({ | ||
img, | ||
title, | ||
route: encodeRoute(route), | ||
type: "Manga", | ||
score: "", | ||
demography: "", | ||
}); | ||
}); | ||
|
||
return { | ||
popular, | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { AppContent, GetContent, Parser } from "types"; | ||
import { _details } from "./details"; | ||
import { _library } from "./library"; | ||
import { _home } from "./home"; | ||
import { _read } from "./read"; | ||
|
||
export default (getContent: GetContent, parser: Parser): AppContent => { | ||
const details = _details(getContent, parser); | ||
const library = _library(getContent, parser); | ||
const home = _home(getContent, parser); | ||
const read = _read(getContent, parser); | ||
return { | ||
name: "zahard", | ||
lang: "en", | ||
details, | ||
home, | ||
library, | ||
read, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import axios from "axios"; | ||
import { Filters, GetContent, LibItem, Library, Parser } from "types"; | ||
import { encodeRoute } from "utils"; | ||
|
||
axios.defaults.adapter = require("axios/lib/adapters/http"); | ||
|
||
const libraryParams = (_page: string, filters?: Filters) => { | ||
return `https://zahard.xyz/search?query=${filters?.title || ""}`; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const _library = (_content: GetContent, _parser: Parser) => { | ||
return async (page: string, filters?: Filters): Promise<Library> => { | ||
const items: LibItem[] = []; | ||
const res_ = await axios.get<{ | ||
suggestions: { value: string; data: string }[]; | ||
}>(libraryParams(page, filters)); | ||
const res = res_.data.suggestions; | ||
for (const sugg of res) { | ||
const title = sugg.value; | ||
const img = `https://zahard.xyz/uploads/manga/${sugg.data}/cover/cover_250x350.jpg`; | ||
const route = `manga/${sugg.data}`; | ||
items.push({ | ||
img, | ||
title, | ||
type: "Manga", | ||
route: encodeRoute(route), | ||
score: "", | ||
demography: "", | ||
}); | ||
} | ||
return { | ||
items, | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { GetContent, Parser, Read } from "types"; | ||
import { decodeRoute } from "utils"; | ||
|
||
export const _read = (content: GetContent, parser: Parser) => { | ||
return async (id: string): Promise<Read> => { | ||
console.log(id); | ||
|
||
const url = "https://zahard.xyz/" + decodeRoute(id); | ||
const { innerHTML } = await content(url, { | ||
scripts: true, | ||
action: async (page) => { | ||
await page.evaluate(async () => { | ||
await new Promise((resolve) => { | ||
let totalHeight = 0; | ||
const distance = 500; | ||
const timer = setInterval(() => { | ||
const scrollHeight = document.body.scrollHeight; | ||
window.scrollBy(0, distance); | ||
totalHeight += distance; | ||
if (totalHeight >= scrollHeight) { | ||
clearInterval(timer); | ||
resolve(true); | ||
} | ||
}, 100); | ||
}); | ||
}); | ||
}, | ||
}); | ||
const $ = parser(innerHTML); | ||
const imgs: Read["imgs"] = []; | ||
const base1 = $("body .readerMsj .container"); | ||
$("body .container-fluid .viewer-cnt .row .col-xs-12 #all img").each( | ||
(i, el) => { | ||
const url = $(el).attr("src")?.trim() || ""; | ||
imgs.push({ | ||
page: i + 1, | ||
url, | ||
free: true, | ||
}); | ||
} | ||
); | ||
const title = base1.find("h1").text().trim(); | ||
const info = base1.find("h2").text().trim(); | ||
const pages = imgs.length; | ||
const temp = imgs[0].url.split("/").reverse(); | ||
const id_ = temp[1] + temp[0].split(".")[0]; | ||
return { | ||
id: id_, | ||
title, | ||
info, | ||
pages, | ||
imgs, | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { parser, content } from "workers"; | ||
import { details_route } from "./helper"; | ||
import { _details } from "../src/details"; | ||
|
||
const details = _details(content, parser); | ||
|
||
jest.setTimeout(40000); | ||
|
||
describe("Details", () => { | ||
test("should get details", async () => { | ||
const res = await details(details_route); | ||
expect(res.chapters).toBeInstanceOf(Array); | ||
expect(res.demography).toBeDefined(); | ||
expect(res.description).toBeDefined(); | ||
expect(res.genders).toBeDefined(); | ||
expect(res.img).toBeDefined(); | ||
expect(res.score).toBeDefined(); | ||
expect(res.status).toBeDefined(); | ||
expect(res.subtitle).toBeDefined(); | ||
expect(res.title).toBeDefined(); | ||
expect(res.type).toBeDefined(); | ||
expect(res.description.length).toBeGreaterThan(0); | ||
expect(res.img.length).toBeGreaterThan(0); | ||
expect(res.status.length).toBeGreaterThan(0); | ||
expect(res.title.length).toBeGreaterThan(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const details_route = "manga=2mercenary-enrollment"; | ||
export const readId = "manga=2mercenary-enrollment=69"; | ||
export const libraryFilters = { title: "one" }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { parser, content } from "workers"; | ||
import { _home } from "../src/home"; | ||
|
||
const home = _home(content, parser); | ||
|
||
jest.setTimeout(40000); | ||
|
||
describe("Home", () => { | ||
test("should get Home page", async () => { | ||
const res = await home(); | ||
expect(res.popular).toBeInstanceOf(Array); | ||
expect(res.popular.length).toBeGreaterThan(1); | ||
expect(res.popular[0].title).toBeDefined(); | ||
expect(res.popular[0].img).toBeDefined(); | ||
expect(res.popular[0].type).toBeDefined(); | ||
expect(res.popular[0].score).toBeDefined(); | ||
expect(res.popular[0].route).toBeDefined(); | ||
expect(res.popular[0].demography).toBeDefined(); | ||
expect(res.popular[0].title.length).toBeGreaterThan(0); | ||
expect(res.popular[0].img.length).toBeGreaterThan(0); | ||
expect(res.popular[0].route.length).toBeGreaterThan(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import extension from "../src"; | ||
import { parser, content } from "workers"; | ||
|
||
const base = extension(content, parser); | ||
|
||
describe("Extension", () => { | ||
test("should be a valid extension", () => { | ||
expect(base.home).toBeInstanceOf(Function); | ||
expect(base.read).toBeInstanceOf(Function); | ||
expect(base.details).toBeInstanceOf(Function); | ||
expect(base.library).toBeInstanceOf(Function); | ||
expect(base.name).toBeDefined(); | ||
expect(base.lang).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { content, parser } from "workers"; | ||
import { libraryFilters } from "./helper"; | ||
import { _library } from "../src/library"; | ||
|
||
const library = _library(content, parser); | ||
|
||
jest.setTimeout(40000); | ||
|
||
describe("Library", () => { | ||
test.skip("should get Library page", async () => { | ||
const res = await library("1", libraryFilters); | ||
expect(res.items).toBeInstanceOf(Array); | ||
expect(res.items.length).toBeGreaterThan(1); | ||
expect(res.items[0].title).toBeDefined(); | ||
expect(res.items[0].img).toBeDefined(); | ||
expect(res.items[0].type).toBeDefined(); | ||
expect(res.items[0].score).toBeDefined(); | ||
expect(res.items[0].route).toBeDefined(); | ||
expect(res.items[0].demography).toBeDefined(); | ||
expect(res.items[0].title.length).toBeGreaterThan(0); | ||
expect(res.items[0].img.length).toBeGreaterThan(0); | ||
expect(res.items[0].route.length).toBeGreaterThan(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { content, parser } from "workers"; | ||
import { readId } from "./helper"; | ||
import { _read } from "../src/read"; | ||
|
||
const read = _read(content, parser); | ||
|
||
jest.setTimeout(40000); | ||
|
||
describe("Read", () => { | ||
test.skip("should get Read info", async () => { | ||
const res = await read(readId); | ||
expect(res.imgs).toBeInstanceOf(Array); | ||
expect(res.info).toBeDefined(); | ||
expect(res.pages).toBeDefined(); | ||
expect(res.title).toBeDefined(); | ||
expect(res.imgs.length).toBeGreaterThan(1); | ||
expect(res.info.length).toBeGreaterThan(0); | ||
expect(res.pages).toBeGreaterThan(0); | ||
expect(res.title.length).toBeGreaterThan(0); | ||
}); | ||
}); |