private async void PreviousPostsWebView_ScriptNotify(object sender, NotifyEventArgs e) { string stringJson = e.Value; var command = JsonConvert.DeserializeObject<ThreadCommand>(stringJson); switch (command.Command) { case "profile": Frame.Navigate(typeof (UserProfileView), command.Id); break; case "post_history": Frame.Navigate(typeof (UserPostHistoryPage), command.Id); break; case "rap_sheet": Frame.Navigate(typeof (RapSheetView), command.Id); break; case "quote": loadingProgressBar.Visibility = Visibility.Visible; string quoteString = await _replyManager.GetQuoteString(Convert.ToInt64(command.Id)); quoteString = string.Concat(Environment.NewLine, quoteString); string replyText = string.IsNullOrEmpty(ReplyText.Text) ? string.Empty : ReplyText.Text; if (replyText != null) ReplyText.Text = replyText.Insert(ReplyText.Text.Length, quoteString); loadingProgressBar.Visibility = Visibility.Collapsed; break; default: var msgDlg = new MessageDialog("ダメだよ~。") { DefaultCommandIndex = 1 }; await msgDlg.ShowAsync(); break; } }
void webView_ScriptNotify(object sender, NotifyEventArgs e) { if (e != null && !String.IsNullOrEmpty(e.Value)) { Debug.WriteLine("JS Message : {0}", e.Value); } }
void WebViewControl_ScriptNotify(object sender, NotifyEventArgs e) { // Be sure to verify the source of the message when performing actions with the data. // As webview can be navigated, you need to check that the message is coming from a page/code // that you trust. rootPage.NotifyUser($"Event received from {e.CallingUri}: \"{e.Value}\"", NotifyType.StatusMessage); }
private async void ScriptNotify(object sender, NotifyEventArgs e) { if (e.Value.StartsWith("latitude")) { char[] separators = { ':' }; this._receivedLatitude = Double.Parse(e.Value.Split(separators)[1]); } if (e.Value.StartsWith("longtitude")) { char[] separators = { ':' }; this._receivedLongitude = Double.Parse(e.Value.Split(separators)[1]); } if (e.Value.StartsWith("zoom")) { char[] separators = { ':' }; this._receivedZoom = Int32.Parse(e.Value.Split(separators)[1]); } if (e.Value == "updateTilePositionButton") { MessageDialog dialog = new MessageDialog("地図の中心部分をタイルに表示します"); dialog.Commands.Add(new UICommand("OK", new UICommandInvokedHandler(DialogCommandhandler))); dialog.Commands.Add(new UICommand("キャンセル", new UICommandInvokedHandler(DialogCommandhandler))); dialog.DefaultCommandIndex = 1; dialog.CancelCommandIndex = 2; await dialog.ShowAsync(); } }
private async void WebView_ScriptNotify(object sender, NotifyEventArgs e) { string stringJson = e.Value; var command = JsonConvert.DeserializeObject<ReplyView.ThreadCommand>(stringJson); switch (command.Command) { case "profile": Frame.Navigate(typeof (UserProfileView), command.Id); break; case "post_history": Frame.Navigate(typeof (UserPostHistoryPage), command.Id); break; case "rap_sheet": Frame.Navigate(typeof (RapSheetView), command.Id); break; case "quote": Frame.Navigate(typeof (ReplyView), command.Id); break; case "edit": Frame.Navigate(typeof (EditReplyPage), command.Id); break; default: var msgDlg = new MessageDialog("Working on it!") { DefaultCommandIndex = 1 }; await msgDlg.ShowAsync(); break; } }
private void MyWebView_ScriptNotify(object sender, NotifyEventArgs e) { // check for F11 pressed if(e.Value == "KeyDown:122") { ToggleMenu(); } }
private async void TaobaoLogin_ScriptNotify(object sender, NotifyEventArgs e) { var t = System.Net.WebUtility.UrlDecode(e.Value); System.Diagnostics.Debug.WriteLine("ScriptNotify:" + t); if (t.IndexOf("\"st\"") >= 0) await LoggedProcess(await LoginHelper.XiamiLogin( JObject.Parse(t).GetValue("st").Value<string>())); }
private async void PreviousPostsWebView_ScriptNotify(object sender, NotifyEventArgs e) { string stringJson = e.Value; var command = JsonConvert.DeserializeObject<ReplyView.ThreadCommand>(stringJson); switch (command.Command) { case "profile": Frame.Navigate(typeof(UserProfileView), command.Id); break; case "post_history": Frame.Navigate(typeof(UserPostHistoryPage), command.Id); break; case "rap_sheet": Frame.Navigate(typeof(RapSheetView), command.Id); break; case "quote": Frame.Navigate(typeof(ReplyView), command.Id); break; case "edit": Frame.Navigate(typeof(EditReplyPage), command.Id); break; case "setFont": if (_localSettings.Values.ContainsKey("zoomSize")) { _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]); PreviewLastPostWebView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() }); } else { _zoomSize = 14; } break; case "openThread": // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand. // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once. var threadManager = new ThreadManager(); var thread = await threadManager.GetThread(new ForumThreadEntity(), command.Id); if (thread == null) { var error = new MessageDialog("Specified post was not found in the live forums.") { DefaultCommandIndex = 1 }; await error.ShowAsync(); break; } string jsonObjectString = JsonConvert.SerializeObject(thread); Frame.Navigate(typeof(ThreadPage), jsonObjectString); break; default: var msgDlg = new MessageDialog("Not working yet!") { DefaultCommandIndex = 1 }; await msgDlg.ShowAsync(); break; } }
// Check to see if the ScriptNotify was raised by the javascript we // injected (ie does it start with %%), and then raise the Navigating // event. private void NavigatingScriptNotify(object sender, NotifyEventArgs e) { if (internalNavigating == null) return; if (!string.IsNullOrWhiteSpace(e.Value)) { if (e.Value.StartsWith("%%")) { internalNavigating(this, new NavigatingEventArgs() { LeavingUri = new Uri(e.Value.Trim('%')) }); } } }
private async void WebView_ScriptNotify(object sender, NotifyEventArgs e) { string stringJson = e.Value; var command = JsonConvert.DeserializeObject<ThreadCommand>(stringJson); switch (command.Command) { case "quote": Frame.Navigate(typeof(ReplyPage), command.Id); break; case "edit": Frame.Navigate(typeof(EditPage), command.Id); break; case "setFont": break; case "scrollToPost": if (!string.IsNullOrEmpty(_vm.ForumThreadEntity.ScrollToPostString)) await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString }); break; case "markAsLastRead": await _threadManager.MarkPostAsLastRead(_forumThread, Convert.ToInt32(command.Id)); int nextPost = Convert.ToInt32(command.Id) + 1; await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) }); var message = new MessageDialog("Post marked as last read! Now go on and live your life!") { DefaultCommandIndex = 1 }; await message.ShowAsync(); break; case "openThread": // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand. // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once. var threadManager = new ThreadManager(); var thread = await threadManager.GetThread(new ForumThreadEntity(), command.Id); if (thread == null) { var error = new MessageDialog("Specified post was not found in the live forums.") { DefaultCommandIndex = 1 }; await error.ShowAsync(); break; } string jsonObjectString = JsonConvert.SerializeObject(thread); Frame.Navigate(typeof(ThreadPage), jsonObjectString); break; default: var msgDlg = new MessageDialog("Not working yet!") { DefaultCommandIndex = 1 }; await msgDlg.ShowAsync(); break; } }
void webView6_ScriptNotify(object sender, NotifyEventArgs e) { // Be sure to verify the source of the message when performing actions with the data. // As webview can be navigated, you need to check that the message is coming from a page/code // that you trust. Color c = Colors.Red; if (e.CallingUri.Scheme =="ms-appx-web") { if (e.Value.ToLower() == "blue") c = Colors.Blue; else if (e.Value.ToLower() == "green") c = Colors.Green; } rootPage.NotifyUser(string.Format("Response from script at '{0}': '{1}'", e.CallingUri, e.Value), NotifyType.StatusMessage); }
async void wvListener_ScriptNotify(object sender, NotifyEventArgs e) { String newURL = e.Value; if (newURL.IndexOf("URL:") == 0) { Debug.WriteLine("[wvListener_ScriptNotify] " + newURL); wvMain.Navigate(new Uri(newURL.Substring(4))); } if (dRequest != null) { dRequest.RequestActive(); } else { dRequest = new DisplayRequest(); dRequest.RequestActive(); } }
private async void WebView_ScriptNotify(object sender, NotifyEventArgs e) { string[] urlParts = e.Value.Split('?'); string docLocation = urlParts[0]; Uri docUri = new Uri("ms-appx:///" + docLocation); var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(docUri); var props = await file.GetBasicPropertiesAsync(); var fileSize = props.Size; string range = urlParts[1]; string[] rangeParts = range.Split('&'); string originalRangeStart = rangeParts[0]; ulong rangeStart; // if the range start is negative then read from the end of the file if (originalRangeStart.StartsWith("-")) { ulong rangeStartPositive = (ulong)Math.Abs(Convert.ToInt64(originalRangeStart)); rangeStart = fileSize - rangeStartPositive; } else { rangeStart = Convert.ToUInt64(originalRangeStart); } // if the end range is not specified then it goes to the end of the file ulong rangeEnd = (rangeParts[1].Length == 0) ? fileSize : Convert.ToUInt64(rangeParts[1]); var stream = await file.OpenReadAsync(); stream.Seek(rangeStart); // get the number of bytes to read uint count = (uint)(rangeEnd - rangeStart); var bytes = new byte[count]; using (var dataReader = new DataReader(stream)) { await dataReader.LoadAsync(count); dataReader.ReadBytes(bytes); } string successFunction = string.Format("setTimeout(function() {{ window.CoreControls.PartRetrievers.WinRTPartRetriever.partSuccess('{0}', '{1}'); }}, 0);", Convert.ToBase64String(bytes), originalRangeStart); MyWebView.InvokeScript("eval", new string[] { successFunction }); }
private async void WebViewControl_ScriptNotify(object sender, NotifyEventArgs e) { if (!string.IsNullOrEmpty(e.Value)) { if (e.Value.ToLower().StartsWith("alert:")) { string cmdParams = e.Value.Substring(e.Value.IndexOf(":") + 1); var msg = new Windows.UI.Popups.MessageDialog(cmdParams, "Alert"); await msg.ShowAsync(); } else { JObject optionsJson = JObject.Parse(e.Value); if (optionsJson != null) { string plugin = ""; string action = ""; string args = ""; string callback = ""; JToken pluginJToken = null; pluginJToken = optionsJson["plugin"]; if (pluginJToken != null) plugin = (pluginJToken as JValue).Value.ToString(); JToken actionJToken = null; actionJToken = optionsJson["action"]; if (actionJToken != null) action = (actionJToken as JValue).Value.ToString(); JToken argsJToken = null; argsJToken = optionsJson["args"]; if (argsJToken != null) args = (argsJToken as JValue).Value.ToString(); JToken callbackJToken = null; callbackJToken = optionsJson["callback"]; if (callbackJToken != null) callback = (callbackJToken as JValue).Value.ToString(); PluginSDK.GOPluginManager.Execute(this, this.WebViewControl, plugin, action, args, callback); } } } }
async void webView_ScriptNotify(object sender, NotifyEventArgs e) { if (e != null && !String.IsNullOrEmpty(e.Value)) { Debug.WriteLine("JS Message : {0}", e.Value); JObject obj = JsonConvert.DeserializeObject<JObject>(e.Value); JToken data, guid; if (obj.TryGetValue("data", out data) && obj.TryGetValue("guid", out guid)) { await DoSomethingWithData(data); var guidStr = guid.Value<string>(); await NotifyScript("Message recieved with guid : "+ guidStr, guidStr); } } }
private async void OnScriptNotify(object sender, NotifyEventArgs e) { if (LaunchExternalBrowser) { try { var link = e.Value; if (link.StartsWith("LaunchLink: ")) { var uri = new Uri(link.Substring("LaunchLink: ".Length), UriKind.RelativeOrAbsolute); await Launcher.LaunchUriAsync(uri); } } catch (Exception) { } } }
private void Webview_ScriptNotify(object sender, NotifyEventArgs e) { var cookie = e.Value; var cookies = cookie.Split('&'); string uid = ""; foreach (var str in cookies) { if(str.Contains("KuGoo=KugooID=")) { uid = str.Replace("KuGoo=KugooID=", ""); break; } } if(uid!="") { var localSettings = ApplicationData.Current.LocalSettings; localSettings.Values["uid"] = uid; Frame.GoBack(); } }
private async void OnScriptNotify(object sender, NotifyEventArgs e) { string value = e.Value; if (!String.IsNullOrEmpty(value)) { switch (value[0]) { case 'L': case 'R': _documentSize = ParseRect(value); await OnDocumentResize(_documentSize); break; case 'S': _documentSize = ParseRect(value); OnDocumentScroll(_documentSize); break; default: break; } } }
/// <summary> /// Raised when the user clicks on a hyperlink on the WebView /// </summary> /// <param name="sender">WebView</param> /// <param name="e">Event arguments</param> private async void WebView_OnScriptNotify(object sender, NotifyEventArgs e) { MessageDialog messageDialog = null; try { string data = e.Value; if (data.ToLower().StartsWith("launchlink:")) { await Launcher.LaunchUriAsync(new Uri(data.Substring("launchlink:".Length), UriKind.Absolute)); } } catch { messageDialog = new MessageDialog(MessagesRsxAccessor.GetString("CannotOpenWebsite")); } if (messageDialog != null) { await messageDialog.ShowAsync(); } }
private void WebView_OnScriptNotify(object sender, NotifyEventArgs e) { //这个事件函数可以监听到JS通知的消息,消息类型为文本 //这里统一消息格式为:JsInvokeModel var model = JsonConvert.DeserializeObject<JsInvokeModel>(e.Value); switch (model.Type) { //case "image": // Info.Text = e.Value; // break; //case "swiperight": // //右滑 // Info.Text = e.Value; // break; //case "swipeleft": // //左滑 // Info.Text = e.Value; // break; //case "text": // Info.Text = e.Value; // break; } }
private async void contentView_ScriptNotify(object sender, NotifyEventArgs e) { await Windows.System.Launcher.LaunchUriAsync(new Uri(e.Value)); }
/// <summary> /// Allow webview script to notify system /// </summary> /// <param name="sender">Event originator</param> /// <param name="e">Notify Event argument</param> private void scriptEvent(object sender, NotifyEventArgs e) { }
void wbMain_ScriptNotify(object sender, NotifyEventArgs e) { }
void webView_ScriptNotify(object sender, NotifyEventArgs e) { string commandStr = e.Value; if (commandStr.IndexOf("MESSAGE") == 0) { commandStr = commandStr.Replace("MESSAGE:", ""); Debug.WriteLine("MESSAGE :: " + commandStr); return; } Dictionary<string,string> dict = commandStr.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries) .Select(part => part.Split('=')) .ToDictionary(split => split[0], split => split[1]); if (dict["type"].Equals("FBPost")) { commandStr = commandStr.Replace("MESSAGE:", ""); Debug.WriteLine("MESSAGE :: " + commandStr); } else if (dict["type"].Equals("FBUI")) { commandStr = commandStr.Replace("MESSAGE:", ""); Debug.WriteLine("MESSAGE :: " + commandStr); if (dict["method"].Equals("feed")) { ShowDialog(dict); } else if (dict["method"].Equals("send")) { ShowDialog(dict); } else if (dict["method"].Equals("apprequests")) { ShowDialog(dict); } } else if (dict["type"].Equals("FBAPI")) { if (dict["func"].Equals("login")) { Login(dict["app_id"], (dict["scope"].Length > 1 && dict["scope"] != null) ? dict["scope"] : ExtendedPermissions); } else if (dict["func"].Equals("logout")) { Logout(); } else if (dict["func"].Equals("feed")) { if (dict["httpMethod"].Equals("GET")) GetUserData(dict); else PostUserData(dict); } else { commandStr = commandStr.Replace("MESSAGE:", ""); Debug.WriteLine("MESSAGE :: " + commandStr); } } }
/// <summary> /// Invoked when the webview calls the window.external.notify function. /// </summary> /// <param name="sender">The webview presenting the DOM.</param> /// <param name="e"> /// Event data containing values passed as parameters of the javascript function. /// </param> private void itemDetail_ScriptNotify(object sender, NotifyEventArgs e) { string value = e.Value; switch (value) { case "showLoading": this.loadingRing.IsActive = true; break; case "hideLoading": this.loadingRing.IsActive = false; break; default: IWebViewModel<string> item = this.itemListView.SelectedItem as IWebViewModel<string>; if (item != null) { Task.Delay(10).ContinueWith(async t => { string err = null; try { await item.OnScriptNotifyAsync(this, this.progress, e.Value); } catch (Exception ex) { err = ex.Message; } finally { progress.Report(null); } if (!string.IsNullOrEmpty(err)) await new MessageDialog(err, "Oops, something went wrong.").ShowAsync(); }, TaskScheduler.FromCurrentSynchronizationContext()); } break; } }
/// <summary> /// Invoke script from webview /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Wv_OnScriptNotify(object sender, NotifyEventArgs e) { try { // invoke IE. string data = e.Value; const string urlPrefix = "url:"; if (data.ToUpper().StartsWith(urlPrefix.ToUpper())) { // if it is not a valid url type, add http prefix. var url = data.Substring(urlPrefix.Length); if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute) || !url.Contains("://")) url = "http://" + url; await Launcher.LaunchUriAsync(new Uri(url, UriKind.RelativeOrAbsolute)); } } catch (Exception) { // Could not build a proper Uri. Abandon. } }
private void WebView_ScriptNotify(object sender, NotifyEventArgs e) { if (e.Value == "stopScrollingToEnd") { scrollToEnd = "false"; } else if (e.Value == "startScrollingToEnd") { scrollToEnd = "true"; } }
private void WebView1_ScriptNotify(object sender, NotifyEventArgs e) { string myurl = e.Value; System.Diagnostics.Debug.WriteLine(myurl); //example:http://bbs.jiangnan.edu.cn/wForum/disparticle.php?boardName=A.JnrainClub&ID=19956&pos=1 if (myurl.Contains("disparticle")) { myUrl = myurl; showMsg(); } }
private async void WebView_ScriptNotify(object sender, NotifyEventArgs e) { string stringJson = e.Value; var command = JsonConvert.DeserializeObject<ThreadPage.ThreadCommand>(stringJson); switch (command.Command) { case "openThread": // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand. // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once. var threadManager = new ThreadManager(); var thread = await threadManager.GetThread(new ForumThreadEntity(), command.Id); if (thread == null) { var error = new MessageDialog("Specified post was not found in the live forums.") { DefaultCommandIndex = 1 }; await error.ShowAsync(); break; } string jsonObjectString = JsonConvert.SerializeObject(thread); Frame.Navigate(typeof(ThreadPage), jsonObjectString); break; } }
/// <summary> /// 点击昵称 头像 设置@操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FlashComment_ScriptNotify(object sender, NotifyEventArgs e) { MyComment.Text += "@" + e.Value + " "; }