Skip to content

Commit

Permalink
HeavenManga: minor code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeZeDev committed Jan 11, 2025
1 parent 962dc99 commit 7830626
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
35 changes: 15 additions & 20 deletions web/src/engine/websites/HeavenManga2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,22 @@ import * as Common from './decorators/Common';
import { FetchJSON } from '../platform/FetchProvider';

function MangaInfoExtractor(element: HTMLAnchorElement) {
const id = element.pathname;
const title = element.querySelector('img').alt.trim();
return { id, title };
return {
id: element.pathname,
title: element.querySelector('img').alt.trim()
};
}

type APIChapter = {
data: {
slug: string
id : number
}[]
id: number
}[]
}

const scriptPages = `
new Promise((resolve, reject) => {
try {
resolve(window.pUrl.map(page => page.imgURL));
} catch (error) {
reject(error);
}
});
`;
const scriptPages = `window.pUrl.map(page => page.imgURL);`;

@Common.MangaCSS(/^{origin}\//, 'div.site-content div.post-title h3')
@Common.MangaCSS(/^{origin}\/manga\/[^/]+$/, 'div.site-content div.post-title h3')
@Common.MangasMultiPageCSS('/top?page={page}', 'div.page-item-detail div.photo a.thumbnail', 1, 1, 0, MangaInfoExtractor)
@Common.PagesSinglePageJS(scriptPages, 500)
@Common.ImageAjax()
Expand All @@ -42,10 +35,12 @@ export default class extends DecoratableMangaScraper {
}

public override async FetchChapters(manga: Manga): Promise<Chapter[]> {
const url = new URL(manga.Identifier, this.URI);
const request = new Request(url.href);
request.headers.set('X-Requested-With', 'XMLHttpRequest');
const data = await FetchJSON<APIChapter>(request);
return data.data.map(page => new Chapter(this, manga, '/manga/leer/' + page.id, "Chapter " + page.slug));
const request = new Request(new URL(manga.Identifier, this.URI), {
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
});
const { data } = await FetchJSON<APIChapter>(request);
return data.map(page => new Chapter(this, manga, `/manga/leer/${page.id}`, `Chapter ${page.slug}`));
}
}
8 changes: 3 additions & 5 deletions web/src/engine/websites/HeavenManga2_e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestFixture, type Config } from '../../../test/WebsitesFixture';
import { TestFixture } from '../../../test/WebsitesFixture';

const config: Config = {
new TestFixture({
plugin: {
id: 'heavenmanga2',
title: 'HeavenManga'
Expand All @@ -19,6 +19,4 @@ const config: Config = {
size: 1_055_197,
type: 'image/jpeg'
}
};

new TestFixture(config).AssertWebsite();
}).AssertWebsite();

0 comments on commit 7830626

Please sign in to comment.