Skip to content

Commit

Permalink
Rawlazy : fix getting pages
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeZeDev committed Nov 22, 2024
1 parent 35729b9 commit 14f8823
Showing 1 changed file with 3 additions and 54 deletions.
57 changes: 3 additions & 54 deletions web/src/engine/websites/RawLazy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Tags } from '../Tags';
import icon from './RawLazy.webp';
import { type Chapter, DecoratableMangaScraper, Manga, Page, type MangaPlugin, type MangaScraper } from '../providers/MangaPlugin';
import { DecoratableMangaScraper, Manga, type MangaPlugin, type MangaScraper } from '../providers/MangaPlugin';
import * as Common from './decorators/Common';
import { FetchCSS, FetchJSON, FetchWindowScript } from '../platform/FetchProvider';
import { FetchJSON, FetchWindowScript } from '../platform/FetchProvider';

function MangaLabelExtractor(element: HTMLElement) {
const text = element instanceof HTMLAnchorElement ? element.text : element.textContent.split('|')[0].trim();
Expand All @@ -20,29 +20,9 @@ type APIResult = {
mes: string;
}

const IframeScript = `
new Promise( (resolve, reject) => {
const interval = setInterval(function () {
try {
if (document.querySelector('#idIframe')) {
clearInterval(interval);
resolve(document.querySelector('#idIframe').src);
}
} catch (error) {
clearInterval(interval);
reject(error);
}
}, 1000);
AbortSignal.timeout(10_000).onabort = function({ target: { reason } }) {
clearInterval(interval);
reject(reason);
};
})
`;

@Common.MangaCSS(/^{origin}\/manga-lazy\/[^/]+\/$/, 'title', MangaLabelExtractor)
@Common.ChaptersSinglePageCSS('div.chapters-list a', ChapterExtractor)
@Common.PagesSinglePageCSS('.chapter_popup img')
@Common.ImageAjax(true)
export default class extends DecoratableMangaScraper {

Expand Down Expand Up @@ -88,35 +68,4 @@ export default class extends DecoratableMangaScraper {
const links = [...dom.querySelectorAll<HTMLAnchorElement>('div.entry-tag h2 a')];
return links.map(link => new Manga(this, provider, link.pathname, MangaLabelExtractor.call(this, link)));
}

public override async FetchPages(chapter: Chapter): Promise<Page[]> {
const chapterUrl = new URL(chapter.Identifier, this.URI).href;
let currentUrl = await FetchWindowScript<string>(new Request(chapterUrl), this.Script('.go-to-B'), 1500);
currentUrl = await FetchWindowScript<string>(new Request(currentUrl), IframeScript, 1500);
const pages = await FetchCSS<HTMLImageElement>(new Request(currentUrl), 'div.z_content img');
return pages.map(image => new Page(this, chapter, new URL(image.src)));
}

private Script(selector: string): string {
return `
new Promise( (resolve, reject) => {
const interval = setInterval(function () {
try {
if (document.querySelector('${selector}')?.href != '#') {
clearInterval(interval);
resolve(document.querySelector('${selector}').href);
}
} catch (error) {
clearInterval(interval);
reject(error);
}
}, 1000);
AbortSignal.timeout(10_000).onabort = function({ target: { reason } }) {
clearInterval(interval);
reject(reason);
};
})
`;
}

}

0 comments on commit 14f8823

Please sign in to comment.