Skip to content

Commit

Permalink
Merge pull request #1466 from gamebeaker/Add-GenesiStudioParser
Browse files Browse the repository at this point in the history
Add genesiStudio parser
  • Loading branch information
gamebeaker authored Sep 7, 2024
2 parents 9537178 + dddc160 commit 2629b39
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
85 changes: 85 additions & 0 deletions plugin/js/parsers/GenesiStudioParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Parses files on https://genesistudio.com
*/
"use strict";

parserFactory.register("genesistudio.com", () => new GenesiStudioParser());

class GenesiStudioParser extends Parser{
constructor() {
super();
this.minimumThrottle = 3000;
}

clampSimultanousFetchSize() {
return 1;
}

async getChapterUrls(dom) {
let data = (await HttpClient.fetchJson(dom.baseURI + "/__data.json")).json;
let tmpids = data.nodes[2].data[0].chapters;
tmpids = data.nodes[2].data[tmpids].free;
let freeChapterids = data.nodes[2].data[tmpids];

let returnchapters = freeChapterids.map(e => ({
sourceUrl: `https://genesistudio.com/viewer/${data.nodes[2].data[data.nodes[2].data[e].id]}`,
title: `${data.nodes[2].data[data.nodes[2].data[e].chapter_title]}`
}));
return returnchapters;
}

async fetchChapter(url) {
let apiUrl = url + "/__data.json";
let json = (await HttpClient.fetchJson(apiUrl)).json;
let newDoc = Parser.makeEmptyDocForContent(url);

this.appendElement(newDoc, "h1", this.titleFromJson(json));
this.appendContent(newDoc, json.nodes[2].data[json.nodes[2].data[0].content]);
let notes = json.nodes[2].data[json.nodes[2].data[0].footnotes];
if (notes !== null && notes != "") {
this.appendElement(newDoc, "h3", "Notes");
this.appendContent(newDoc, notes);
}
return newDoc.dom;
}

appendContent(newDoc, content) {
var div = document.createElement("div");
div.innerHTML = content;
while (div.children.length > 0) {
newDoc.content.appendChild(div.children[0]);
}
}

appendElement(newDoc, tag, text) {
let element = newDoc.dom.createElement(tag);
element.textContent = text;
newDoc.content.appendChild(element);
}

titleFromJson(json) {
let title = "";
title += util.isNullOrEmpty(json.nodes[1].data[json.nodes[1].data[1].chapter_title])
? ""
: `${json.nodes[1].data[json.nodes[1].data[1].chapter_title]}`;
return title;
}

findContent(dom) {
return Parser.findConstrutedContent(dom);
}

extractTitleImpl(dom) {
return dom.querySelector("h1");
}

findCoverImageUrl(dom) {
let imgs = dom.querySelectorAll("img");
for (let i = 0; i < imgs.length; i++) {
if (imgs[i].src.search("https://api.genesistudio.com/storage/v1/render/image/public")==0) {
return imgs[i].src;
}
}
return null;
}
}
7 changes: 7 additions & 0 deletions plugin/js/parsers/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class TemplateParser extends Parser{
*/
}

//overwrite Max web pages to fetch simultaneously mostly used on sites that block multiple requests
/*
clampSimultanousFetchSize() {
return 1;
}
*/

// returns promise with the URLs of the chapters to fetch
// promise is used because may need to fetch the list of URLs from internet
/*
Expand Down
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ <h3>Instructions</h3>
<script src="js/parsers/FreeWebNovelParser.js"></script>
<script src="js/parsers/FullnovelParser.js"></script>
<script src="js/parsers/GamefaqsGamespotParser.js"></script>
<script src="js/parsers/GenesiStudioParser.js"></script>
<script src="js/parsers/GraverobbertlParser.js"></script>
<script src="js/parsers/GravityNovelsParser.js"></script>
<script src="js/parsers/GravityTalesParser.js"></script>
Expand Down

0 comments on commit 2629b39

Please sign in to comment.