Skip to content

Commit

Permalink
Update FanFictionParser.js
Browse files Browse the repository at this point in the history
Fix for loading inconsistent caching issue on ff.net

Update FanFictionParser.js

Removed shortUri double-negate; code will run functionally equivalent.
  • Loading branch information
Kiradien committed Nov 23, 2023
1 parent b1200d2 commit 3c24485
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions plugin/js/parsers/FanFictionParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ class FanFictionParser extends Parser {
return dom;
}

async fetchWebPageContent(webPage)
{
try
{
return await super.fetchWebPageContent(webPage);
}
catch(ex)
{
//Determine if path contains extra parameters. Immediately fail if already shortened.
//Shortened URI is not always ideal solution; apparently related to caching on server.
let regex = /(https?:\/\/(?:www\.)?\w+\.\w+\/s\/\d+\/\d+)\/[a-z\-0-9]+/i
let shortUri = regex.exec(webPage.sourceUrl);
if (shortUri)
{
console.log(`Failed to load URI [${webPage.sourceUrl}] - Attempting alternative. [${shortUri[1]}]`);
//Await throttle timer again for second page fetch.
await this.rateLimitDelay();
webPage.sourceUrl = shortUri[1];
return await super.fetchWebPageContent(webPage);
}
else
{
throw ex;
}
}
}

addTitleToChapter(url, dom) {
let path = url.split("/");
let chapterId = path[path.length - 2];
Expand Down

0 comments on commit 3c24485

Please sign in to comment.