Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1454 xenforo batch post dl #1524

Merged
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
108 changes: 108 additions & 0 deletions plugin/js/parsers/XenforoBatchParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"use strict";
parserFactory.registerManualSelect(
"Xenforo Batch Post Parser",
function() { return new XenforoBatchParser() }
);

class XenforoBatchParser extends Parser{
constructor() {
super();
this.cache = new FetchCache();
this.subParser = null;
}

getSubParser(dom)
{
if (!this.subParser)
{
this.subParser = parserFactory.fetchByUrl(dom.baseURI);
this.minimumThrottle = this.subParser.minimumThrottle;
}
return this.subParser;
}

// returns promise with the URLs of the chapters to fetch
// promise is used because may need to fetch the list of URLs from internet
async getChapterUrls(dom) {
let pagingUriComponent = "page-";
let baseURI = null;
let pageCount = 1;
{
let lastPage = dom.querySelector("div.pageNav li:last-child a");
baseURI = lastPage.baseURI;
let pageRegexResult = /\d+\/?$/.exec(lastPage.href);
if (pageRegexResult)
{
pageCount = parseInt(pageRegexResult[0]);
}
pagingUriComponent = new RegExp(baseURI+"(.*?)\\d+/?$").exec(lastPage.href)[1] ?? pagingUriComponent;
}
let chapters = [...Array(pageCount).keys()].map(index => {
var link = dom.createElement("a");
link.setAttribute("href", `${baseURI}${pagingUriComponent}${index}`); //ChangeMe!
link.appendChild(dom.createTextNode(`Page ${index + 1}`));
return link;
});

return chapters.map(a => util.hyperLinkToChapter(a));
}

async fetchChapter(url) {
let fetchedDom = await this.cache.fetch(url);
let newDoc = Parser.makeEmptyDocForContent(url);
[... fetchedDom.querySelectorAll("article.message")].forEach(parent => {
let author = parent.dataset["author"];
let postIdElement = parent.querySelector("header.message-attribution ul.message-attribution-opposite li:last-child a");
let title = "";

let chapterBody = parent.querySelector("article.message-body");
let titleElement = parent.querySelector("span.threadmarkLabel");
if (titleElement)
{
title = titleElement.textContent.trim();
}
else
{
title = postIdElement.textContent;
let possibleTitle = chapterBody.querySelector("div.bbWrapper").firstChild.textContent;
if (possibleTitle.length < 100) //prevent overly-long titles
{
title = `${title}: ${possibleTitle}`;
}
}
title = `${title} — ${author}`;
titleElement = newDoc.dom.createElement("h1");
titleElement.textContent = title;
newDoc.content.appendChild(titleElement);
util.resolveLazyLoadedImages(chapterBody, "img.lazyload");
newDoc.content.appendChild(chapterBody);
});
return newDoc.dom;
}

clampSimultanousFetchSize() {
return this.subParser.clampSimultanousFetchSize();
}

isLinkToChapter(link) {
return this.subParser.isLinkToChapter(link);
}

findContent(dom) {
return this.getSubParser(dom).findContent(dom);
};

extractTitleImpl(dom) {
return this.getSubParser(dom).extractTitleImpl(dom);
};

extractAuthor(dom) {
return this.getSubParser(dom).extractAuthor(dom);
};

//addTitleToChapter(newDoc, parent) {}

getInformationEpubItemChildNodes(dom) {
return this.getSubParser(dom).getInformationEpubItemChildNodes(dom);
}
}
1 change: 1 addition & 0 deletions plugin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ <h3>Instructions</h3>
<script src="js/parsers/WuxiaworldParser.js"></script>
<script src="js/parsers/WuxiaworldWorldParser.js"></script>
<script src="js/parsers/XbiqugeParser.js"></script>
<script src="js/parsers/XenforoBatchParser.js"></script>
<script src="js/parsers/ZenithNovelsParser.js"></script>
<script src="js/parsers/ZeonicrepublicParser.js"></script>
<script src="js/parsers/ZhenhunxiaoshuoParser.js"></script>
Expand Down
Loading