mirror of
https://github.com/kodjodevf/mangayomi-extensions.git
synced 2026-02-14 10:51:17 +00:00
extension(mangafire): Added view manga as volume
This commit is contained in:
@@ -6,30 +6,35 @@ const mangayomiSources = [{
|
||||
"iconUrl": "https://mangafire.to/assets/sites/mangafire/favicon.png?v3",
|
||||
"typeSource": "single",
|
||||
"itemType": 0,
|
||||
"version": "0.1.22",
|
||||
"version": "0.1.23",
|
||||
"dateFormat": "",
|
||||
"dateFormatLocale": "",
|
||||
"pkgPath": "manga/src/all/mangafire.js"
|
||||
}];
|
||||
|
||||
class DefaultExtension extends MProvider {
|
||||
|
||||
getPreference(key) {
|
||||
return new SharedPreferences().get(key);
|
||||
}
|
||||
|
||||
mangaListFromPage(res) {
|
||||
const doc = new Document(res.body);
|
||||
const elements = doc.select("div.unit");
|
||||
const list = [];
|
||||
|
||||
for (const element of elements){
|
||||
const name = element.selectFirst("div.info > a").text;
|
||||
const imageUrl = element.selectFirst("img").getSrc;
|
||||
const link = element.selectFirst("a").getHref;
|
||||
list.push({name, imageUrl, link});
|
||||
for (const element of elements) {
|
||||
const name = element.selectFirst("div.info > a").text;
|
||||
const imageUrl = element.selectFirst("img").getSrc;
|
||||
const link = element.selectFirst("a").getHref;
|
||||
list.push({ name, imageUrl, link });
|
||||
}
|
||||
|
||||
const hasNextPage = doc.selectFirst("li.page-item.active + li").text != "";
|
||||
return { "list": list, "hasNextPage": hasNextPage };
|
||||
}
|
||||
|
||||
statusFromString(status){
|
||||
statusFromString(status) {
|
||||
return {
|
||||
"Releasing": 0,
|
||||
"Completed": 1,
|
||||
@@ -41,14 +46,14 @@ class DefaultExtension extends MProvider {
|
||||
|
||||
parseDate(date) {
|
||||
const months = {
|
||||
"jan": "01", "feb": "02", "mar": "03", "apr": "04", "may": "05", "jun": "06", "jul": "07", "aug": "08", "sep": "09", "oct": "10", "nov": "11", "dec": "12"
|
||||
"jan": "01", "feb": "02", "mar": "03", "apr": "04", "may": "05", "jun": "06", "jul": "07", "aug": "08", "sep": "09", "oct": "10", "nov": "11", "dec": "12"
|
||||
};
|
||||
date = date.toLowerCase().replace(",", "").split(" ");
|
||||
|
||||
if (!(date[0] in months)) {
|
||||
return String(new Date().valueOf())
|
||||
}
|
||||
|
||||
|
||||
date[0] = months[date[0]];
|
||||
date = [date[2], date[0], date[1]];
|
||||
date = date.join("-");
|
||||
@@ -104,7 +109,7 @@ class DefaultExtension extends MProvider {
|
||||
}
|
||||
|
||||
async getDetail(url) {
|
||||
// get urls
|
||||
const viewType = this.getPreference("mangafire_pref_content_view")
|
||||
const id = url.split(".").pop();
|
||||
const detail = {};
|
||||
|
||||
@@ -126,30 +131,39 @@ class DefaultExtension extends MProvider {
|
||||
|
||||
// get chapter
|
||||
// /read/ is needed to get chapter details
|
||||
const chapterUrl = this.source.baseUrl + `/ajax/read/${id}/chapter/${this.source.lang}`;
|
||||
const chapterUrl = this.source.baseUrl + `/ajax/read/${id}/${viewType}/${this.source.lang}`;
|
||||
const idRes = await new Client().get(chapterUrl);
|
||||
const idDoc = new Document(JSON.parse(idRes.body).result.html);
|
||||
const ids = idDoc.select("a");
|
||||
// /manga/ is needed to get chapter dateUpload
|
||||
const chapRes = await new Client().get(this.source.baseUrl + `/ajax/manga/${id}/chapter/${this.source.lang}`);
|
||||
const chapDoc = new Document(JSON.parse(chapRes.body).result);
|
||||
const chapElements = chapDoc.selectFirst(".scroll-sm").children;
|
||||
|
||||
var chapElements = null
|
||||
if (viewType == "chapter") { // upload date is not present in volumes
|
||||
// /manga/ is needed to get chapter upload date
|
||||
const chapRes = await new Client().get(this.source.baseUrl + `/ajax/manga/${id}/${viewType}/${this.source.lang}`);
|
||||
const chapDoc = new Document(JSON.parse(chapRes.body).result);
|
||||
chapElements = chapDoc.selectFirst(".scroll-sm").children;
|
||||
}
|
||||
detail.chapters = [];
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const name = ids[i].text;
|
||||
const id = ids[i].attr("data-id");
|
||||
var title = ids[i].attr("title").split(" - ");
|
||||
var scanlator = title.length > 1 ? title[0] : "Vol 1"
|
||||
const id = ids[i]
|
||||
const name = id.text;
|
||||
const mangaId = id.attr("data-id");
|
||||
|
||||
const url = this.source.baseUrl + `/ajax/read/chapter/${id}`;
|
||||
let dateUpload;
|
||||
try {
|
||||
dateUpload = this.parseDate(chapElements[i].selectFirst("span + span").text);
|
||||
} catch (_) {
|
||||
dateUpload = null
|
||||
var scanlator = null
|
||||
var dateUpload = null;
|
||||
if (viewType == "chapter") { // upload date is not present in volumes
|
||||
const chapElement = chapElements[i]
|
||||
var title = chapElement.selectFirst("a").attr("title").split(" - ");
|
||||
scanlator = title.length > 1 ? title[0] : "Vol 1"
|
||||
try {
|
||||
dateUpload = this.parseDate(chapElement.selectFirst("span + span").text);
|
||||
} catch (_) {
|
||||
dateUpload = null
|
||||
}
|
||||
}
|
||||
|
||||
detail.chapters.push({ name, url, dateUpload,scanlator });
|
||||
const url = this.source.baseUrl + `/ajax/read/${viewType}/${mangaId}`;
|
||||
detail.chapters.push({ name, url, dateUpload, scanlator });
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
@@ -268,6 +282,15 @@ class DefaultExtension extends MProvider {
|
||||
}
|
||||
|
||||
getSourcePreferences() {
|
||||
throw new Error("getSourcePreferences not implemented");
|
||||
return [{
|
||||
key: 'mangafire_pref_content_view',
|
||||
listPreference: {
|
||||
title: 'View manga as',
|
||||
summary: '',
|
||||
valueIndex: 0,
|
||||
entries: ["Chapters", "Volumes"],
|
||||
entryValues: ["chapter", "volume"]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user