From 99b75150cc10f5de45c1822dcc236e998058e4e2 Mon Sep 17 00:00:00 2001 From: NatsuDzn Date: Thu, 31 Mar 2022 20:33:50 +0200 Subject: [PATCH 1/2] [TASK] Replace Japanread by Bentomanga --- src/pages/{Japanread => Bentomanga}/main.ts | 66 +++++++++------------ src/pages/Bentomanga/meta.json | 6 ++ src/pages/Bentomanga/style.less | 33 +++++++++++ src/pages/Bentomanga/tests.json | 30 ++++++++++ src/pages/Japanread/meta.json | 6 -- src/pages/Japanread/style.less | 42 ------------- src/pages/Japanread/tests.json | 30 ---------- src/pages/pages.ts | 4 +- 8 files changed, 98 insertions(+), 119 deletions(-) rename src/pages/{Japanread => Bentomanga}/main.ts (52%) create mode 100644 src/pages/Bentomanga/meta.json create mode 100644 src/pages/Bentomanga/style.less create mode 100644 src/pages/Bentomanga/tests.json delete mode 100644 src/pages/Japanread/meta.json delete mode 100644 src/pages/Japanread/style.less delete mode 100644 src/pages/Japanread/tests.json diff --git a/src/pages/Japanread/main.ts b/src/pages/Bentomanga/main.ts similarity index 52% rename from src/pages/Japanread/main.ts rename to src/pages/Bentomanga/main.ts index 5fbe65ecb4..91eff13236 100644 --- a/src/pages/Japanread/main.ts +++ b/src/pages/Bentomanga/main.ts @@ -1,8 +1,8 @@ import { pageInterface } from '../pageInterface'; -export const Japanread: pageInterface = { - name: 'Japanread', - domain: 'https://www.japanread.cc/', +export const Bentomanga: pageInterface = { + name: 'Bentomanga', + domain: 'https://www.bentomanga.com', languages: ['French'], type: 'manga', isSyncPage(url) { @@ -15,11 +15,14 @@ export const Japanread: pageInterface = { getIdentifier(url) { return utils.urlPart(url, 4); }, - getOverviewUrl(url) { - return url.substr(0, url.lastIndexOf('/')); + getOverviewUrl() { + return utils.absoluteLink( + j.$('.reader-controls-title > div > a').attr('href'), + Bentomanga.domain, + ); }, getEpisode(url) { - return parseInt(utils.urlPart(url, 5)); + return parseInt(utils.urlPart(url, 6)); }, getVolume() { const currentChapter = j.$('#jump-chapter option:selected'); @@ -37,54 +40,31 @@ export const Japanread: pageInterface = { } return 0; }, - nextEpUrl(url) { - const nextChapter = j.$('#jump-chapter option:selected').prev(); - - if (nextChapter && typeof nextChapter !== 'undefined') { - let temp = nextChapter - .text() - .trim() - .match(/(ch\.|chapitre)\D?\d+/i); - if (temp !== null) { - temp = temp[0].replace('.', '-').match(/\d+/); - if (temp !== null) { - return utils.absoluteLink(temp[0], Japanread.sync.getOverviewUrl(url)); - } - } - } - return ''; - }, }, overview: { getTitle() { - return j.$('h1.card-header').text().trim(); + return j.$('.component-manga-title_main > h1').text().trim(); }, getIdentifier(url) { return utils.urlPart(url, 4); }, uiSelector(selector) { - j.$('.card.card-manga .card-body .row.edit .col-md-7') - .first() - .append( - j.html( - '
MAL-Sync:
', - ), - ); - j.$('.container .card .mal-sync').first().append(j.html(selector)); + j.$('.datas').after( + j.html( + `

MAL-Sync

${selector}
`, + ), + ); }, list: { offsetHandler: false, elementsSelector() { - return j.$('[data-row=chapter]'); + return j.$('[data-chapter]'); }, elementUrl(selector) { - if (j.$('#navbar-guest').length === 0) { - return utils.absoluteLink(selector.find('a').eq(1).attr('href'), Japanread.domain); - } - return utils.absoluteLink(selector.find('a').first().attr('href'), Japanread.domain); + return utils.absoluteLink(selector.find('a.text-truncate').attr('href'), Bentomanga.domain); }, elementEp(selector) { - return Japanread.sync.getEpisode(Japanread.overview!.list!.elementUrl!(selector)); + return Bentomanga.sync.getEpisode(Bentomanga.overview!.list!.elementUrl!(selector)); }, }, }, @@ -98,7 +78,7 @@ export const Japanread: pageInterface = { utils.waitUntilTrue( () => { return ( - j.$('#jump-chapter option:selected').text() !== '' || j.$('[data-row=chapter]').length + j.$('#jump-chapter option:selected').text() !== '' || j.$('.div-chapters').length ); }, () => { @@ -108,5 +88,13 @@ export const Japanread: pageInterface = { ); } }); + utils.changeDetect( + () => { + page.handleList(); + }, + () => { + return j.$('[data-chapter]').length; + }, + ); }, }; diff --git a/src/pages/Bentomanga/meta.json b/src/pages/Bentomanga/meta.json new file mode 100644 index 0000000000..2770e10045 --- /dev/null +++ b/src/pages/Bentomanga/meta.json @@ -0,0 +1,6 @@ +{ + "search": "https://www.bentomanga.com/manga_list?search={searchterm}", + "urls": { + "match": ["*://www.bentomanga.com/*", "*://bentomanga.com/*"] + } +} diff --git a/src/pages/Bentomanga/style.less b/src/pages/Bentomanga/style.less new file mode 100644 index 0000000000..3919df7577 --- /dev/null +++ b/src/pages/Bentomanga/style.less @@ -0,0 +1,33 @@ +@import './../pages'; + +#malp { + * { + color: white; + } +} + +@media only screen and (max-width: 850px) { + #malp { + .MalLogin { + width: 100%; + } + } +} + +#MalData { + select option { + background-color: #192229 !important; + } +} + +.mal-sync-active { + background-color: #80b133 !important; + + * { + color: white !important; + } +} + +.flash { + background-color: transparent !important; +} diff --git a/src/pages/Bentomanga/tests.json b/src/pages/Bentomanga/tests.json new file mode 100644 index 0000000000..7b738b8150 --- /dev/null +++ b/src/pages/Bentomanga/tests.json @@ -0,0 +1,30 @@ +{ + "title": "Bentomanga", + "url": "https://www.bentomanga.com/", + "testCases": [ + { + "url": "https://www.bentomanga.com/manga/ao-no-hako", + "expected": { + "sync": false, + "title": "Ao no hako", + "identifier": "ao-no-hako", + "uiSelector": true, + "epList": { + "43": "https://bentomanga.com/manga/ao-no-hako/chapter/43", + "46": "https://bentomanga.com/manga/ao-no-hako/chapter/46" + } + } + }, + { + "url": "https://www.bentomanga.com/manga/ao-no-hako/chapter/45", + "expected": { + "sync": true, + "title": "Ao no hako", + "identifier": "ao-no-hako", + "overviewUrl": "https://www.bentomanga.com/manga/ao-no-hako", + "episode": 45, + "uiSelector": false + } + } + ] +} diff --git a/src/pages/Japanread/meta.json b/src/pages/Japanread/meta.json deleted file mode 100644 index 24b828c08e..0000000000 --- a/src/pages/Japanread/meta.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "search": "https://www.japanread.cc/manga-list?q={searchterm}", - "urls": { - "match": ["*://www.japanread.cc/*"] - } -} diff --git a/src/pages/Japanread/style.less b/src/pages/Japanread/style.less deleted file mode 100644 index 2d43747e34..0000000000 --- a/src/pages/Japanread/style.less +++ /dev/null @@ -1,42 +0,0 @@ -@import './../pages'; - -@textColor: inherit; -@activeEp: #cee1ff; - -#malp { - margin: 0; - - span { - color: @textColor; - } - - select > * { - background-color: white !important; - } -} - -.strong { - font-weight: bold; -} - -@media only screen and (max-width: 1440px) { - #malp { - .MalLogin { - width: 100%; - } - } -} - -#MalData { - select option { - background-color: white !important; - } -} - -.mal-sync-active { - background-color: #82af42; - - * { - color: white !important; - } -} diff --git a/src/pages/Japanread/tests.json b/src/pages/Japanread/tests.json deleted file mode 100644 index 83aff295ba..0000000000 --- a/src/pages/Japanread/tests.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "title": "Japanread", - "url": "https://www.japanread.cc/", - "testCases": [{ - "url": "https://www.japanread.cc/manga/oshi-no-ko", - "expected": { - "sync": false, - "title": "Oshi no Ko", - "identifier": "oshi-no-ko", - "uiSelector": true, - "epList": { - "32": "https://www.japanread.cc/manga/oshi-no-ko/32", - "46": "https://www.japanread.cc/manga/oshi-no-ko/46" - } - } - }, - { - "url": "https://www.japanread.cc/manga/oshi-no-ko/45", - "expected": { - "sync": true, - "title": "Oshi no Ko", - "identifier": "oshi-no-ko", - "overviewUrl": "https://www.japanread.cc/manga/oshi-no-ko", - "nextEpUrl": "https://www.japanread.cc/manga/oshi-no-ko/46", - "episode": 45, - "uiSelector": false - } - } - ] -} \ No newline at end of file diff --git a/src/pages/pages.ts b/src/pages/pages.ts index 3c6a456d3c..a180919f7c 100644 --- a/src/pages/pages.ts +++ b/src/pages/pages.ts @@ -106,7 +106,7 @@ import { Guya } from './Guya/main'; import { MangaHub } from './MangaHub/main'; import { ComicK } from './ComicK/main'; import { AnimeShitai } from './AnimeShitai/main'; -import { Japanread } from './Japanread/main'; +import { Bentomanga } from './Bentomanga/main'; import { MangaSushi } from './MangaSushi/main'; import { ArangScans } from './ArangScans/main'; import { HunlightScans } from './HunlightScans/main'; @@ -246,7 +246,7 @@ export const pages = { MangaHub, ComicK, AnimeShitai, - Japanread, + Bentomanga, MangaSushi, ArangScans, HunlightScans, From 9098bcf238f446f6ffd828629b2edfd8ce70e8bc Mon Sep 17 00:00:00 2001 From: NatsuDzn Date: Tue, 12 Apr 2022 18:06:02 +0200 Subject: [PATCH 2/2] [TASK] Re-add Japanread --- src/pages/Japanread/main.ts | 112 +++++++++++++++++++++++++++++++++ src/pages/Japanread/meta.json | 6 ++ src/pages/Japanread/style.less | 42 +++++++++++++ src/pages/Japanread/tests.json | 31 +++++++++ src/pages/pages.ts | 2 + 5 files changed, 193 insertions(+) create mode 100644 src/pages/Japanread/main.ts create mode 100644 src/pages/Japanread/meta.json create mode 100644 src/pages/Japanread/style.less create mode 100644 src/pages/Japanread/tests.json diff --git a/src/pages/Japanread/main.ts b/src/pages/Japanread/main.ts new file mode 100644 index 0000000000..5fbe65ecb4 --- /dev/null +++ b/src/pages/Japanread/main.ts @@ -0,0 +1,112 @@ +import { pageInterface } from '../pageInterface'; + +export const Japanread: pageInterface = { + name: 'Japanread', + domain: 'https://www.japanread.cc/', + languages: ['French'], + type: 'manga', + isSyncPage(url) { + return typeof url.split('/')[5] !== 'undefined' && url.split('/')[5].length > 0; + }, + sync: { + getTitle() { + return j.$('.reader-controls-title > div > a').text().trim(); + }, + getIdentifier(url) { + return utils.urlPart(url, 4); + }, + getOverviewUrl(url) { + return url.substr(0, url.lastIndexOf('/')); + }, + getEpisode(url) { + return parseInt(utils.urlPart(url, 5)); + }, + getVolume() { + const currentChapter = j.$('#jump-chapter option:selected'); + if (currentChapter.length) { + let temp = currentChapter + .text() + .trim() + .match(/(vol\.|volume)\D?\d+/i); + if (temp !== null) { + temp = temp[0].match(/\d+/); + if (temp !== null) { + return parseInt(temp[0]); + } + } + } + return 0; + }, + nextEpUrl(url) { + const nextChapter = j.$('#jump-chapter option:selected').prev(); + + if (nextChapter && typeof nextChapter !== 'undefined') { + let temp = nextChapter + .text() + .trim() + .match(/(ch\.|chapitre)\D?\d+/i); + if (temp !== null) { + temp = temp[0].replace('.', '-').match(/\d+/); + if (temp !== null) { + return utils.absoluteLink(temp[0], Japanread.sync.getOverviewUrl(url)); + } + } + } + return ''; + }, + }, + overview: { + getTitle() { + return j.$('h1.card-header').text().trim(); + }, + getIdentifier(url) { + return utils.urlPart(url, 4); + }, + uiSelector(selector) { + j.$('.card.card-manga .card-body .row.edit .col-md-7') + .first() + .append( + j.html( + '
MAL-Sync:
', + ), + ); + j.$('.container .card .mal-sync').first().append(j.html(selector)); + }, + list: { + offsetHandler: false, + elementsSelector() { + return j.$('[data-row=chapter]'); + }, + elementUrl(selector) { + if (j.$('#navbar-guest').length === 0) { + return utils.absoluteLink(selector.find('a').eq(1).attr('href'), Japanread.domain); + } + return utils.absoluteLink(selector.find('a').first().attr('href'), Japanread.domain); + }, + elementEp(selector) { + return Japanread.sync.getEpisode(Japanread.overview!.list!.elementUrl!(selector)); + }, + }, + }, + init(page) { + api.storage.addStyle( + require('!to-string-loader!css-loader!less-loader!./style.less').toString(), + ); + j.$(document).ready(function () { + if (page.url.split('/')[3] === 'manga' && typeof page.url.split('/')[4] !== 'undefined') { + con.info('Waiting'); + utils.waitUntilTrue( + () => { + return ( + j.$('#jump-chapter option:selected').text() !== '' || j.$('[data-row=chapter]').length + ); + }, + () => { + con.info('Start'); + page.handlePage(); + }, + ); + } + }); + }, +}; diff --git a/src/pages/Japanread/meta.json b/src/pages/Japanread/meta.json new file mode 100644 index 0000000000..24b828c08e --- /dev/null +++ b/src/pages/Japanread/meta.json @@ -0,0 +1,6 @@ +{ + "search": "https://www.japanread.cc/manga-list?q={searchterm}", + "urls": { + "match": ["*://www.japanread.cc/*"] + } +} diff --git a/src/pages/Japanread/style.less b/src/pages/Japanread/style.less new file mode 100644 index 0000000000..2d43747e34 --- /dev/null +++ b/src/pages/Japanread/style.less @@ -0,0 +1,42 @@ +@import './../pages'; + +@textColor: inherit; +@activeEp: #cee1ff; + +#malp { + margin: 0; + + span { + color: @textColor; + } + + select > * { + background-color: white !important; + } +} + +.strong { + font-weight: bold; +} + +@media only screen and (max-width: 1440px) { + #malp { + .MalLogin { + width: 100%; + } + } +} + +#MalData { + select option { + background-color: white !important; + } +} + +.mal-sync-active { + background-color: #82af42; + + * { + color: white !important; + } +} diff --git a/src/pages/Japanread/tests.json b/src/pages/Japanread/tests.json new file mode 100644 index 0000000000..7c893f0a9d --- /dev/null +++ b/src/pages/Japanread/tests.json @@ -0,0 +1,31 @@ +{ + "title": "Japanread", + "url": "https://www.japanread.cc/", + "testCases": [ + { + "url": "https://www.japanread.cc/manga/oshi-no-ko", + "expected": { + "sync": false, + "title": "Oshi no Ko", + "identifier": "oshi-no-ko", + "uiSelector": true, + "epList": { + "77": "https://www.japanread.cc/manga/oshi-no-ko/77", + "65": "https://www.japanread.cc/manga/oshi-no-ko/65" + } + } + }, + { + "url": "https://www.japanread.cc/manga/oshi-no-ko/45", + "expected": { + "sync": true, + "title": "Oshi no Ko", + "identifier": "oshi-no-ko", + "overviewUrl": "https://www.japanread.cc/manga/oshi-no-ko", + "nextEpUrl": "https://www.japanread.cc/manga/oshi-no-ko/46", + "episode": 45, + "uiSelector": false + } + } + ] +} diff --git a/src/pages/pages.ts b/src/pages/pages.ts index a180919f7c..ed5763c31c 100644 --- a/src/pages/pages.ts +++ b/src/pages/pages.ts @@ -106,6 +106,7 @@ import { Guya } from './Guya/main'; import { MangaHub } from './MangaHub/main'; import { ComicK } from './ComicK/main'; import { AnimeShitai } from './AnimeShitai/main'; +import { Japanread } from './Japanread/main'; import { Bentomanga } from './Bentomanga/main'; import { MangaSushi } from './MangaSushi/main'; import { ArangScans } from './ArangScans/main'; @@ -246,6 +247,7 @@ export const pages = { MangaHub, ComicK, AnimeShitai, + Japanread, Bentomanga, MangaSushi, ArangScans,