Пример #1
0
 private async Task GetVerificationCodeAsync()   // js to callback
 {
     var js = @"var node = document.getElementById('captcha_image');
                      var src = node.getAttribute('src');
                      window.external.notify(JSON.stringify(src));";
     await InnerWebView.InvokeScriptAsync("eval", new[] { js });
 }
Пример #2
0
        /// <summary>
        /// insert id and password into webview from popup, and after that, click the submit button.
        /// </summary>
        /// <param name="user">your cache id</param>
        /// <param name="pass">your cache password</param>
        /// <returns></returns>
        private async Task InsertLoginMessageAsync(string user, string pass, string code = null, bool auto = false)
        {
            try { // insert js and run it, so that we can insert message into the target place and click the submit button.
                var autoToLogin    = auto ? "checked" : "";
                var newJSFounction = $@"
                            var node_list = document.getElementsByTagName('input');
                                for (var i = 0; i < node_list.length; i++) {"{"}
                                var node = node_list[i];
                                    if (node.getAttribute('type') == 'submit') 
                                        node.click();
                                    if (node.id == 'email') 
                                        node.innerText = '{user}';
                                    if (node.id == 'password') 
                                        node.innerText = '{pass}';
                                    if (node.name == 'form_email') 
                                        node.setAttribute('value', '{user}');
                                    if (node.name == 'form_password') 
                                        node.setAttribute('value', '{pass}');
                                    if (node.id == 'captcha_field') 
                                        node.innerText = '{code}';
                                    if (node.id == 'remember') 
                                        node.setAttribute('checked', '{autoToLogin}');
                                {"}"} ";
                await InnerWebView.InvokeScriptAsync("eval", new[] { newJSFounction });
            } catch (Exception) { // if any error throws, reset the UI and report errer.
                Submit.IsEnabled   = true;
                SubitRing.IsActive = false;
                ReportHelper.ReportAttentionAsync("Error");
            }
        }
Пример #3
0
 /// <summary>
 /// send message to windows so that we can get message of login-success whether or not.
 /// </summary>
 /// <returns></returns>
 private async Task AskWebViewToCallbackAsync()   // js to callback
 {
     var js = @"window.external.notify(
                             JSON.stringify(
                                 new Array (
                                     document.body.innerText,
                                     document.body.innerHTML)));";
     await InnerWebView.InvokeScriptAsync("eval", new[] { js });
 }