updates and new extensions
This commit is contained in:
240
book/comix.js
240
book/comix.js
@@ -3,7 +3,7 @@ class Comix {
|
||||
this.baseUrl = "https://comix.to";
|
||||
this.apiUrl = "https://comix.to/api/v2";
|
||||
this.type = "book-board";
|
||||
this.version = "1.0";
|
||||
this.version = "1.1";
|
||||
this.mediaType = "manga";
|
||||
}
|
||||
|
||||
@@ -14,18 +14,212 @@ class Comix {
|
||||
};
|
||||
}
|
||||
|
||||
getFilters() {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const years = [];
|
||||
for (let i = currentYear; i >= 1990; i--) {
|
||||
years.push({ value: i.toString(), label: i.toString() });
|
||||
}
|
||||
years.push({ value: "older", label: "Older" });
|
||||
|
||||
return {
|
||||
sort: {
|
||||
label: "Sort By",
|
||||
type: "select",
|
||||
options: [
|
||||
{ value: "relevance", label: "Best Match" },
|
||||
{ value: "views_30d", label: "Popular (30 days)" },
|
||||
{ value: "views_total", label: "Total Views" },
|
||||
{ value: "chapter_updated_at", label: "Latest Updates" },
|
||||
{ value: "created_at", label: "Created Date" },
|
||||
{ value: "title", label: "Title" },
|
||||
{ value: "year", label: "Year" },
|
||||
{ value: "follows_total", label: "Most Follows" }
|
||||
],
|
||||
default: "views_30d"
|
||||
},
|
||||
status: {
|
||||
label: "Status",
|
||||
type: "multiselect",
|
||||
options: [
|
||||
{ value: "finished", label: "Finished" },
|
||||
{ value: "releasing", label: "Releasing" },
|
||||
{ value: "on_hiatus", label: "On Hiatus" },
|
||||
{ value: "discontinued", label: "Discontinued" },
|
||||
{ value: "not_yet_released", label: "Not Yet Released" }
|
||||
]
|
||||
},
|
||||
type: {
|
||||
label: "Type",
|
||||
type: "multiselect",
|
||||
options: [
|
||||
{ value: "manga", label: "Manga" },
|
||||
{ value: "manhwa", label: "Manhwa" },
|
||||
{ value: "manhua", label: "Manhua" },
|
||||
{ value: "other", label: "Other" }
|
||||
]
|
||||
},
|
||||
demographic: {
|
||||
label: "Demographic",
|
||||
type: "multiselect",
|
||||
options: [
|
||||
{ value: "1", label: "Shoujo" },
|
||||
{ value: "2", label: "Shounen" },
|
||||
{ value: "3", label: "Josei" },
|
||||
{ value: "4", label: "Seinen" }
|
||||
]
|
||||
},
|
||||
genre: {
|
||||
label: "Genres",
|
||||
type: "multiselect",
|
||||
options: [
|
||||
{ value: "6", label: "Action" },
|
||||
{ value: "87264", label: "Adult" },
|
||||
{ value: "7", label: "Adventure" },
|
||||
{ value: "8", label: "Boys Love" },
|
||||
{ value: "9", label: "Comedy" },
|
||||
{ value: "10", label: "Crime" },
|
||||
{ value: "11", label: "Drama" },
|
||||
{ value: "87265", label: "Ecchi" },
|
||||
{ value: "12", label: "Fantasy" },
|
||||
{ value: "13", label: "Girls Love" },
|
||||
{ value: "87266", label: "Hentai" },
|
||||
{ value: "14", label: "Historical" },
|
||||
{ value: "15", label: "Horror" },
|
||||
{ value: "16", label: "Isekai" },
|
||||
{ value: "17", label: "Magical Girls" },
|
||||
{ value: "87267", label: "Mature" },
|
||||
{ value: "18", label: "Mecha" },
|
||||
{ value: "19", label: "Medical" },
|
||||
{ value: "20", label: "Mystery" },
|
||||
{ value: "21", label: "Philosophical" },
|
||||
{ value: "22", label: "Psychological" },
|
||||
{ value: "23", label: "Romance" },
|
||||
{ value: "24", label: "Sci-Fi" },
|
||||
{ value: "25", label: "Slice of Life" },
|
||||
{ value: "87268", label: "Smut" },
|
||||
{ value: "26", label: "Sports" },
|
||||
{ value: "27", label: "Superhero" },
|
||||
{ value: "28", label: "Thriller" },
|
||||
{ value: "29", label: "Tragedy" },
|
||||
{ value: "30", label: "Wuxia" },
|
||||
{ value: "31", label: "Aliens" },
|
||||
{ value: "32", label: "Animals" },
|
||||
{ value: "33", label: "Cooking" },
|
||||
{ value: "34", label: "Cross Dressing" },
|
||||
{ value: "35", label: "Delinquents" },
|
||||
{ value: "36", label: "Demons" },
|
||||
{ value: "37", label: "Genderswap" },
|
||||
{ value: "38", label: "Ghosts" },
|
||||
{ value: "39", label: "Gyaru" },
|
||||
{ value: "40", label: "Harem" },
|
||||
{ value: "41", label: "Incest" },
|
||||
{ value: "42", label: "Loli" },
|
||||
{ value: "43", label: "Mafia" },
|
||||
{ value: "44", label: "Magic" },
|
||||
{ value: "45", label: "Martial Arts" },
|
||||
{ value: "46", label: "Military" },
|
||||
{ value: "47", label: "Monster Girls" },
|
||||
{ value: "48", label: "Monsters" },
|
||||
{ value: "49", label: "Music" },
|
||||
{ value: "50", label: "Ninja" },
|
||||
{ value: "51", label: "Office Workers" },
|
||||
{ value: "52", label: "Police" },
|
||||
{ value: "53", label: "Post-Apocalyptic" },
|
||||
{ value: "54", label: "Reincarnation" },
|
||||
{ value: "55", label: "Reverse Harem" },
|
||||
{ value: "56", label: "Samurai" },
|
||||
{ value: "57", label: "School Life" },
|
||||
{ value: "58", label: "Shota" },
|
||||
{ value: "59", label: "Supernatural" },
|
||||
{ value: "60", label: "Survival" },
|
||||
{ value: "61", label: "Time Travel" },
|
||||
{ value: "62", label: "Traditional Games" },
|
||||
{ value: "63", label: "Vampires" },
|
||||
{ value: "64", label: "Video Games" },
|
||||
{ value: "65", label: "Villainess" },
|
||||
{ value: "66", label: "Virtual Reality" },
|
||||
{ value: "67", label: "Zombies" }
|
||||
]
|
||||
},
|
||||
year_from: {
|
||||
label: "Year From",
|
||||
type: "select",
|
||||
options: [{ value: "", label: "Any" }, ...years]
|
||||
},
|
||||
year_to: {
|
||||
label: "Year To",
|
||||
type: "select",
|
||||
options: [{ value: "", label: "Any" }, ...years]
|
||||
},
|
||||
min_chap: {
|
||||
label: "Min. Chapters",
|
||||
type: "number",
|
||||
placeholder: "e.g. 10"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async search(queryObj) {
|
||||
const q = (queryObj.query || "").trim().replace(/\s+/g, "+");
|
||||
|
||||
const { query, filters, page } = queryObj;
|
||||
const q = (query || "").trim().replace(/\s+/g, "+");
|
||||
const pageNum = page || 1;
|
||||
|
||||
const url = new URL(`${this.apiUrl}/manga`);
|
||||
|
||||
let sortMode = "views_30d";
|
||||
|
||||
if (filters) {
|
||||
|
||||
if (filters.sort) {
|
||||
sortMode = filters.sort;
|
||||
}
|
||||
|
||||
if (filters.genre) {
|
||||
const genres = String(filters.genre).split(',');
|
||||
genres.forEach(g => {
|
||||
if (g.trim()) url.searchParams.append("genres[]", g.trim());
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.status) {
|
||||
const statuses = String(filters.status).split(',');
|
||||
statuses.forEach(s => {
|
||||
if (s.trim()) url.searchParams.append("statuses[]", s.trim());
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.type) {
|
||||
const types = String(filters.type).split(',');
|
||||
types.forEach(t => {
|
||||
if (t.trim()) url.searchParams.append("types[]", t.trim());
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.demographic) {
|
||||
const demos = String(filters.demographic).split(',');
|
||||
demos.forEach(d => {
|
||||
if (d.trim()) url.searchParams.append("demographics[]", d.trim());
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.year_from) url.searchParams.set("release_year[from]", filters.year_from);
|
||||
if (filters.year_to) url.searchParams.set("release_year[to]", filters.year_to);
|
||||
if (filters.min_chap) url.searchParams.set("min_chap", filters.min_chap);
|
||||
}
|
||||
|
||||
if (q) {
|
||||
url.searchParams.set("keyword", q);
|
||||
url.searchParams.set("order[relevance]", "desc");
|
||||
} else {
|
||||
url.searchParams.set("order[views_30d]", "desc");
|
||||
|
||||
sortMode = "relevance";
|
||||
}
|
||||
|
||||
const orderDirection = (sortMode === "title") ? "asc" : "desc";
|
||||
url.searchParams.set(`order[${sortMode}]`, orderDirection);
|
||||
|
||||
url.searchParams.set("limit", "50");
|
||||
url.searchParams.set("page", "1");
|
||||
url.searchParams.set("page", pageNum.toString());
|
||||
|
||||
const res = await fetch(url, { headers: this.headers });
|
||||
if (!res.ok) throw new Error(`Search failed: ${res.status}`);
|
||||
@@ -37,12 +231,15 @@ class Comix {
|
||||
title: m.title,
|
||||
image: m.poster?.large || null,
|
||||
rating: m.score ?? null,
|
||||
type: "book"
|
||||
type: "book",
|
||||
|
||||
year: m.year || null,
|
||||
status: m.status || null
|
||||
}));
|
||||
}
|
||||
|
||||
async getMetadata(id) {
|
||||
const url = `${this.apiUrl}/manga/${id}?includes[]=genre&includes[]=author&includes[]=artist`;
|
||||
const url = `${this.apiUrl}/manga/${id}?includes[]=genre&includes[]=author&includes[]=artist&includes[]=demographic`;
|
||||
|
||||
const res = await fetch(url, { headers: this.headers });
|
||||
if (!res.ok) throw new Error(`Metadata failed: ${res.status}`);
|
||||
@@ -99,12 +296,13 @@ class Comix {
|
||||
if (ch.language !== "en") continue;
|
||||
|
||||
const key = ch.number;
|
||||
|
||||
if (!map.has(key) || ch.is_official === 1) {
|
||||
map.set(key, ch);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(map.values())
|
||||
const chapters = Array.from(map.values())
|
||||
.sort((a, b) => a.number - b.number)
|
||||
.map((ch, i) => ({
|
||||
id: `${mangaId}|${slug}|${ch.chapter_id}|${ch.number}`,
|
||||
@@ -115,33 +313,27 @@ class Comix {
|
||||
releaseDate: ch.updated_at ?? null,
|
||||
index: i
|
||||
}));
|
||||
|
||||
return chapters;
|
||||
}
|
||||
|
||||
async findChapterPages(chapterId) {
|
||||
const parts = chapterId.split("|");
|
||||
console.log(parts)
|
||||
if (parts.length < 4) return [];
|
||||
|
||||
const [hashId, slug, chapterRealId, number] = parts;
|
||||
|
||||
const readerUrl = `${this.baseUrl}/title/${hashId}-${slug}/${chapterRealId}-chapter-${number}`;
|
||||
|
||||
const res = await fetch(readerUrl, { headers: this.headers });
|
||||
const apiUrl = `${this.apiUrl}/chapters/${chapterRealId}`;
|
||||
|
||||
const res = await fetch(apiUrl, { headers: this.headers });
|
||||
if (!res.ok) return [];
|
||||
|
||||
const html = await res.text();
|
||||
const json = await res.json();
|
||||
if (!json.result || !json.result.images) return [];
|
||||
|
||||
const regex = /["\\]*images["\\]*\s*:\s*(\[[^\]]*\])/s;
|
||||
const match = html.match(regex);
|
||||
if (!match?.[1]) return [];
|
||||
|
||||
let images;
|
||||
try {
|
||||
images = JSON.parse(match[1]);
|
||||
} catch {
|
||||
images = JSON.parse(match[1].replace(/\\"/g, '"'));
|
||||
}
|
||||
|
||||
return images.map((img, i) => ({
|
||||
return json.result.images.map((img, i) => ({
|
||||
url: img.url,
|
||||
index: i,
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user