Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit af95515

Browse files
authored
Merge pull request #8 from TheBritishAccent/master
Add fuzzy search to Catmanga
2 parents 3ea8415 + d9d8f53 commit af95515

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

plugins/catmanga/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ function listChapters(query) {
4141
// We have to do it manually since Catmanga has no searching.
4242
var manga;
4343
allSeries.forEach(function(element) {
44-
if (query.toLowerCase() == element["title"].toLowerCase() ||
45-
query.toLowerCase() == element["series_id"].toLowerCase()) {
44+
if (fuzzySearch(query, element["title"]) || fuzzySearch(query, element["series_id"])) {
4645
manga = element;
4746
} else {
4847
element["alt_titles"].forEach(function(title) {
49-
if (title.toLowerCase() == query.toLowerCase()) {
48+
if (fuzzySearch(query, title)) {
5049
manga = element;
5150
}
5251
});
@@ -65,8 +64,8 @@ function listChapters(query) {
6564

6665
var chapters = [];
6766
manga["chapters"].forEach(function(chapter) {
68-
var seriesID = manga["series_id"];
69-
var chapterNum = chapter["number"].toString().replace(/\./, "_");
67+
var seriesID = manga["series_id"].replace(/\-/, "_");
68+
var chapterNum = chapter["number"].toString().replace(/\./, "d");
7069
var chapterGroups = chapter["groups"].join(", ")
7170

7271
var slimObj = {};
@@ -85,9 +84,9 @@ function listChapters(query) {
8584

8685
function selectChapter(id) {
8786
// Get buildID for chapter
88-
var mangaIDMatch = /(.*?)ch((\d_?)*)$/.exec(id);
89-
var mangaID = mangaIDMatch[1];
90-
var mangaChapterNumber = mangaIDMatch[2].replace(/\_/, "."); // Convert '_' back to '.
87+
var mangaIDMatch = /(.*?)ch((\dd?)*)$/.exec(id);
88+
var mangaID = mangaIDMatch[1].replace(/\_/, "-"); // Convert '_' back to '-'
89+
var mangaChapterNumber = mangaIDMatch[2].replace(/d/, "."); // Convert chxx(d)xx back to '.'
9190

9291
var chapterReaderURL = ROOT_URL + "series/" + mangaID + "/" + mangaChapterNumber;
9392
var chapterHTML = mango.get(chapterReaderURL).body;
@@ -151,6 +150,12 @@ function nextPage() {
151150
});
152151
}
153152

153+
function fuzzySearch(query, trueString) {
154+
return trueString.toLowerCase()
155+
.indexOf(query.toLowerCase()) !== -1;
156+
}
157+
158+
154159
// https://stackoverflow.com/a/10073788
155160
function pad(n, width, z) {
156161
z = z || '0';

0 commit comments

Comments
 (0)