Skip to content

Commit

Permalink
Merge pull request #1524 from Kiradien/#1454-Xenforo_Batch_Post_DL
Browse files Browse the repository at this point in the history
#1454 xenforo batch post dl
  • Loading branch information
Kiradien authored Sep 28, 2024
2 parents 54bf253 + 492f6d6 commit ad728f3
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
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

0 comments on commit ad728f3

Please sign in to comment.