From 80517824b69fb66d8e9dae5e093839a2ef11dfeb Mon Sep 17 00:00:00 2001 From: Sans3108 Date: Wed, 18 Sep 2024 05:51:34 +0300 Subject: [PATCH] postponed mangadex --- package.json | 4 +- pnpm-lock.yaml | 22 +- src/scripts/background/service-worker.ts | 431 ++++------------------- src/views/options.html | 9 +- 4 files changed, 98 insertions(+), 368 deletions(-) diff --git a/package.json b/package.json index 5faf42f..adb3232 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@types/fs-extra": "^11.0.4", "@types/html-minifier-terser": "^7.0.2", "@types/node": "20.14.8", - "nodemon": "^3.1.4" + "nodemon": "^3.1.5" }, "dependencies": { "clean-css": "^5.3.3", @@ -24,7 +24,7 @@ "glob": "^10.4.5", "html-minifier-terser": "^7.2.0", "htmlparser2": "^9.1.0", - "terser": "^5.32.0", + "terser": "^5.33.0", "typescript": "^5.6.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 27f8e25..6d928b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,8 +24,8 @@ importers: specifier: ^9.1.0 version: 9.1.0 terser: - specifier: ^5.32.0 - version: 5.32.0 + specifier: ^5.33.0 + version: 5.33.0 typescript: specifier: ^5.6.2 version: 5.6.2 @@ -46,8 +46,8 @@ importers: specifier: 20.14.8 version: 20.14.8 nodemon: - specifier: ^3.1.4 - version: 3.1.4 + specifier: ^3.1.5 + version: 3.1.5 packages: @@ -317,8 +317,8 @@ packages: no-case@3.0.4: resolution: {integrity: sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==} - nodemon@3.1.4: - resolution: {integrity: sha512-wjPBbFhtpJwmIeY2yP7QF+UKzPfltVGtfce1g/bB15/8vCGZj8uxD62b/b9M9/WVgme0NZudpownKN+c0plXlQ==} + nodemon@3.1.5: + resolution: {integrity: sha512-V5UtfYc7hjFD4SI3EzD5TR8ChAHEZ+Ns7Z5fBk8fAbTVAj+q3G+w7sHJrHxXBkVn6ApLVTljau8wfHwqmGUjMw==} engines: {node: '>=10'} hasBin: true @@ -406,8 +406,8 @@ packages: resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==} engines: {node: '>=4'} - terser@5.32.0: - resolution: {integrity: sha512-v3Gtw3IzpBJ0ugkxEX8U0W6+TnPKRRCWGh1jC/iM/e3Ki5+qvO1L1EAZ56bZasc64aXHwRHNIQEzm6//i5cemQ==} + terser@5.33.0: + resolution: {integrity: sha512-JuPVaB7s1gdFKPKTelwUyRq5Sid2A3Gko2S0PncwdBq7kN9Ti9HPWDQ06MPsEDGsZeVESjKEnyGy68quBk1w6g==} engines: {node: '>=10'} hasBin: true @@ -674,7 +674,7 @@ snapshots: entities: 4.5.0 param-case: 3.0.4 relateurl: 0.2.7 - terser: 5.32.0 + terser: 5.33.0 htmlparser2@9.1.0: dependencies: @@ -736,7 +736,7 @@ snapshots: lower-case: 2.0.2 tslib: 2.7.0 - nodemon@3.1.4: + nodemon@3.1.5: dependencies: chokidar: 3.6.0 debug: 4.3.7(supports-color@5.5.0) @@ -825,7 +825,7 @@ snapshots: dependencies: has-flag: 3.0.0 - terser@5.32.0: + terser@5.33.0: dependencies: '@jridgewell/source-map': 0.3.6 acorn: 8.12.1 diff --git a/src/scripts/background/service-worker.ts b/src/scripts/background/service-worker.ts index 0d99f6d..08164c9 100644 --- a/src/scripts/background/service-worker.ts +++ b/src/scripts/background/service-worker.ts @@ -356,7 +356,7 @@ class ProviderManager { } const url = await provider.handle(data, preferences, preferredTitle).catch(e => { - console.log(`AW: ERROR`, e); + console.log(`AW: ProviderManager#handle ERROR`, e); return null; }); @@ -401,6 +401,20 @@ function getTheme(): Promise<'light' | 'dark' | null> { }); }); } + +function getMalTitle(data: MediaData, preferences: UserPreferences, fallback: string | null): string | null { + const order = preferences.langOrder!.split(''); + + const titles = [ + { lang: 'n', title: data.idMal ? data.malData?.alternative_titles?.ja : null }, + { lang: 'r', title: data.idMal ? data.malData?.title : null }, + { lang: 'e', title: data.idMal ? data.malData?.alternative_titles?.en : null } + ].map(t => (t.title === '' ? { lang: t.lang, title: null } : t)); + + titles.sort((a, b) => order.indexOf(a.lang) - order.indexOf(b.lang)); + + return titles.find(t => t.title !== null && t.title !== undefined)?.title || fallback; +} //#endregion //#region Providers @@ -422,7 +436,7 @@ class HianimeProvider extends BaseProvider { if (!direct) return searchUrl; const rawHtml = await getRawHtml(searchUrl).catch(e => { - console.log(`AW: ERROR`, e); + console.log(`AW: HianimeProvider#handle ERROR`, e); return null; }); @@ -451,117 +465,79 @@ class HianimeProvider extends BaseProvider { endpoint.searchParams.set('keyword', preferredTitle); - const typeMap: Record = { + //#region Type + const typeMapAnilist: Record = { TV: 2, - TV_SHORT: 2, // non-existent, TV fallback + TV_SHORT: null, MOVIE: 1, SPECIAL: 5, OVA: 3, ONA: 4, MUSIC: 6, - MANGA: 2, // non-existent, TV fallback - NOVEL: 2, // non-existent, TV fallback - ONE_SHOT: null // non-existent, no fallback + MANGA: null, + NOVEL: null, + ONE_SHOT: null }; - const type = data.format ? typeMap[data.format] : null; - + const type = data.format ? typeMapAnilist[data.format] : null; if (type) endpoint.searchParams.set('type', type.toString()); + //#endregion - const statusMap: Record = { + //#region Status + const statusMapAnilist: Record = { FINISHED: 1, RELEASING: 2, NOT_YET_RELEASED: 3, - CANCELLED: null, // non-existent, no fallback - HIATUS: null // non-existent, no fallback + CANCELLED: null, + HIATUS: null }; - const status = data.status ? statusMap[data.status] : null; - + const status = data.status ? statusMapAnilist[data.status] : null; if (status) endpoint.searchParams.set('status', status.toString()); + //#endregion - const seasonMap: Record = { + //#region Season + const seasonMapAnilist: Record = { WINTER: 4, SPRING: 1, SUMMER: 2, FALL: 3 }; - const season = data.season ? seasonMap[data.season] : null; + const season = data.season ? seasonMapAnilist[data.season] : null; if (season) endpoint.searchParams.set('season', season.toString()); + //#endregion + //#region Season Year if (data.seasonYear) endpoint.searchParams.set('sy', data.seasonYear.toString()); + //#endregion if (Boolean(preferences.withGenres)) { console.log('AW: Appending genres...'); - const genreMap: Record = { - Action: 1, - Adventure: 2, - Comedy: 4, - Drama: 8, - Ecchi: 9, - Fantasy: 10, - Horror: 14, - 'Mahou Shoujo': null, - Mecha: 18, - Music: 19, - Mystery: null, - Psychological: 40, - Romance: 22, - 'Sci-Fi': 24, - 'Slice of Life': 36, - Sports: 30, - Supernatural: 37, - Thriller: 41 - }; - - // const Hianime_genre_ids = [ - // 1, // Action - // 2, // Adventure - // 3, // Cars - // 4, // Comedy - // 5, // Dementia - // 6, // Demons - // 8, // Drama - // 9, // Ecchi - // 10, // Fantasy - // 11, // Game - // 35, // Harem - // 13, // Historical - // 14, // Horror - // 44, // Isekai - // 43, // Josei - // 15, // Kids - // 16, // Magic - // 17, // Martial Arts - // 18, // Mecha - // 38, // Military - // 19, // Music - // 7, // Mistery - // 20, // Parody - // 39, // Police - // 40, // Psychological - // 22, // Romance - // 21, // Samurai - // 23, // School - // 24, // Sci-Fi - // 42, // Seinen - // 26, // Shoujo - // 25, // Shouko Ai - // 27, // Shounen - // 28, // Shounen Ai - // 36, // Slice of Life - // 29, // Space - // 30, // Sports - // 31, // Super Power - // 37, // Supernatural - // 41, // Thriller - // 32 // Vampire - // ]; - if (data.genres) { + const genreMap: Record = { + Action: 1, + Adventure: 2, + Comedy: 4, + Drama: 8, + Ecchi: 9, + Fantasy: 10, + Horror: 14, + Mecha: 18, + Music: 19, + Psychological: 40, + Romance: 22, + 'Sci-Fi': 24, + 'Slice of Life': 36, + Sports: 30, + Supernatural: 37, + Mystery: null, + 'Mahou Shoujo': null, + Thriller: 41 + }; + const genreIds: string[] = []; for (const g of data.genres) { @@ -681,7 +657,7 @@ class AnitakuProvider extends BaseProvider { if (!direct) return searchUrl; const rawHtml = await getRawHtml(searchUrl).catch(e => { - console.log(`AW: ERROR`, e); + console.log(`AW: AnitakuProvider#handle ERROR`, e); return null; }); @@ -704,17 +680,7 @@ class AnitakuProvider extends BaseProvider { } public getSearchUrl(data: MediaData, preferences: UserPreferences, preferredTitle: string | null): string { - const order = preferences.langOrder!.split(''); - - const titles = [ - { lang: 'n', title: data.idMal ? data.malData?.alternative_titles?.ja : null }, - { lang: 'r', title: data.idMal ? data.malData?.title : null }, - { lang: 'e', title: data.idMal ? data.malData?.alternative_titles?.en : null } - ].map(t => (t.title === '' ? { lang: t.lang, title: null } : t)); - - titles.sort((a, b) => order.indexOf(a.lang) - order.indexOf(b.lang)); - - const title = titles.find(t => t.title !== null && t.title !== undefined)?.title || preferredTitle; + const title = getMalTitle(data, preferences, preferredTitle); if (!title) throw new Error(`Could not compute title!`); @@ -977,7 +943,6 @@ class AnitakuProvider extends BaseProvider { } } -// Possibly based on mal data class MangafireProvider extends BaseProvider { public readonly usesMal = true; public readonly type = 'manga'; @@ -996,7 +961,7 @@ class MangafireProvider extends BaseProvider { if (!direct) return searchUrl; const rawHtml = await getRawHtml(searchUrl).catch(e => { - console.log(`AW: ERROR`, e); + console.log(`AW: MangafireProvider#handle ERROR`, e); return null; }); @@ -1019,20 +984,8 @@ class MangafireProvider extends BaseProvider { } public getSearchUrl(data: MediaData, preferences: UserPreferences, preferredTitle: string | null): string { - const order = preferences.langOrder!.split(''); - - const titles = [ - { lang: 'n', title: data.idMal ? data.malData?.alternative_titles?.ja : null }, - { lang: 'r', title: data.idMal ? data.malData?.title : null }, - { lang: 'e', title: data.idMal ? data.malData?.alternative_titles?.en : null } - ].map(t => (t.title === '' ? { lang: t.lang, title: null } : t)); - - titles.sort((a, b) => order.indexOf(a.lang) - order.indexOf(b.lang)); - - const title = titles.find(t => t.title !== null && t.title !== undefined)?.title || preferredTitle; - + const title = getMalTitle(data, preferences, preferredTitle); if (!title) throw new Error(`Could not compute title!`); - console.log(`AW: ${this.id} title: ${title}`); const endpoint = new URL('https://mangafire.to/filter'); @@ -1231,253 +1184,24 @@ class MangafireProvider extends BaseProvider { } } -class MangareaderProvider extends BaseProvider { - public readonly usesMal = false; - public readonly type = 'manga'; - public readonly id = 'mangareader'; - public readonly displayName = 'MangaReader'; - - public readonly baseColor = '#6a5488'; - - public readonly parsingTarget = null; - - public async handle(data: MediaData, preferences: UserPreferences, preferredTitle: string | null): Promise { - return 'https://mangareader.to'; - } - - public getSearchUrl(data: MediaData, preferences: UserPreferences, preferredTitle: string | null): string { - const order = preferences.langOrder!.split(''); - - const titles = [ - { lang: 'n', title: data.idMal ? data.malData?.alternative_titles?.ja : null }, - { lang: 'r', title: data.idMal ? data.malData?.title : null }, - { lang: 'e', title: data.idMal ? data.malData?.alternative_titles?.en : null } - ].map(t => (t.title === '' ? { lang: t.lang, title: null } : t)); - - titles.sort((a, b) => order.indexOf(a.lang) - order.indexOf(b.lang)); - - const title = titles.find(t => t.title !== null && t.title !== undefined)?.title || preferredTitle; - - if (!title) throw new Error(`Could not compute title!`); - - console.log(`AW: ${this.id} title: ${title}`); - - const endpoint = new URL('https://mangareader.to/filter'); - - endpoint.searchParams.set('keyword', title); - - const typeMap: Record = { - unknown: null, - manga: 1, - novel: 4, - one_shot: 2, - doujinshi: 3, - manhwa: 5, - manhua: 6, - oel: null - }; - - const typeMapAnilist: Record = { - TV: null, - TV_SHORT: null, - MOVIE: null, - SPECIAL: null, - OVA: null, - ONA: null, - MUSIC: null, - MANGA: 1, - NOVEL: 4, - ONE_SHOT: 2 - }; - - const type = data.malData ? typeMap[data.malData.media_type as FormatMalManga] : data.format ? typeMapAnilist[data.format] : null; - if (type) endpoint.searchParams.set('type', type.toString()); - - const statusMap: Record = { - finished: 1, - currently_publishing: 2, - not_yet_published: 5 - }; - - const statusMapAnilist: Record = { - FINISHED: 1, - RELEASING: 2, - NOT_YET_RELEASED: 5, - CANCELLED: 4, - HIATUS: 3 - }; - - const status = data.malData ? statusMap[data.malData.status as StatusMalManga] : data.status ? statusMapAnilist[data.status] : null; - if (status) endpoint.searchParams.set('status', status.toString()); +// class MangadexProvider extends BaseProvider { +// public readonly usesMal = false; +// public readonly type = 'manga'; +// public readonly id = 'mangadex'; +// public readonly displayName = 'MangaDex'; - // go from here dumbass +// public readonly baseColor = '#9b3e26'; - function pickDecade(year: number): string | null { - const decades = ['2000s', '1990s', '1980s', '1970s', '1960s', '1950s', '1940s', '1930s']; - - if (year >= 2004) return year.toString(); - - return decades.find(decade => decade.startsWith(`${Math.floor(year / 10) * 10}s`)) || null; - } - - if (data.malData && data.malData.start_date) { - const startYear = parseInt(data.malData.start_date.slice(0, 4)); - - if (!isNaN(startYear)) { - const year = pickDecade(startYear); - if (year) endpoint.searchParams.set('year[]', year); - } - } else if (data.seasonYear) { - const year = pickDecade(data.seasonYear); - if (year) endpoint.searchParams.set('year[]', year); - } else if (data.startDate && data.startDate.year) { - endpoint.searchParams.set('year[]', data.startDate.year.toString()); - } +// public readonly parsingTarget = null; - if (Boolean(preferences.withGenres)) { - console.log('AW: Appending genres...'); +// public async handle(data: MediaData, preferences: UserPreferences, preferredTitle: string | null): Promise { +// return 'https://mangadex.org'; +// } - const genreMap: Record = { - Action: 1, - Adventure: 78, - 'Avant Garde': 3, - 'Boys Love': 4, - Comedy: 5, - Drama: 6, - Ecchi: 7, - Fantasy: 79, - 'Girls Love': 9, - Gourmet: 10, - Harem: 11, - Horror: 530, - Isekai: 13, - Iyashikei: 531, - Josei: 15, - Kids: 532, - 'Mahou Shoujo': 533, - 'Martial Arts': 534, - Mecha: 19, - Military: 535, - Music: 21, - Mystery: 22, - Parody: 23, - Psychological: 536, - 'Reverse Harem': 25, - Romance: 26, - School: 73, - 'Sci-Fi': 28, - Seinen: 537, - Shoujo: 30, - Shounen: 31, - 'Slice of Life': 538, - Space: 33, - Sports: 34, - 'Super Power': 75, - Supernatural: 76, - Suspense: 37, - Vampire: 39, - Racing: null, - Mythology: null, - 'Strategy Game': null, - Hentai: null, - Historical: null, - Samurai: null, - Detective: null, - Crossdressing: null, - 'Award Winning': null, - Workplace: null, - Erotica: null, - 'Adult Cast': null, - Anthropomorphic: null, - CGDCT: null, - Childcare: null, - 'Combat Sports': null, - Delinquents: null, - Educational: null, - 'Gag Humor': null, - Gore: null, - 'High Stakes Game': null, - 'Idols (Female)': null, - 'Idols (Male)': null, - 'Love Polygon': null, - 'Magical Sex Shift': null, - Medical: null, - Memoir: null, - 'Organized Crime': null, - 'Otaku Culture': null, - 'Performing Arts': null, - Pets: null, - Reincarnation: null, - 'Romantic Subtext': null, - Showbiz: null, - Survival: null, - 'Team Sports': null, - 'Time Travel': null, - 'Video Game': null, - Villainess: null, - 'Visual Arts': null - }; - - const genreMapAnilist: Record = { - Action: 1, - Adventure: 78, - Comedy: 5, - Drama: 6, - Ecchi: 7, - Fantasy: 79, - Horror: 530, - 'Mahou Shoujo': 533, - Mecha: 19, - Music: 21, - Mystery: 22, - Psychological: 536, - Romance: 26, - 'Sci-Fi': 28, - 'Slice of Life': 538, - Sports: 34, - Supernatural: 76, - Thriller: null - }; - - if (data.malData) { - for (const g of data.malData.genres) { - const genreName = g.name as keyof typeof GenreMalManga; - - const id = genreMap[genreName]; - - if (id) endpoint.searchParams.append('genre[]', id.toString()); - } - } else if (data.genres) { - for (const g of data.genres) { - const id = genreMapAnilist[g]; - - if (id) endpoint.searchParams.append('genre[]', id.toString()); - } - } - } - - return endpoint.toString(); - } -} - -class MangadexProvider extends BaseProvider { - public readonly usesMal = false; - public readonly type = 'manga'; - public readonly id = 'mangadex'; - public readonly displayName = 'MangaDex'; - - public readonly baseColor = '#9b3e26'; - - public readonly parsingTarget = null; - - public async handle(data: MediaData, preferences: UserPreferences, preferredTitle: string | null): Promise { - return 'https://mangadex.org'; - } - - public getSearchUrl(data: MediaData, preferences: UserPreferences, preferredTitle: string | null): string { - return 'https://mangadex.org'; - } -} +// public getSearchUrl(data: MediaData, preferences: UserPreferences, preferredTitle: string | null): string { +// return 'https://mangadex.org'; +// } +// } //#endregion @@ -1486,8 +1210,7 @@ const manager = new ProviderManager().register( new HianimeProvider(), // anime new AnitakuProvider(), // anime new MangafireProvider(), // manga, default - new MangadexProvider(), // manga - new MangareaderProvider() // manga + // new MangadexProvider(), // manga ); // Runs on extension install, browser version update, extension version update @@ -1556,7 +1279,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { const title = titles.find(t => t.title !== null && t.title !== undefined)?.title || null; const mediaUrl = await manager.handle(data, url[3], preferences, title).catch(e => { - console.log(`AW: ERROR`, e); + console.log(`AW: manager.handle ERROR`, e); return null; }); diff --git a/src/views/options.html b/src/views/options.html index 934afc0..e910a31 100644 --- a/src/views/options.html +++ b/src/views/options.html @@ -120,9 +120,16 @@

Reset options to default

+
+

Providers Info

+
+

Version 8.0.0

-

If you have questions or concerns direct them to my Discord DM's: sans._.

+

+ If you have questions or concerns direct them to my Discord DM's: sans._. or submit a feature request + here. +