Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 protected async override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     try
     {
         var js = new FileInfo(@"test.js");
         using (var runtime = JsRuntime.Create())
         {
             runtime.AllocatingMemory  += this.Runtime_MemoryEvent;
             runtime.CollectingGarbage += this.Runtime_CollectingGarbage;
             using (runtime.CreateContext().Use(true))
             {
                 try
                 {
                     var obj = JsExternalObject.Create(this);
                     obj.ExternalData = 12;
                     obj.ExternalData = 100;
                     JsContext.StartDebugging();
                     var func    = JsFunction.Create(saf);
                     var console = Opportunity.ChakraBridge.WinRT.Browser.Console.GetOrCreate();
                     console.Logging += Con_Logging;
                     var c2 = Opportunity.ChakraBridge.WinRT.Browser.Console.GetOrCreate();
                     JsValue.GlobalObject["func"] = func;
                     JsContext.RunScript("console.log(1,'2',{});func(1,'2',{});new func();", js.Name);
                 }
                 catch (Exception)
                 {
                     var error = JsContext.LastError;
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
Exemple #2
0
        private async Task <string> parseChapterPageAsync(ChapterDataDetailed chapter, HtmlDocument document)
        {
            // var preview = "7966638.html",next = "7966640.html",bid = "11341",book="剑娘",zid = "7966639",chapter = "第893章 舰娘再现";document.onkeydown= jumpPage;
            var rscript = document.DocumentNode.SelectNodes("/html/head/script").Last(n => !n.GetInnerText().IsNullOrWhiteSpace());
            var prop    = Helpers.ParseJsKvp(rscript.GetInnerText());

            chapter.Key   = prop["zid"];
            chapter.Title = prop["chapter"];
            var nk = prop["next"]; // 123567.html

            if (nk.Contains('.'))
            {
                nk = nk.Substring(0, nk.IndexOf('.'));
            }
            else
            {
                nk = null; //the last chapter
            }
            var center = document.GetElementbyId("center");

            chapter.UpdateTime = DateTime.Parse(center.SelectSingleNode("./div[@class='title']/span[last()]").GetInnerText());
            chapter.WordCount  = int.Parse(center.SelectSingleNode("./div[@class='title']/span[last()-1]").GetInnerText());

            var displayTitle = center.SelectSingleNode("./div[@class='title']/h1").GetInnerText();

            if (displayTitle != chapter.Title && displayTitle.EndsWith(chapter.Title))
            {
                chapter.VolumeTitle = displayTitle.Substring(0, displayTitle.Length - chapter.Title.Length).Trim();
            }

            var script  = center.SelectSingleNode("./script");
            var content = document.GetElementbyId("content");

            if (script != null)
            {
                var scr  = script.GetInnerText();
                var uri  = "/ajax/content/";
                var data = default(Dictionary <string, string>);
                IJsValue post(IJsFunction callee, IJsObject caller, bool isConstructCall, IReadOnlyList <IJsValue> arguments)
                {
                    uri  = arguments[0].ToString().CoalesceNullOrEmpty("/ajax/content/");
                    data = ((IDictionary <string, IJsValue>)arguments[1]).ToDictionary(kv => kv.Key, kv => kv.Value.ToString());
                    return(JsUndefined.Instance);
                }

                using (jsrt.CreateContext().Use(true))
                {
                    var jq = JsObject.Create();
                    jq["post"] = JsFunction.Create(post);
                    JsValue.GlobalObject["$"] = jq;
                    JsContext.RunScript(scr);
                }
                var realContent = await Post(new Uri(uri, UriKind.RelativeOrAbsolute), new HttpFormUrlEncodedContent(data));

                var contentDoc = new HtmlDocument();
                contentDoc.Load((await realContent.Content.ReadAsBufferAsync()).AsStream(), document.DeclaredEncoding);
                content = contentDoc.DocumentNode;
            }
            chapter.Content = string.Join("\n", content.Elements("p").EmptyIfNull().Select(p => p.GetInnerText()));

            return(nk);
        }