public PluginResult OnTriggered(PluginTriggerEventArgs e) { DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo"); dde.Connect(); string result = dde.Request("URL", 1000); dde.Disconnect(); // Result string is in the format "uri", "title", ... var parts = result.Trim('"').Split(new string[] { "\",\"" }, StringSplitOptions.None); string url = parts[0].Replace("\\\"", "\""); string name = parts[1].Replace("\\\"", "\""); return(PluginResult.FromUrl(url, name)); }
public PluginResult OnTriggered(PluginTriggerEventArgs e) { DdeClient dde = new DdeClient("Opera", "WWW_GetWindowInfo"); dde.Connect(); string result = dde.Request("URL", 1000); dde.Disconnect(); // Result string is in the format "url", "Opera - [title]", ... var parts = result.Trim('"').Split(new string[] { "\",\"" }, StringSplitOptions.None); string url = parts[0].Replace("\\\"", "\""); string name = Regex.Match(parts[1], @"Opera - \[(.*?)\]").Groups[1].Value.Replace("\\\"", "\""); return(PluginResult.FromUrl(url, name)); }
public PluginResult OnTriggered(PluginTriggerEventArgs e) { var windowElm = AutomationElement.FromHandle(e.Handle); var omniboxElm = windowElm.FindFirst( TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar")); // Omnibox contents can be changed at any time, so it's not the most reliable. But it's the only thing available var omniboxValuePattern = (ValuePattern)omniboxElm.GetCurrentPattern(ValuePattern.Pattern); string omniboxText = omniboxValuePattern.Current.Value; // The Omnibox drops "http://" off URLs if that's the protocol of the URL if (!Uri.IsWellFormedUriString(omniboxText, UriKind.Absolute)) { omniboxText = "http://" + omniboxText; if (!Uri.IsWellFormedUriString(omniboxText, UriKind.Absolute)) { return(null); } } // The tab window's title gives the page's title // Chrome's automation stuff doesn't seem to give any indicators as to which one's active // so look for one that's a substring of the window title string windowTitle = (string)windowElm.GetCurrentPropertyValue(AutomationElement.NameProperty); var tabElms = windowElm.FindAll( TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem)); string currentTabTitle = omniboxText; foreach (var tabElm in tabElms.Cast <AutomationElement>()) { string tabTitle = (string)tabElm.GetCurrentPropertyValue(AutomationElement.NameProperty); if (windowTitle.Contains(tabTitle)) { currentTabTitle = tabTitle; } } return(PluginResult.FromUrl(omniboxText, currentTabTitle)); }