fix(mangakakalot): exclude banner ads and non-CDN images from chapter pages#143
Open
malaquiasdev wants to merge 1 commit into
Open
fix(mangakakalot): exclude banner ads and non-CDN images from chapter pages#143malaquiasdev wants to merge 1 commit into
malaquiasdev wants to merge 1 commit into
Conversation
… pages Adds isMangaPageImage predicate that rejects images from the mangakakalot.gg host, the /images/bns/ banner namespace, or with a .gif extension. Page numbers are renumbered sequentially after filtering. Closes #102.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Adds a pure predicate
isMangaPageImage(url)tosrc/integrations/mangakakalot/client/parser.tsand wires it intoparseChapterImages. The parser now rejects images by three rules:.giffile extensionmangakakalot.gg/www.mangakakalot.gghost (real pages come from external CDN like*.2xstorage.com)/images/bns/path segment (banner namespace)After filtering,
pageis renumbered sequentially starting at1so there are no gaps.Why it exists
P0 bug (#102). Real-session log showed every mangakakalot CBZ contained at least one banner ad as a "page":
{"event":"mangakakalot.image_fetch","url":"https://www.mangakakalot.gg/images/bns/common/ehentaiai.gif"}Root cause:
$(SELECTORS.chapterReaderImage).each(...)pulled every<img>inside.container-chapter-readerand used the loop index as the page number, with no URL filter. Affected 100% of CBZs produced via the mangakakalot fallback today.How it works internally
isMangaPageImage(url: string): booleannear the bottom ofparser.ts. Pure, exported for unit testing. Usesnew URL(url)to extract host + pathname; URLs that fail to parse are rejected (safer default).parseChapterImagesbuilds the result array via apageNumcounter that only increments after the predicate passes — sequential renumbering is real, not a side-effect of the loop index.tests/fixtures/mangakakalot/chapter-with-banners.html: 4 real*.2xstorage.compage imgs interleaved with 3 banners (one for each rejection rule). Test asserts exactly 4 results with pages[1,2,3,4].What did not change
fetchChapterImagesHTTP code untouched — parser-only fix.mangadexandfallback-httpintegrations untouched.chapter-naruto-1.htmland its test path remain valid.Test checklist
bun test— 436 pass, 0 failbun run typecheck— cleanbun run check— cleanchapter-with-banners.htmlfixture asserts banner exclusion + sequential renumbering[1,2,3,4]chapter-naruto-1.html(3 pages,[1,2,3])Reviewer notes
QA flagged two P1 test gaps (non-blocking, behavior is correct; tests just don't document it):
.GIF— regex/\.gif(?:[?#].*)?$/iis already case-insensitive, but no test pins the flag..gifburied inside a query string (e.g.?src=banner.gif) — current regex anchors on pathname, so this is not rejected by extension rule. Host or path rule may still catch it. Worth deciding whether to harden.Inspector flagged two P2 forward risks (not bugs in this fix):
data-srcURLs would throw insidenew URL(rawUrl)and be silently dropped.new URL(rawUrl, chapterUrl)would survive a future DOM change.SITE_HOSTSis an exact-matchSet—s3.mangakakalot.gg-style subdomains wouldn't be caught. A regex/(^|\.)mangakakalot\.gg$/iwould be more defensive but is scope creep relative to fix(mangakakalot): chapter parser includes banner ads as pages in CBZ #102.Both items intentionally left for follow-up.
Closes
Closes #102
✅ Checklist
docs/(not applicable — bug fix, no behavior surface change)