Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions plugin/js/parsers/LumosStoriesParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@

"use strict";

parserFactory.register("lumostories.com", () => new LumosStoriesParer());
parserFactory.register("api.lumostories.com", () => new LumosStoriesParer());


class LumosStoriesParer extends Parser {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed it right now, but it looks like I misspelled 'Parser' in this. I will do a quick commit to change this.

constructor() {
super();
this.minimumThrottle = 3000;
}

/**
*
* @returns {"https://api.lumostories.com/api/v1"}
*/
getApiBaseUrl() {
return "https://api.lumostories.com/api/v1";
}

/**
* @param {HTMLDocument} dom
* @returns {String}
*/
getBookId(dom) {
//https://lumostories.com/en/story/216/chapters/
if (dom.baseURI.endsWith("/chapters/") || dom.baseURI.endsWith("/chapters")) {
let uriArray = dom.baseURI.split("/").filter(Boolean);
let id = uriArray[uriArray.length - 2];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is length - 2 going to work? That assumes there's a trailing '/' when not there, needs to be - 1

Should probably add '/' if not there, then run e.g.

let url = dom.baseURI;
if (!url.endsWith("/") {
    url += "/"
}
 if (dom.baseURI.endsWith("/chapters/"))
...etc
```

Actually, can simplify this and the case of https://lumostories.com/en/story/216/

Whole function can be
````javascript
getBookId(dom) {
    return  dom.baseURI.split("/")[5];
}
```


return id;
}
// https://lumostories.com/en/story/216/
let uriArray = dom.baseURI.split("/").filter(Boolean);
let id = uriArray[uriArray.length - 1];

return id;
}

/**
* @param {HTMLDocument} dom
*/
async getChapterUrls(dom) {
let id = this.getBookId(dom);
let book = (await HttpClient.fetchJson(`${this.getApiBaseUrl()}/books/${id}`)).json;

return book.chapters.map((ch) => ({
sourceUrl: `${this.getApiBaseUrl()}/book_chapters/${ch.id}/content?title=${ch.title}`,
title: `Chapter ${ch.number} - ${ch.title}`,
newArc: null,
isIncludeable: new Date() >= new Date(ch.release_date)
})).reverse();
}

/**
* @param {HTMLDocument} dom
*/
async loadEpubMetaInfo(dom) {
let id = this.getBookId(dom);
let book = (await HttpClient.fetchJson(`${this.getApiBaseUrl()}/books/${id}`)).json;
this.title = book.name;
this.author = book.author.username;
this.description = book.summary?.trim();
this.subject = book.tags.map((tag) => tag.name).join(", ");
return;
}

extractTitleImpl() {
return this.title;
}

extractAuthor() {
return this.author;
}

extractDescription() {
return this.description;
}

/**
* @param {HTMLDocument} dom
*/
findContent(dom) {
return dom.querySelector("body");
}

/**
* @param {HTMLDocument} dom
*/
findCoverImageUrl(dom) {
let title = dom.querySelector("h1").textContent ?? "";
let img = dom.querySelector(`img[alt="${title}"]`);

return img?.src ?? null;
}

/**
* @param {String} url
*/
async fetchChapter(url) {
let search = new URLSearchParams(new URL(url).search);
let chapterUrl = (await HttpClient.fetchText(url.replace(/\?.*$/, ""))).replaceAll("\"", "");
/** @type {HTMLDocument} */
let html = (await HttpClient.wrapFetch(chapterUrl)).responseXML;

let title = search.get("title");

if (title) {
let body = html.querySelector("body");

let h1 = html?.createElement("h1");

h1.textContent = title;
body.prepend(h1);
}


return html;
}

isCustomError(response) {
const hasError = response?.responseXML.querySelector("error");

if (!hasError) return false;

return true;
}

setCustomErrorResponse(url, wrapOptions, checkedresponse) {
if (!checkedresponse?.ok) {
let newresp = {};
newresp.url = url;
newresp.wrapOptions = wrapOptions;
newresp.response = {};
newresp.response.url = checkedresponse.response.url;
newresp.response.status = checkedresponse?.status;
return newresp;
}
}

}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ <h3>Instructions</h3>
<script src="js/parsers/LnmtlParser.js"></script>
<script src="js/parsers/LoreNovelsParser.js"></script>
<script src="js/parsers/LunoxscansParser.js"></script>
<script src="js/parsers/LumosStoriesParser.js"></script>
<script src="js/parsers/MachineTranslationParser.js"></script>
<script src="js/parsers/MadnovelParser.js"></script>
<script src="js/parsers/MagicWizardsParser.js"></script>
Expand Down
Loading