void Logo_OnClick(IHTMLEventObj e) { try { IHTMLDOMNode plugin = (IHTMLDOMNode)e.srcElement.parentElement.parentElement; Data data = new Data(plugin); Utils.WriteToFile(Utils.PluginFileName, data.GetAsASingleLine()); bool alreadyOpened = false; if (e.srcElement.getAttribute("alreadyopened", 0).ToString() == "true") { alreadyOpened = true; } // try to find an opened tab with the same url int foundAlreadyOpened = -1; string toOpenDomain = Utils.GetDomain(data.url); List<String> openedUrls = tabs.GetTabUrls((IntPtr)ieInstance.HWND); int i = 0; foreach (string openedUrl in openedUrls) { string openDomain = Utils.GetDomain(openedUrl); if (toOpenDomain.Equals(openDomain)) { foundAlreadyOpened = i; break; } i++; } // when already opened and found the tab index, just activate it. if (alreadyOpened) { if (foundAlreadyOpened >= 0) { tabs.ActivateTab((IntPtr)ieInstance.HWND, foundAlreadyOpened); return; } else { e.srcElement.setAttribute("alreadyopened", "false", 0); } } else { // found a tab with same url but not opened, must warm the user before opening a new one if (foundAlreadyOpened >= 0) { //if (System.Windows.Forms.MessageBox.Show("Existe un sitio abierto para " + data.title + ". Desea cerrarlo y continuar?.", "", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) if (System.Windows.Forms.MessageBox.Show("Existe un sitio abierto para '" + Utils.GetDomain(data.url) + "'. Desea cerrarlo y continuar?.", "", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { foreach (IHTMLElement htmlElement in document.getElementsByTagName("IMG")) { if (htmlElement.className == "remote_site_logo") { IHTMLDOMNode tPlugin = (IHTMLDOMNode)htmlElement.parentElement.parentElement; Data tData = new Data(tPlugin); if (Utils.GetDomain(tData.url) == Utils.GetDomain(data.url)) { htmlElement.setAttribute("alreadyopened", "false", 0); } } } tabs.ActivateTab((IntPtr)ieInstance.HWND, foundAlreadyOpened); string activeTabText = tabs.GetActiveTabCaption((IntPtr)ieInstance.HWND); tabs.CloseTab((IntPtr)ieInstance.HWND, activeTabText); Thread.Sleep(500); } else { return; } } } // deletes cookies for current site before trying the login process (avoid the keep me logging fail) try { string cachePatternUrl = Cookies.SetupCookieCachePattern(data.url); System.Collections.ArrayList results = Cookies.FindUrlCacheEntries(cachePatternUrl); Cookies.Delete(results); results = Cookies.FindUrlCacheEntries(cachePatternUrl.Replace(@"*www\.", "")); Cookies.Delete(results); results = Cookies.FindUrlCacheEntries(cachePatternUrl.Replace(@"*www\.", "*.")); Cookies.Delete(results); /* cachePatternUrl = Cookies.SetupCookieCachePattern(data.url).Replace(@"Cookie:", @"Visited:"); results = Cookies.FindUrlCacheEntries(cachePatternUrl); Cookies.Delete(results); results = Cookies.FindUrlCacheEntries(cachePatternUrl.Replace(@"*www\.", "")); Cookies.Delete(results); results = Cookies.FindUrlCacheEntries(cachePatternUrl.Replace(@"*www\.", "*.")); Cookies.Delete(results); */ } catch (Exception ee) { Utils.l(ee); } // mark this "logo" as opened e.srcElement.setAttribute("alreadyopened", "true", 0); object Empty = ""; object oFlags; object urlRedir = ""; oFlags = 2048; //navOpenInNewTab urlRedir = data.url; this.ieInstance.Navigate2(ref urlRedir, ref oFlags, ref Empty, ref Empty, ref Empty); } catch (Exception ex) { Utils.l(ex); } }
private void bind() { try { string line = Utils.ReadFromFile(Utils.PluginFileName); if (!string.IsNullOrEmpty(line)) { Data data = new Data(line); HTMLInputElement usernameElement = (HTMLInputElement)FindElement(data.usernameField); if (usernameElement == null) { // Utils.l("No es posible encontrar el campo Usuario."); return; } else { usernameElement.value = data.username; } HTMLInputElement passwordElement = (HTMLInputElement)FindElement(data.passwordField); if (usernameElement == null) { // Utils.l("No es posible encontrar el campo Clave."); return; } else { passwordElement.value = data.password; } try { IHTMLElement submitElement = FindElement(data.submitField); if (submitElement == null) { // Utils.l("No es posible encontrar el elemento Enter."); return; } // try c# click try { submitElement.click(); } catch (Exception eee) { } // sleep and the try js click Thread.Sleep(2000); // try js click string prevId = submitElement.id; submitElement.id = "1000Pass_submit_id"; IHTMLElementCollection iframes = (IHTMLElementCollection)this.document.getElementsByTagName("iframe"); IHTMLElementCollection frames = (IHTMLElementCollection)this.document.getElementsByTagName("frame"); if (iframes.length > 0) { foreach (IHTMLElement frm in iframes) { HTMLDocument doc = (HTMLDocument)((SHDocVw.IWebBrowser2)frm).Document; doc.parentWindow.execScript("var element = document.getElementById('1000Pass_submit_id');if(element != null){try{element.click();}catch(e){}}", "javascript"); } } else if (frames.length > 0) { foreach (IHTMLElement frm in frames) { HTMLDocument doc = (HTMLDocument)((SHDocVw.IWebBrowser2)frm).Document; doc.parentWindow.execScript("var element = document.getElementById('1000Pass_submit_id');if(element != null){try{element.click();}catch(e){}}", "javascript"); } } else { this.document.parentWindow.execScript("var element = document.getElementById('1000Pass_submit_id');if(element != null){try{element.click();}catch(e){}}", "javascript"); } // leave the element as it was before submitElement.id = prevId; } catch (Exception eee) { Utils.l(eee); } } // delete plugin info when finish the binding Utils.WriteToFile(Utils.PluginFileName, ""); } catch (Exception e) { Utils.l(e); } }