private void Browser_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e) { var doc = (IHTMLDocument2)browser.Document.DomDocument; this.styleSheet = doc.createStyleSheet("themesheet.css"); this.ThemeStyleSheet(); }
private void Init() { IHTMLDocument2 doc = (webBrowser1.Document.DomDocument) as IHTMLDocument2; // The first parameter is the url, the second is the index of the added style sheet. IHTMLStyleSheet ss = doc.createStyleSheet("", 0); this.Text = webBrowser1.DocumentTitle; // Now that you have the style sheet you have a few options: // 1. You can just set the content as text. //ss.cssText = @"div { display: none; }"; // 2. You can add/remove style rules. ss.addRule("div#content", "padding: 0px;"); ss.addRule("div#siteHeader", "display: none;"); ss.addRule("div#videoHeader", "display: none;"); ss.addRule("div#playlist", "display: none;"); ss.addRule("div#playlistInformation", "display: none;"); ss.addRule("div#playlistContainer", "display: none;"); ss.addRule("div#playlistTrashbox", "display: none;"); ss.addRule("div#videoExplorerExpand", "display: none;"); ss.addRule("div#bottomContentTabContainer", "display: none;"); ss.addRule("div#footer", "display: none;"); ss.addRule("div#playerTabContainer", "display: none;"); ss.addRule("div#appliPanel", "display: none;"); Zoom((int)numericUpDown1.Value); var docEvents = (mshtml.HTMLDocumentEvents2_Event)webBrowser1.Document.DomDocument; docEvents.onmousewheel -= docEvents_onmousewheel; //may not be necessary? docEvents.onmousewheel += docEvents_onmousewheel; }
private void SetThemeColors() { if (Browser != null) { string cssText = GetCssText(); if (!string.IsNullOrEmpty(cssText) && Browser.Document != null) { IHTMLDocument2 doc = Browser.Document.DomDocument as IHTMLDocument2; if (doc != null) { if (doc.styleSheets.length > 0) { object index = 0; var ss = doc.styleSheets.item(ref index) as IHTMLStyleSheet; ss.cssText = cssText; } else { IHTMLStyleSheet ss = doc.createStyleSheet(); if (ss != null) { ss.cssText = cssText; } } } } } }
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { HtmlDocument document = browser.Document; HtmlElement head = document.GetElementsByTagName("head")[0]; HTMLDocument mshtml = (HTMLDocument)document.DomDocument; IHTMLDOMNode msHead = null; foreach (IHTMLDOMNode item in mshtml.getElementsByTagName("head")) { msHead = item; } List <IHTMLDOMNode> origins = new List <IHTMLDOMNode>(); foreach (IHTMLDOMNode item in msHead.childNodes) { origins.Add(item); msHead.removeChild(item); } IHTMLStyleSheet sytle = mshtml.createStyleSheet(); sytle.cssText = Style; HtmlElement jquery = document.CreateElement("script"); ((IHTMLScriptElement)jquery.DomElement).text = Resources.jquery; HtmlElement script = document.CreateElement("script"); ((IHTMLScriptElement)script.DomElement).text = Script; head.AppendChild(jquery); head.AppendChild(script); foreach (IHTMLDOMNode item in origins) { msHead.appendChild(item); } UpdateTable(); }
private void LoadDefferedStyleSheetLinks() { if (stylesheet != null && VisualEditor.Document != null) { HTMLDocument hdoc = (HTMLDocument)VisualEditor.Document.DomDocument; foreach (var link in deferredStyleSheetLinks) { try { foreach (IHTMLStyleSheet ss in hdoc.styleSheets) { if (ss.href == link) { continue; // Already Added. } } IHTMLStyleSheet hstyle = hdoc.createStyleSheet(link); } catch (Exception ex) { ex.GetType(); } } } }
private void Browser_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e) { var doc = (IHTMLDocument2)browser.Document.DomDocument; this.styleSheet = doc.createStyleSheet("themesheet.css"); doc.createStyleSheet(TermWindowPackage.Instance?.OptionCustomCSSPath ?? ""); this.ThemeStyleSheet(); }
/// <summary> /// Set style for visual editor. /// </summary> private void SetStylesheet() { if (stylesheet != null && VisualEditor.Document != null) { HTMLDocument hdoc = (HTMLDocument)VisualEditor.Document.DomDocument; IHTMLStyleSheet hstyle = hdoc.createStyleSheet("", 0); hstyle.cssText = stylesheet; } }
private void ApplyStyleSheet(bool apply) { try { if (apply) { var document = WebBrowser.Document as HTMLDocument; if (document == null) { return; } var gameFrame = document.getElementById("game_frame"); if (gameFrame == null) { gameFrame = document.getElementById("ooi-game"); } if (gameFrame == null) { gameFrame = document.getElementById("flashWrap"); } if (gameFrame == null && document.url.Contains(".swf?")) { gameFrame = document.body; } HTMLDocument target; HTMLEmbed flash; if (gameFrame != null) { target = gameFrame.document as HTMLDocument; } else if ((flash = FindFlashElement()) != null) { target = flash.document; } else { return; } styleSheet = target.createStyleSheet(); styleSheet.cssText = OverrideStyleSheet; } else { if (styleSheet != null) { styleSheet.cssText = string.Empty; } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
void OnIbetStatementDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (webStatement.Document != null) { IHTMLDocument2 currentDocument = (IHTMLDocument2)webStatement.Document.DomDocument; int length = currentDocument.styleSheets.length; IHTMLStyleSheet styleSheet = currentDocument.createStyleSheet(@"", length + 1); styleSheet.cssText = Css.IbetStatements; } }
public static void AddCSS(this HtmlDocument htmlDocument, string cssFileName) { IHTMLDocument2 currentDocument = (IHTMLDocument2)htmlDocument.DomDocument; int length = currentDocument.styleSheets.length; IHTMLStyleSheet styleSheet = currentDocument.createStyleSheet(@"", length + 1); using (TextReader reader = new StreamReader(cssFileName)) { styleSheet.cssText = reader.ReadToEnd(); } }
private static void SetupWebBrowserCSS(WebBrowser browser) { IHTMLDocument2 doc = (IHTMLDocument2)browser.Document; if (doc == null) { return; } IHTMLStyleSheet ss = doc.createStyleSheet("", 0); ss.cssText = GetCSSStyle(browser); }
/// <summary> /// Applying CSS styles on document diaplayed in WebBrowser /// </summary> /// <param name="browser">Current WebBrowser</param> /// <param name="style">String containing CSS styles</param> public static void ConfigureBrowser(this System.Windows.Controls.WebBrowser browser, string style) { if (string.IsNullOrEmpty(style)) { return; } if (browser.Document is HTMLDocument document) { IHTMLStyleSheet styleSheet = document.createStyleSheet("", 0); styleSheet.cssText = style; } }
private void WebBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { IHTMLDocument2 doc = (webBrowser1.Document.DomDocument) as IHTMLDocument2; IHTMLStyleSheet ss = doc.createStyleSheet("", 0); if (BlackBg == true) { ss.cssText = "body {background-color: #000000;}"; // GetCssText(); } else { ss.cssText = "body {background-color: #FFFFFF;}"; } }
// Add CSS styling to the webBrowser object private void InitCSS() { IHTMLDocument2 document = (webBrowserDescription.Document.DomDocument) as IHTMLDocument2; // The first parameter is the url, the second is the index of the added style sheet. IHTMLStyleSheet styleSheet = document.createStyleSheet("", 0); // Change the font for everything in the document. Font list taken from the Github readme page int index = styleSheet.addRule("*", "font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\";"); // Edit existing rules // styleSheet.cssText = @"h1 { color: blue; }"; // Remove existing rules // styleSheet.removeRule(index); }
void webLogs_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { logDoc = webLogs.Document; logDocRaw = (IHTMLDocument2)logDoc.DomDocument; IHTMLStyleSheet ss = logDocRaw.createStyleSheet("", 0); ss.cssText = Properties.Resources.defaultTemplate; var myScript = logDoc.CreateElement("script"); ((IHTMLScriptElement)myScript.DomElement).text = Properties.Resources.hoverJavaScript; // logDoc.Body.AppendChild(myStyle); logDoc.Body.AppendChild(myScript); Debug.WriteLine(logDoc.Body.InnerHtml); }
/// <summary> /// Attaches theme-specific styles to the help page. /// </summary> private void AttachStandardStyles() { var doc = Browser?.Document?.DomDocument as IHTMLDocument2; if (doc != null) { string cssText = GetCssText(); if (!string.IsNullOrEmpty(cssText)) { IHTMLStyleSheet ss = doc.createStyleSheet(); if (ss != null) { ss.cssText = cssText; } } } }
private void OnLoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { if (((WebBrowser)sender).Source.ToString().Contains("pushbullet.com/authorize")) { mshtml.IHTMLDocument2 document = LoginBrowser.Document as mshtml.IHTMLDocument2; IHTMLStyleSheet style = document.createStyleSheet("", 0); style.addRule(".agree-page", "position:absolute;top:0;left:0;right:0;"); style.addRule(".agree-page > div:nth-child(2)", "display:none;"); style.addRule(".agree-page h1", "margin-top:100px !important;"); style.addRule("#header img", "display:none;"); style.addRule("#account-btn:not([style*='background'])", "display:none;"); style.addRule(".approve", "margin-bottom: 0 !important;"); style.addRule(".deny", "background: #e85845;color: white !important;width: 230px;height: 60px;margin: 0 auto;line-height: 22px;font-size:20px !important;text-decoration: none;display: flex;align-items: center;justify-content: center;"); } }
private void AdaptChangelog(object sender, EventArgs e) { IHTMLDocument2 doc = (wbChangelog.Document.DomDocument) as IHTMLDocument2; // The first parameter is the url, the second is the index of the added style sheet. IHTMLStyleSheet ss = doc.createStyleSheet("", 0); // Now that you have the style sheet you have a few options: // 1. You can just set the content as text. ss.cssText = @"#pageHeaderContainer { display: none; } .cookiePolicyNotice { display: none; } .toTop { display: none !important; } #main { padding-top: 10px !important; } .articleList > li:not(:first-child) { margin-top: 20px !important; } #content > .section { margin-top: 10px; }"; HtmlElement head = wbChangelog.Document.GetElementsByTagName("head")[0]; HtmlElement scriptEl = wbChangelog.Document.CreateElement("script"); IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement; element.text = @"function check() { if (typeof $ === 'undefined' || window.ada) { return; } $(document).ready(function() { if($('.contentTitle').text() !== 'Artikel') { $('.contentTitle').prepend('<a onclick=\'window.history.back();\'><<</a> '); window.ada = true; } }); }"; head.AppendChild(scriptEl); wbChangelog.Document.InvokeScript("check"); }
// When the WebBrowser control's document is fully loaded: // Style the web page with Resources/styles.css and add LinkClicked event handlers to all the hyperlinks. private void wb_Licenses_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { // Get our styles.css resource ResourceManager res = new ResourceManager(RESOURCE_LIB_NAME, typeof(ZeroMunge).Assembly); string stylesheet = (string)res.GetObject("stylesheet"); // Set the web page's stylesheet IHTMLDocument2 doc = (IHTMLDocument2)wb_Licenses.Document.DomDocument; IHTMLStyleSheet ss = doc.createStyleSheet("", 0); ss.cssText = @stylesheet; // Add LinkClicked event handlers to all the links in the page foreach (HtmlElement link in wb_Licenses.Document.Links) { link.Click += wb_Licenses_LinkClicked; } }
/// <summary> /// This is called when the initial html/body framework is set up, /// or when document.DocumentText is set. At this point, the /// document is editable. /// </summary> /// <param name="sender">sender</param> /// <param name="e">navigation args</param> private void this_Navigated(object sender, WebBrowserNavigatedEventArgs e) { TableEditor = new HtmlTableHelper(this); SetBackgroundColor(BackColor); IHTMLStyleSheet style = htmlDoc.createStyleSheet("", 0); style.cssText = @"table, th, td { border-collapse: collapse; border-color: black } "; //table, th, td { border: 1px solid black; } Ready(sender); // register for change notification IMarkupContainer2 cont2 = (IMarkupContainer2)htmlDoc; uint m_cookie; cont2.RegisterForDirtyRange(this, out m_cookie); // register for key/mouse events SetEditDesigner(); }
private void OnVisualEditorDocumentNavigated(object sender, System.Windows.Forms.WebBrowserNavigatedEventArgs e) { VisualEditor.Document.ContextMenuShowing += this.OnDocumentContextMenuShowing; htmldoc = new HtmlDocument(VisualEditor.Document); //((IHTMLDocument2)VisualEditor.Document.DomDocument).designMode = "ON"; //样式 if (style != null && VisualEditor.Document != null) { HTMLDocument hdoc = (HTMLDocument)VisualEditor.Document.DomDocument; IHTMLStyleSheet hstyle = hdoc.createStyleSheet("", 0); hstyle.cssText = style; } //内容 if (myBindingContent != null) { VisualEditor.Document.Body.InnerHtml = myBindingContent; } VisualEditor.Document.Body.SetAttribute("contenteditable", "true"); VisualEditor.Document.Focus(); }
private void AddStyles() { try { if (webBrowser.Document != null) { IHTMLDocument2 currentDocument = (IHTMLDocument2)webBrowser.Document.DomDocument; int length = currentDocument.styleSheets.length; IHTMLStyleSheet styleSheet = currentDocument.createStyleSheet(@"", length + 1); //length = currentDocument.styleSheets.length; //styleSheet.addRule("body", "background-color:blue"); TextReader reader = new StreamReader(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Styles/table_style.css")); string style = reader.ReadToEnd(); styleSheet.cssText = style; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ApplyStyle(string style) { if (string.IsNullOrEmpty(style)) { return; } try { if (wb.Document != null) { var currentDocument = (IHTMLDocument2)wb.Document; int length = currentDocument.styleSheets.length; IHTMLStyleSheet styleSheet = currentDocument.createStyleSheet(@"", length + 1); styleSheet.cssText = style; } } catch (Exception) { } }
public KanColleBrowser() { InitializeComponent(); WebBrowser.Navigated += (_, __) => ApplyZoomFactor(zoomFactor); WebBrowser.LoadCompleted += (_, __) => LockFlash(IsFlashLocked); SetSilence(true); SetAllowDrop(false); //btnBack.Click += (_, __) => WebBrowser.GoBack(); //btnFoward.Click += (_, __) => WebBrowser.GoForward(); GotoUrlCommand = new DelegateCommand(() => { if (!txtAddress.Text.Contains(":")) txtAddress.Text = "http://" + txtAddress.Text; try { WebBrowser.Navigate(txtAddress.Text); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } }); btnRefresh.Click += (_, __) => WebBrowser.Navigate(WebBrowser.Source); btnBackToGame.Click += (_, __) => WebBrowser.Navigate(Properties.Settings.Default.GameUrl); btnStop.Click += (_, __) => Stop(); WebBrowser.Navigating += (_, e) => { txtAddress.Text = e.Uri.AbsoluteUri; //btnBack.IsEnabled = WebBrowser.CanGoBack; //btnFoward.IsEnabled = WebBrowser.CanGoForward; styleSheet = null; UpdateSize(false); }; btnScreenShot.Click += (_, __) => TakeScreenShot(Config.Current.GenerateScreenShotFileName()); btnCleanCache.Click += async (sender, _) => { var button = sender as Button; button.IsEnabled = false; if (MessageBox.Show(StringTable.CleanCache_Alert, "", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) == MessageBoxResult.Yes) if (await WinInetHelper.DeleteInternetCacheAsync()) MessageBox.Show(StringTable.CleanCache_Success); else MessageBox.Show(StringTable.CleanCache_Fail); button.IsEnabled = true; }; this.Loaded += (_, __) => { if (firstLoad && Officer.Staff.IsStarted) { var url = Config.Current.OverrideGameUrl; if (string.IsNullOrWhiteSpace(url)) url = Properties.Settings.Default.GameUrl; WebBrowser.Navigate(url); firstLoad = false; } }; }
private void ApplyStyleSheet(bool apply) { try { if (apply) { var document = WebBrowser.Document as HTMLDocument; if (document == null) return; var gameFrame = document.getElementById("game_frame"); if (gameFrame == null) gameFrame = document.getElementById("ooi-game"); if (gameFrame == null) gameFrame = document.getElementById("flashWrap"); if (gameFrame == null && document.url.Contains(".swf?")) gameFrame = document.body; HTMLDocument target; HTMLEmbed flash; if (gameFrame != null) target = gameFrame.document as HTMLDocument; else if ((flash = FindFlashElement()) != null) target = flash.document; else return; styleSheet = target.createStyleSheet(); styleSheet.cssText = OverrideStyleSheet; } else { if (styleSheet != null) styleSheet.cssText = string.Empty; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
public void InitializeStyleSheet() { css = doc.createStyleSheet("", 0); css.cssText = File.ReadAllText("github-markdown.css"); }
private void setCustomStyleSheet(String styleString) { IHTMLStyleSheet customCSS = getHtmlDocument(mWebBrowser).createStyleSheet(); customCSS.cssText = styleString; }
public void GetPage() { doc = (webBrowser1.Document.DomDocument) as IHTMLDocument2; ss = doc.createStyleSheet("", 0); url = webBrowser1.Url.ToString(); title = webBrowser1.DocumentTitle; }
// Depth is here because of an IE bug- /* index.htm <style> @import(url1.css) </style> url1.css @import(url2.css) url2.css @import(url3.css) Enumerating the import statement in url2.css will cause an out of memory exception and destabilize / crash IE. The depth restriction causes us to skip imports that are at that depth or deeper. */ private static void AddSheetReferencesToList(ArrayList list, IHTMLStyleSheet styleSheet, string baseUrl, int depth) { try { if (styleSheet.href != null) baseUrl = UrlHelper.EscapeRelativeURL(baseUrl, styleSheet.href); // handle style sheet imports if (styleSheet.imports.length > 0 && depth < 2) { IEnumerator importEnum = styleSheet.imports.GetEnumerator(); while (importEnum.MoveNext()) { // Add this style sheet to the reference list IHTMLStyleSheet importSheet = (IHTMLStyleSheet)importEnum.Current; string sheetPath = importSheet.href; if (baseUrl != "about:blank" && !UrlHelper.IsUrl(importSheet.href)) sheetPath = UrlHelper.EscapeRelativeURL(baseUrl, importSheet.href); ResourceUrlInfo urlInfo = new ResourceUrlInfo(); urlInfo.ResourceUrl = importSheet.href; urlInfo.ResourceAbsoluteUrl = sheetPath; urlInfo.ResourceType = HTMLTokens.Style; list.Add(urlInfo); // Add the sheets references to the list AddSheetReferencesToList(list, importSheet, baseUrl, depth + 1); } } IHTMLStyleSheetRulesCollection rules = (IHTMLStyleSheetRulesCollection)styleSheet.rules; for (int i = 0; i < rules.length; i++) { IHTMLStyleSheetRule rule = (IHTMLStyleSheetRule)rules.item(i); IHTMLRuleStyle styleRule = (IHTMLRuleStyle)rule.style; AddStyleReference(baseUrl, list, styleRule.backgroundImage); AddStyleReference(baseUrl, list, styleRule.background); AddStyleReference(baseUrl, list, styleRule.listStyleImage); AddStyleReference(baseUrl, list, styleRule.listStyle); } } catch (UnauthorizedAccessException) { // We weren't permitted to access the style sheets, try manual parse } catch (Exception ex) { Trace.Fail("An unexpected exception occurred while attempting to enumerate stylesheet references. " + ex.ToString()); // IE is a total pile, I hate it } }
private static void AddSheetReferencesToList(ArrayList list, IHTMLStyleSheet styleSheet, string baseUrl) { AddSheetReferencesToList(list, styleSheet, baseUrl, 0); }
internal CssStyleSheet(ScriptContext context, IHTMLStyleSheet comObject) : base(context, comObject) { }
private void AddMaps(WebBrowser browser) { string googleURL = "http://maps.googleapis.com/maps/api/js?libraries=&sensor=false&callback=init"; if (!string.IsNullOrEmpty(m_gmeClientID)) { googleURL += "&client=" + m_gmeClientID; } if (!string.IsNullOrEmpty(m_googleChannel)) { googleURL += "&channel=" + m_googleChannel; } //Clear body if (browser.Document != null) { if (browser.Document.Body != null) { HtmlElement htEl = browser.Document.CreateElement("script"); if (htEl != null) { htEl.SetAttribute("type", "text/javascript"); Type t = htEl.DomElement.GetType(); t.InvokeMember("text", BindingFlags.SetProperty, null, htEl.DomElement, new object[] { @"function modContent() { var head = document.getElementsByTagName(""head"")[0]; /*while (head.getElementsByTagName(""META"").length > 0) { head.removeChild(head.getElementsByTagName(""META"")[0]); }*/ while (head.getElementsByTagName(""link"").length > 0) { head.removeChild(document.getElementsByTagName(""link"")[0]); } while (head.getElementsByTagName(""script"").length > 0) { head.removeChild(document.getElementsByTagName(""script"")[0]); } while (head.getElementsByTagName(""style"").length > 0) { head.removeChild(document.getElementsByTagName(""style"")[0]); } if (document.body) {document.body.innerHTML = """" ;}} function getContent() { return document.getElementsByTagName(""head"")[0].innerHTML; } " }); if (browser.Document.Body != null) { browser.Document.Body.AppendChild(htEl); } browser.Document.InvokeScript("modContent"); } htEl = browser.Document.CreateElement("script"); if (htEl != null) { htEl.SetAttribute("type", "text/javascript"); Type t = htEl.DomElement.GetType(); t.InvokeMember("text", BindingFlags.SetProperty, null, htEl.DomElement, new object[] { "function addGoogle() { var sc = document.createElement(\"SCRIPT\"); sc.type=\"text/javascript\"; sc.src=\"" + googleURL + "\";document.body.appendChild(sc);}" }); if (browser.Document.Body != null) { browser.Document.Body.AppendChild(htEl); } } htEl = browser.Document.CreateElement("script"); if (htEl != null) { htEl.SetAttribute("type", "text/javascript"); Type t = htEl.DomElement.GetType(); t.InvokeMember("text", BindingFlags.SetProperty, null, htEl.DomElement, new object[] { "baseLayer = \"google.maps.MapTypeId." + MapType + "\";" + getOpenLayersCode() }); if (browser.Document.Body != null) { browser.Document.Body.AppendChild(htEl); } } htEl = browser.Document.CreateElement("script"); if (htEl != null) { htEl.SetAttribute("type", "text/javascript"); Type t = htEl.DomElement.GetType(); t.InvokeMember("text", BindingFlags.SetProperty, null, htEl.DomElement, new object[] { getWrapperCode() }); if (browser.Document.Body != null) { browser.Document.Body.AppendChild(htEl); } } htEl = browser.Document.CreateElement("style"); if (htEl != null) { var htmlDocument2 = browser.Document.DomDocument as IHTMLDocument2; if (htmlDocument2 != null) { IHTMLStyleSheet styleSheet = htmlDocument2.createStyleSheet("", 0); styleSheet.cssText = "BODY { margin: 0px; padding: 0px;} #map { width: 600px; height: 400px; border: 0px;}"; } browser.Document.GetElementsByTagName("head")[0].AppendChild(htEl); } htEl = browser.Document.CreateElement("div"); if (htEl != null) { htEl.Id = "map"; if (browser.Document.Body != null) { browser.Document.Body.AppendChild(htEl); } } } browser.Document.InvokeScript("addGoogle"); ThreadPool.QueueUserWorkItem(delegate { object res = null; if (m_logger.IsDebugEnabled) { m_logger.Debug("Starting detection of initcomplete"); } do { try { browser.Invoke(new MethodInvoker(delegate { res = browser.Document.InvokeScript("isLoaded"); })); if (!(res is bool && (bool)res)) { Thread.Sleep(100); } } catch { Thread.Sleep(100); } } while (m_appContext != null && !(res is bool && (bool)res)); if (m_appContext != null) { m_haveInited = true; UpdateURLTemplates(); if (m_logger.IsDebugEnabled) { m_logger.Debug("init is complete"); } } else { if (m_logger.IsDebugEnabled) { m_logger.Debug("AppContext Destroyed before init"); } } }); } }
public KanColleBrowser() { InitializeComponent(); WebBrowser.Navigated += (_, __) => ApplyZoomFactor(zoomFactor); WebBrowser.LoadCompleted += (_, __) => LockFlash(IsFlashLocked); SetSilence(true); SetAllowDrop(false); //btnBack.Click += (_, __) => WebBrowser.GoBack(); //btnFoward.Click += (_, __) => WebBrowser.GoForward(); GotoUrlCommand = new DelegateCommand(() => { if (!txtAddress.Text.Contains(":")) { txtAddress.Text = "http://" + txtAddress.Text; } try { WebBrowser.Navigate(txtAddress.Text); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } }); btnRefresh.Click += (_, __) => WebBrowser.Navigate(WebBrowser.Source); btnBackToGame.Click += (_, __) => WebBrowser.Navigate(Properties.Settings.Default.GameUrl); btnStop.Click += (_, __) => Stop(); WebBrowser.Navigating += (_, e) => { txtAddress.Text = e.Uri.AbsoluteUri; //btnBack.IsEnabled = WebBrowser.CanGoBack; //btnFoward.IsEnabled = WebBrowser.CanGoForward; styleSheet = null; UpdateSize(false); }; btnScreenShot.Click += (_, __) => TakeScreenShot(Config.Current.GenerateScreenShotFileName()); btnCleanCache.Click += async(sender, _) => { var button = sender as Button; button.IsEnabled = false; if (MessageBox.Show(StringTable.CleanCache_Alert, "", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) == MessageBoxResult.Yes) { if (await WinInetHelper.DeleteInternetCacheAsync()) { MessageBox.Show(StringTable.CleanCache_Success); } else { MessageBox.Show(StringTable.CleanCache_Fail); } } button.IsEnabled = true; }; this.Loaded += (_, __) => { if (firstLoad && Officer.Staff.IsStarted) { var url = Config.Current.OverrideGameUrl; if (string.IsNullOrWhiteSpace(url)) { url = Properties.Settings.Default.GameUrl; } WebBrowser.Navigate(url); firstLoad = false; } }; }