From 9ca5c9fb6c231a6527029393eec32f3fbe33cea1 Mon Sep 17 00:00:00 2001 From: David Smith Date: Mon, 22 May 2017 00:53:46 -0500 Subject: [PATCH] Get more reliable elements when searching for the threadmark lists. 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). --- .../Input/Forums/Adapters/XenForoAdapter.cs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/NetTally.Core/Input/Forums/Adapters/XenForoAdapter.cs b/NetTally.Core/Input/Forums/Adapters/XenForoAdapter.cs index 85420c06..3f3cfc3d 100644 --- a/NetTally.Core/Input/Forums/Adapters/XenForoAdapter.cs +++ b/NetTally.Core/Input/Forums/Adapters/XenForoAdapter.cs @@ -453,25 +453,31 @@ static IEnumerable 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 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 nodeSelector = (n) => n.Element("a"); + // Return empty list if no threadmark ul or ol found. + if (mainList == null) + return new List(); - Func> childSelector = (i) => i.Element("ul")?.Elements("li") ?? i.Element("ol")?.Elements("li") ?? new List(); - var results = list.Elements("li").TraverseList(childSelector, nodeSelector, filterLambda); + Predicate filterLambda = (n) => + (quest.UseCustomThreadmarkFilters && quest.ThreadmarkFilter.Match(n.InnerText)) || + (!quest.UseCustomThreadmarkFilters && DefaultThreadmarkFilter.Match(n.InnerText)); - return results; - } + Func nodeSelector = (n) => n.Element("a"); + + Func> childSelector = (i) => i.Element("ul")?.Elements("li") ?? new List(); + + var results = mainList.Elements("li").TraverseList(childSelector, nodeSelector, filterLambda); + + return results; } catch (ArgumentNullException e) {