Exemple #1
0
        private void tm_XuLyTinNhan_Tick(object sender, EventArgs e)
        {
            Application.DoEvents();

            try
            {
                GeckoHtmlElement nodeRoot = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//div[@class='voice acw abt'][last()]");
                if (nodeRoot == null)
                {
                    isDangXuLyTinNhan = false;
                    return;
                }

                GeckoHtmlElement divMsg = web2.Document.CreateHtmlElement("div");

                string html = "";

                var user = nodeRoot.GetElementsByTagName("strong").Where(n => n.GetAttribute("class") == "actor").FirstOrDefault();
                if (user != null)
                {
                    html += "<div class='user'><b>" + user.TextContent + "</b>";
                    var timeSpan = nodeRoot.GetElementsByTagName("abbr").FirstOrDefault();
                    if (timeSpan != null)
                    {
                        html += "<span class='time'>(" + timeSpan.TextContent + ")</span>";
                    }
                    html += "</div>";
                }

                var mess = nodeRoot.GetElementsByTagName("div").Where(n => n.GetAttribute("data-sigil") == "message-text");

                bool isTiepTuc = true;

                foreach (GeckoHtmlElement m in mess)
                {
                    Application.DoEvents();
                    isTiepTuc = true;
                    if (chkImgOffline.Checked)
                    {
                        var arrImg = m.GetElementsByTagName("img");
                        foreach (GeckoImageElement _img in arrImg)
                        {
                            string strBase64 = ImageToBase64(_img);
                            if (strBase64 != "")
                            {
                                _img.SetAttribute("src", "data:image/png;base64," + strBase64);
                            }
                        }
                    }

                    Regex  r         = new Regex("timestamp&quot;:(.*?),", RegexOptions.Multiline);
                    Match  mt        = r.Match(m.OuterHtml);
                    string _str_time = "";
                    if (mt.Success)
                    {
                        DateTime tSS = SecondToDateTime(mt.Groups[1].Value.ToString());
                        _str_time = tSS.ToString("HH:mm");
                        if (txtDenLuc.Checked && tSS < txtDenLuc.Value)
                        {
                            isTiepTuc = false;
                        }
                    }

                    if (chkTaiTextDuyNhat.Checked)
                    {
                        if (m.TextContent.Trim() != "")
                        {
                            html += "<div class='msg'><span class='time2'>" + _str_time + "</span>" + m.TextContent + "</div>";
                        }
                    }
                    else
                    {
                        html += "<div class='msg'><span class='time2'>" + _str_time + "</span>" + m.InnerHtml + "</div>";
                    }
                }

                divMsg.InnerHtml = "<div>" + html + "</div>";

                web2.Document.Body.InsertBefore(divMsg, web2.Document.Body.ChildNodes[0]);


                nodeRoot.ParentNode.RemoveChild(nodeRoot);

                if (!isTiepTuc)
                {
                    btnLoadTinNhan.Text = "Tải tin nhắn";
                    isDangXuLyTinNhan   = false;
                    divLoadMore         = null;
                    TrangThaiDangTai(true);
                    tm_XuLyTinNhan.Stop();
                }
            }
            catch (Exception)
            {
            }
        }
Exemple #2
0
        protected void UpdateUrlAbsolute(GeckoDocument doc, GeckoHtmlElement ele)
        {
            string link = doc.Url.GetLeftPart(UriPartial.Authority);

            var eleColec = ele.GetElementsByTagName("IMG");
            foreach (GeckoHtmlElement it in eleColec)
            {
                if (!it.GetAttribute("src").StartsWith("http://"))
                    it.SetAttribute("src", link + it.GetAttribute("src"));
            }
            eleColec = ele.GetElementsByTagName("A");
            foreach (GeckoHtmlElement it in eleColec)
            {
                if (!it.GetAttribute("href").StartsWith("http://"))
                    it.SetAttribute("href", link + it.GetAttribute("href"));
            }
        }