Skip to content

Commit

Permalink
Get more reliable elements when searching for the threadmark lists.
Browse files Browse the repository at this point in the history
Do better verification.
Rework the logic so that it can handle the new threadmark formatting on SV
(as of May 21, 2017), which now has an extra ol list for the tabs at the top
of the threadmark page (for different threadmark types).
  • Loading branch information
Kinematics committed May 22, 2017
1 parent 87e4f59 commit 9ca5c9f
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions NetTally.Core/Input/Forums/Adapters/XenForoAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,25 +453,31 @@ static IEnumerable<HtmlNode> GetThreadmarksList(IQuest quest, HtmlDocument page)
{
var content = GetPageContent(page, PageType.Threadmarks);

var section = content.GetDescendantWithClass("div", "section");
var threadmarksDiv = content.GetDescendantWithClass("div", "threadmarks");

// Check a few different locations for the HTML list.
var list = section.Element("ol") ?? section.Descendants("ul").FirstOrDefault() ?? section.Descendants("ol").FirstOrDefault();
HtmlNode mainList = threadmarksDiv.Elements("ol").FirstOrDefault(e => e.HasClass("threadmarkList"));

if (list != null)
if (mainList == null)
{
Predicate<HtmlNode> filterLambda = (n) =>
(quest.UseCustomThreadmarkFilters && quest.ThreadmarkFilter.Match(n.InnerText)) ||
(!quest.UseCustomThreadmarkFilters && DefaultThreadmarkFilter.Match(n.InnerText));
mainList = threadmarksDiv.Elements("ul").FirstOrDefault(e => e.Elements("li").FirstOrDefault(a => a.HasClass("threadmarkItem")) != null);
}

Func<HtmlNode, HtmlNode> nodeSelector = (n) => n.Element("a");
// Return empty list if no threadmark ul or ol found.
if (mainList == null)
return new List<HtmlNode>();

Func<HtmlNode, IEnumerable<HtmlNode>> childSelector = (i) => i.Element("ul")?.Elements("li") ?? i.Element("ol")?.Elements("li") ?? new List<HtmlNode>();

var results = list.Elements("li").TraverseList(childSelector, nodeSelector, filterLambda);
Predicate<HtmlNode> filterLambda = (n) =>
(quest.UseCustomThreadmarkFilters && quest.ThreadmarkFilter.Match(n.InnerText)) ||
(!quest.UseCustomThreadmarkFilters && DefaultThreadmarkFilter.Match(n.InnerText));

return results;
}
Func<HtmlNode, HtmlNode> nodeSelector = (n) => n.Element("a");

Func<HtmlNode, IEnumerable<HtmlNode>> childSelector = (i) => i.Element("ul")?.Elements("li") ?? new List<HtmlNode>();

var results = mainList.Elements("li").TraverseList(childSelector, nodeSelector, filterLambda);

return results;
}
catch (ArgumentNullException e)
{
Expand Down

0 comments on commit 9ca5c9f

Please sign in to comment.