Skip to content

Commit

Permalink
Only single copy of FanFiction chapters.
Browse files Browse the repository at this point in the history
resolves #135
  • Loading branch information
dteviot committed Sep 16, 2017
1 parent 30f312f commit 6887a0a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plugin/js/parsers/FanFictionParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ class FanFictionParser extends Parser {
// no list of chapters found, assume it's a single chapter story
return Promise.resolve(that.singleChapterStory(baseUrl, dom));
} else {
return Promise.resolve(options.map(option => that.optionToChapterInfo(baseUrl, option)));
let foundUrls = new Set();
let isUnique = function(chapterInfo) {
let unique = !foundUrls.has(chapterInfo.sourceUrl);
if (unique) {
foundUrls.add(chapterInfo.sourceUrl);
}
return unique;
}

return Promise.resolve(
options.map(option => that.optionToChapterInfo(baseUrl, option))
.filter(isUnique)
);
}
}

Expand Down
7 changes: 7 additions & 0 deletions testdata/FanFiction.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
<p>If you're like me, you will have...</p>
</div>
</div>
<span style="float:right; "><select id="chap_select" title="Chapter Navigation" name="chapter" onchange="self.location = &#39;/s/1234567/&#39;+ this.options[this.selectedIndex].value + &#39;/WebToEpub&#39;;">
<option value="1" selected="">1. Introduction</option>
<option value="2">2. Using the Code or "How to load an Extension into Chrome"</option>
<option value="3">3. Basics of Building a Chrome extension</option>
<option value="4">4. How to read the HTML of a web page on a Chrome tab.</option>
<option value="5">5. Using Chrome's &quot;Inspect Element&quot; to examine the DOM</option>
</select></span>
</div>
</div>
</div>
Expand Down

0 comments on commit 6887a0a

Please sign in to comment.