public async Task AddForum() { var forum = new FbItem { Id = AddPath, Name = AddName, Type = FbItemType.Forum, ShowForumColor = true }; if (!ValidateAndFixPaths(forum)) { Messenger.Default.Send <string>("Ej kompletta uppgifter (fyll i namn, och sökvägen)", FlashbackConstants.MessengerShowWarning); return; } if (ExtraForumList.Any(x => x.Id == forum.Id)) { AddName = ""; AddPath = ""; return; } ExtraForumList.Add(forum); AddName = ""; AddPath = ""; await _fileService.SaveExtraForums(ExtraForumList.ToList()); }
private async Task <ForumList> ParseMainForumlist(string result) { var document = await new HtmlParser().ParseAsync(result); var documentParsed = document.QuerySelectorAll("div.navbar-forum a.forum-title"); var forum = new List <FbItem>(); foreach (var f in documentParsed) { #if RELEASE // Detta är "förbjudet" för bajsnödiga MS if (f.TextContent.Trim() == "Droger" || f.TextContent.Trim() == "Sex") { continue; } #endif var fbForum = new FbItem() { Id = f.Attributes["href"].Value.Replace("/", ""), Name = f.TextContent, ShowForumColor = true, ShowPostCount = false }; forum.Add(fbForum); } return(new ForumList() { Items = new ObservableCollection <FbItem>(forum), Title = "Kategorier" }); }
private async Task <List <FbItem> > ParseMyQuotedPosts(string result) { var parser = new HtmlParser(); var quotedPosts = await parser.ParseAsync(result); var quotedPostsList = new List <FbItem>(); // var quotes = root.SelectNodes("/html/body/div[@id='site']/div[@id='site-content']//div[@id='site-left']/div[@id='posts']/div"); var postsCheck = quotedPosts.QuerySelectorAll("div#site-left div#posts div.post"); if (postsCheck != null) { foreach (var post in postsCheck) { var item = new FbItem() { Type = FbItemType.Thread }; var titleCheck = post.QuerySelector("div.post-body a strong"); if (titleCheck != null) { item.Name = WebUtility.HtmlDecode(titleCheck.TextContent.FixaRadbrytningar()); } //var idCheck = post.QuerySelector("div.post-body a"); var idCheck = post.QuerySelector("div.post-body div:nth-child(2) a"); if (idCheck != null) { string id = idCheck.Attributes["href"].Value; id = id.Replace("/", ""); item.Id = id; } string date = ""; var dateCheck = post.QuerySelector("div.post-heading").LastChild; if (dateCheck != null) { date = WebUtility.HtmlDecode(dateCheck.TextContent.FixaRadbrytningar()); } string username = ""; var usercheck = post.QuerySelector("div.post-body small a"); if (usercheck != null) { username = usercheck.TextContent.FixaRadbrytningar(); } item.Description = date + " - " + username; quotedPostsList.Add(item); } } return(quotedPostsList); }
private async Task <List <FbItem> > ParseSearchResult(string result) { var parser = new HtmlParser(); var quotedPosts = await parser.ParseAsync(result); var searchResult = new List <FbItem>(); Regex regex = new Regex(@"Svar: ([\d]+)"); var searchCheck = quotedPosts.QuerySelectorAll("table#threadslist tr"); if (searchCheck != null) { foreach (var searchRow in searchCheck) { var item = new FbItem() { Type = FbItemType.Thread, ShowPostCount = true }; var titleCheck = searchRow.QuerySelector("td:nth-child(2) div a"); if (titleCheck != null) { item.Name = WebUtility.HtmlDecode(titleCheck.TextContent); string id = titleCheck.Attributes["href"].Value; id = id.Replace("/", ""); item.Id = id; } else { continue; } var descriptionCheck = searchRow.QuerySelector("td:nth-child(2) a.thread-forum-title"); if (descriptionCheck != null) { item.Description = descriptionCheck.TextContent; } var countCheck = searchRow.QuerySelector("td:nth-child(4)"); if (countCheck != null) { foreach (Match match in regex.Matches(countCheck.Attributes[1].Value.FixaRadbrytningar())) { item.PostCount = int.Parse(match.Groups[1].Value); } } searchResult.Add(item); } } return(searchResult); }
private bool ValidateAndFixPaths(FbItem forum) { if (string.IsNullOrWhiteSpace(forum.Id) || string.IsNullOrWhiteSpace(forum.Name)) { return(false); } forum.Id = forum.Id.Replace("/", ""); forum.Id = forum.Id.ToLower(); return(forum.Id.Contains("f")); }
private async Task <List <FbItem> > ParseMyStartedThreads(string result) { var parser = new HtmlParser(); var threads = await parser.ParseAsync(result); var threadsCheck = threads.QuerySelectorAll("table#threadslist tr"); var resultThreads = new List <FbItem>(); if (threadsCheck != null) { foreach (var thread in threadsCheck) { var item = new FbItem() { Type = FbItemType.Thread, ShowPostCount = true, ShowForumColor = false }; var titleCheck = thread.QuerySelector("td:nth-child(2) div a"); if (titleCheck != null) { item.Name = WebUtility.HtmlDecode(titleCheck.TextContent).FixaRadbrytningar(); item.Id = titleCheck.Attributes["href"].Value.Replace("/", ""); } else { continue; } var subforumCheck = thread.QuerySelector("td:nth-child(2) a.thread-forum-title"); if (subforumCheck != null) { item.Description = WebUtility.HtmlDecode(subforumCheck.TextContent).FixaRadbrytningar(); } var countCheck = thread.QuerySelector("td:nth-child(3) div:nth-child(1) a"); if (countCheck != null) { item.PostCount = int.Parse(countCheck.TextContent.Replace(" ", "").Replace("svar", "")); } resultThreads.Add(item); } } return(resultThreads); }
private async void UIElement_OnTapped(object sender, TappedRoutedEventArgs e) { // så jävla fult men orkar inte just nu med vymodelcommandbinding. // TODO FbItem forumToDelete = (sender as Button).DataContext as FbItem; if (forumToDelete == null) { return; } var model = DataContext as ManageForumlistViewModel; if (model != null) { await model.DeleteForum(forumToDelete); } }
public async Task DeleteForum(FbItem item) { ExtraForumList.Remove(item); await _fileService.SaveExtraForums(ExtraForumList.ToList()); }
private async Task <List <FbItem> > ParseNewTopics(string result) { var parser = new HtmlParser(); var topics = await parser.ParseAsync(result); var postsCheck = topics.QuerySelectorAll("table.table-threads tr"); var newTopics = new List <FbItem>(); if (postsCheck != null) { foreach (var post in postsCheck) { var item = new FbItem() { ShowPostCount = true, ShowForumColor = false, Type = FbItemType.Thread }; var titleCheck = post.QuerySelector("a.thread-title"); if (titleCheck != null) { item.Id = titleCheck.Attributes["href"].Value.Replace("/", ""); item.Name = WebUtility.HtmlDecode(titleCheck.TextContent).FixaRadbrytningar(); } else { continue; } var subforumCheck = post.QuerySelector("td:nth-child(2) div:nth-child(2) a"); if (subforumCheck != null) { item.Description = WebUtility.HtmlDecode(subforumCheck.TextContent).FixaRadbrytningar(); } var countCheck = post.QuerySelector("td:nth-child(3) div:nth-child(2)"); int number = 0; if (countCheck != null) { int pos = countCheck.TextContent.IndexOf("•", StringComparison.Ordinal); if (pos != -1) { // fyfan vilket piss var textNumber = countCheck.TextContent.Substring(pos + 1, countCheck.TextContent.Length - pos - 1); textNumber = textNumber.FixaRadbrytningar().Replace(" ", "").Replace("svar", ""); int.TryParse(textNumber, out number); } } item.PostCount = number; newTopics.Add(item); } return(newTopics); } else { return(new List <FbItem>()); } }
private async Task <List <FbItem> > ParseHotTopics(string result) { var parser = new HtmlParser(); var document = await parser.ParseAsync(result); var threadsParsed = document.QuerySelectorAll("table.table-threads tr"); List <FbItem> hotTopics = new List <FbItem>(); foreach (var t in threadsParsed) { var titleCheck = t.QuerySelector("td:nth-child(2) a"); string title; if (titleCheck != null) { title = WebUtility.HtmlDecode(titleCheck.TextContent.FixaRadbrytningar()); } else { continue; } int postCount = 0; var postCountCheck = t.QuerySelector("td:nth-child(3) div:nth-child(2)"); if (postCountCheck != null) { int pos = postCountCheck.TextContent.IndexOf("•", StringComparison.Ordinal); if (pos != -1) { // fyfan vilket piss var textNumber = postCountCheck.TextContent.Substring(pos + 1, postCountCheck.TextContent.Length - pos - 1); textNumber = textNumber.Replace(" ", "").Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("svar", ""); int.TryParse(textNumber, out postCount); } } var descriptionCheck = t.QuerySelector("td:nth-child(2) div:nth-child(2)"); string description = ""; if (descriptionCheck != null) { description = descriptionCheck.TextContent.FixaRadbrytningar(); } var fbTopic = new FbItem() { Id = titleCheck.Attributes["href"].Value.Replace("/", ""), Name = title, Type = FbItemType.Thread, Description = description, ShowPostCount = true, ShowForumColor = false, PostCount = postCount }; hotTopics.Add(fbTopic); } return(hotTopics); }
private async Task <ForumList> ParseForumlist(string result) { if (string.IsNullOrWhiteSpace(result)) { return new ForumList() { Items = new ObservableCollection <FbItem>() } } ; var document = await new HtmlParser().ParseAsync(result); var forumTitle = WebUtility.HtmlDecode(document.QuerySelector("title").TextContent.Replace(" - Flashback Forum", "")); // Börjar med själva underformuen var forumsParsed = document.QuerySelectorAll("table.forumslist tr:not(.tr_subforum)"); var forum = new List <FbItem>(); foreach (var f in forumsParsed) { var titel = f.QuerySelector("td:first-child a"); var senastepost = f.QuerySelector("div:last-child td.forum-lastpostinfo div div:last-child"); var fbForum = new FbItem() { Id = titel.Attributes["href"].Value, Name = titel.TextContent, Description = WebUtility.HtmlDecode(senastepost.TextContent.FixaRadbrytningar()), ShowForumColor = false, ShowPostCount = false, Type = FbItemType.Forum }; forum.Add(fbForum); } // Därefter hämtar vi ut eventuella trådar var threads = new List <FbItem>(); var threadsParsed = document.QuerySelectorAll("table#threadslist tr"); foreach (var t in threadsParsed) { var threadTitle = t.QuerySelector("td:nth-child(2) a"); if (threadTitle == null) { continue; } var postCountCheck = t.QuerySelector("td:nth-child(3) div:nth-child(1)"); int postCount = 0; if (postCountCheck != null) { if (!int.TryParse(postCountCheck.TextContent.FixaRadbrytningar().Replace(" ", "").Replace("svar", ""), out postCount)) { continue; } } var lastPostCheck = t.QuerySelector("td:nth-child(4)"); string lastPost = ""; if (lastPostCheck != null) { lastPost = lastPostCheck.TextContent.FixaRadbrytningar().Replace("av", " av"); } if (string.IsNullOrWhiteSpace(lastPost)) { continue; } bool isSticky = false; var stickyCheck = t.QuerySelector("i.fa-thumb-tack"); if (stickyCheck != null) { isSticky = true; } var fbThread = new FbItem() { Name = WebUtility.HtmlDecode(threadTitle.TextContent), Id = threadTitle.Attributes["href"].Value.Replace("/", ""), ShowPostCount = true, PostCount = postCount, Description = lastPost, IsSticky = isSticky, Type = FbItemType.Thread }; threads.Add(fbThread); } forum.AddRange(threads); var pagesCheck = document.QuerySelector("div.row-forum-toolbar ul li span"); Regex regex = new Regex(@"Sidan ([\d]+) av ([\d]+)"); bool showNavigation = false; int currentPage = 0; int totalPages = 0; if (pagesCheck != null) { showNavigation = true; foreach (Match match in regex.Matches(pagesCheck.FirstChild.TextContent)) { currentPage = int.Parse(match.Groups[1].Value); totalPages = int.Parse(match.Groups[2].Value); } } var parentCheck = document.QuerySelector("div.list-forum-title ol li:nth-last-child(2) a"); string parentId = ""; if (parentCheck != null) { parentId = parentCheck.Attributes["href"].Value.Replace("/", ""); } return(new ForumList() { Items = new ObservableCollection <FbItem>(forum), Title = forumTitle, ShowNavigation = showNavigation, CurrentPage = currentPage, MaxPages = totalPages, ParentId = parentId }); }