Exemplo n.º 1
0
        public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
        {
            if (!TwitterUtils.IsTweetDeckWebsite(frame) || browser.IsLoading)
            {
                lastHighlightedTweetAuthors   = StringUtils.EmptyArray;
                lastHighlightedTweetImageList = StringUtils.EmptyArray;
                ContextInfo = default(KeyValuePair <string, string>);
            }
            else
            {
                lastHighlightedTweetAuthors   = TweetDeckBridge.LastHighlightedTweetAuthorsArray;
                lastHighlightedTweetImageList = TweetDeckBridge.LastHighlightedTweetImagesArray;
            }

            bool hasTweetImage = IsImage;
            bool hasTweetVideo = IsVideo;

            string TextOpen(string name) => "Open " + name + " in browser";
            string TextCopy(string name) => "Copy " + name + " address";
            string TextSave(string name) => "Save " + name + " as...";

            if (parameters.TypeFlags.HasFlag(ContextMenuType.Link) && !parameters.UnfilteredLinkUrl.EndsWith("tweetdeck.twitter.com/#", StringComparison.Ordinal) && !hasTweetImage && !hasTweetVideo)
            {
                if (TwitterUtils.RegexAccount.IsMatch(parameters.UnfilteredLinkUrl))
                {
                    model.AddItem(MenuOpenLinkUrl, TextOpen("account"));
                    model.AddItem(MenuCopyLinkUrl, TextCopy("account"));
                    model.AddItem(MenuCopyUsername, "Copy account username");
                }
                else
                {
                    model.AddItem(MenuOpenLinkUrl, TextOpen("link"));
                    model.AddItem(MenuCopyLinkUrl, TextCopy("link"));
                }

                model.AddSeparator();
            }

            if (hasTweetVideo)
            {
                model.AddItem(MenuOpenMediaUrl, TextOpen("video"));
                model.AddItem(MenuCopyMediaUrl, TextCopy("video"));
                model.AddItem(MenuSaveMedia, TextSave("video"));
                model.AddSeparator();
            }
            else if ((parameters.TypeFlags.HasFlag(ContextMenuType.Media) && parameters.HasImageContents) || hasTweetImage)
            {
                model.AddItem(MenuViewImage, "View image in photo viewer");
                model.AddItem(MenuOpenMediaUrl, TextOpen("image"));
                model.AddItem(MenuCopyMediaUrl, TextCopy("image"));
                model.AddItem(MenuSaveMedia, TextSave("image"));

                if (lastHighlightedTweetImageList.Length > 1)
                {
                    model.AddItem(MenuSaveTweetImages, TextSave("all images"));
                }

                model.AddSeparator();
            }
        }
Exemplo n.º 2
0
 private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
 {
     if (e.Frame.IsMain && TwitterUtils.IsTweetDeckWebsite(e.Frame))
     {
         ScriptLoader.ExecuteFile(e.Frame, "update.js");
         Check(false);
     }
 }
Exemplo n.º 3
0
        private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
        {
            IFrame frame = e.Frame;

            if (frame.IsMain && TwitterUtils.IsTweetDeckWebsite(frame))
            {
                Ready?.Invoke(this, new PluginDispatchEventArgs(executor));
            }
        }
Exemplo n.º 4
0
        public void Register(IWebBrowser browser, PluginEnvironment environment, Control sync, bool asMainBrowser = false)
        {
            browser.FrameLoadEnd += (sender, args) => {
                IFrame frame = args.Frame;

                if (frame.IsMain && TwitterUtils.IsTweetDeckWebsite(frame))
                {
                    ExecutePlugins(frame, environment, sync);
                }
            };

            browser.RegisterAsyncJsObject("$TDP", bridge);

            if (asMainBrowser)
            {
                mainBrowser = browser;
            }
        }
Exemplo n.º 5
0
        public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
        {
            bool isSelecting = parameters.TypeFlags.HasFlag(ContextMenuType.Selection);
            bool isEditing   = parameters.TypeFlags.HasFlag(ContextMenuType.Editable);

            model.Remove(CefMenuCommand.Back);
            model.Remove(CefMenuCommand.Forward);
            model.Remove(CefMenuCommand.Print);
            model.Remove(CefMenuCommand.ViewSource);
            RemoveSeparatorIfLast(model);

            if (isSelecting)
            {
                if (isEditing)
                {
                    model.AddSeparator();
                    model.AddItem(MenuWriteApplyROT13, "Apply ROT13");
                }

                model.AddSeparator();
            }

            base.OnBeforeContextMenu(browserControl, browser, frame, parameters, model);

            if (isSelecting && !isEditing && TwitterUtils.IsTweetDeckWebsite(frame))
            {
                InsertSelectionSearchItem(model, MenuSearchInColumn, "Search in a column");
            }

            if (Context.Types.HasFlag(ContextInfo.ContextType.Chirp) && !isSelecting && !isEditing)
            {
                model.AddItem(MenuOpenTweetUrl, "Open tweet in browser");
                model.AddItem(MenuCopyTweetUrl, "Copy tweet address");
                model.AddItem(MenuScreenshotTweet, "Screenshot tweet to clipboard");

                if (!string.IsNullOrEmpty(Context.Chirp.QuoteUrl))
                {
                    model.AddSeparator();
                    model.AddItem(MenuOpenQuotedTweetUrl, "Open quoted tweet in browser");
                    model.AddItem(MenuCopyQuotedTweetUrl, "Copy quoted tweet address");
                }

                model.AddSeparator();
            }

            if (!isSelecting && !isEditing)
            {
                AddSeparator(model);

                IMenuModel globalMenu = model.Count == 0 ? model : model.AddSubMenu(MenuGlobal, Program.BrandName);

                globalMenu.AddItem(CefMenuCommand.Reload, TitleReloadBrowser);
                globalMenu.AddCheckItem(MenuMute, TitleMuteNotifications);
                globalMenu.SetChecked(MenuMute, Config.MuteNotifications);
                globalMenu.AddSeparator();

                globalMenu.AddItem(MenuSettings, TitleSettings);
                globalMenu.AddItem(MenuPlugins, TitlePlugins);
                globalMenu.AddItem(MenuAbout, TitleAboutProgram);

                AddDebugMenuItems(globalMenu);
            }

            RemoveSeparatorIfLast(model);

            form.InvokeAsyncSafe(form.AnalyticsFile.BrowserContextMenus.Trigger);
        }
Exemplo n.º 6
0
        public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
        {
            if (!TwitterUtils.IsTweetDeckWebsite(frame) || browser.IsLoading)
            {
                Context = TweetDeckBridge.ContextInfo.Reset();
            }
            else
            {
                Context = TweetDeckBridge.ContextInfo.Create(parameters);
            }

            if (parameters.TypeFlags.HasFlag(ContextMenuType.Selection) && !parameters.TypeFlags.HasFlag(ContextMenuType.Editable))
            {
                model.AddItem(MenuSearchInBrowser, "Search in browser");
                model.AddSeparator();
                model.AddItem(MenuReadApplyROT13, "Apply ROT13");
                model.AddSeparator();
            }

            string TextOpen(string name) => "Open " + name + " in browser";
            string TextCopy(string name) => "Copy " + name + " address";
            string TextSave(string name) => "Save " + name + " as...";

            if (Context.Types.HasFlag(ContextInfo.ContextType.Link) && !Context.UnsafeLinkUrl.EndsWith("tweetdeck.twitter.com/#", StringComparison.Ordinal))
            {
                if (TwitterUtils.RegexAccount.IsMatch(Context.UnsafeLinkUrl))
                {
                    model.AddItem(MenuOpenLinkUrl, TextOpen("account"));
                    model.AddItem(MenuCopyLinkUrl, TextCopy("account"));
                    model.AddItem(MenuCopyUsername, "Copy account username");
                }
                else
                {
                    model.AddItem(MenuOpenLinkUrl, TextOpen("link"));
                    model.AddItem(MenuCopyLinkUrl, TextCopy("link"));
                }

                model.AddSeparator();
            }

            if (Context.Types.HasFlag(ContextInfo.ContextType.Video))
            {
                model.AddItem(MenuOpenMediaUrl, TextOpen("video"));
                model.AddItem(MenuCopyMediaUrl, TextCopy("video"));
                model.AddItem(MenuSaveMedia, TextSave("video"));
                model.AddSeparator();
            }
            else if (Context.Types.HasFlag(ContextInfo.ContextType.Image) && Context.MediaUrl != TweetNotification.AppLogo.Url)
            {
                model.AddItem(MenuViewImage, "View image in photo viewer");
                model.AddItem(MenuOpenMediaUrl, TextOpen("image"));
                model.AddItem(MenuCopyMediaUrl, TextCopy("image"));
                model.AddItem(MenuSaveMedia, TextSave("image"));

                if (Context.Chirp.Images.Length > 1)
                {
                    model.AddItem(MenuSaveTweetImages, TextSave("all images"));
                }

                model.AddSeparator();
            }
        }
Exemplo n.º 7
0
        public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
        {
            model.Remove(CefMenuCommand.Back);
            model.Remove(CefMenuCommand.Forward);
            model.Remove(CefMenuCommand.Print);
            model.Remove(CefMenuCommand.ViewSource);
            RemoveSeparatorIfLast(model);

            if (parameters.TypeFlags.HasFlag(ContextMenuType.Selection))
            {
                if (parameters.TypeFlags.HasFlag(ContextMenuType.Editable))
                {
                    model.AddSeparator();
                    model.AddItem(MenuInputApplyROT13, "Apply ROT13");
                }

                model.AddSeparator();
            }

            base.OnBeforeContextMenu(browserControl, browser, frame, parameters, model);

            lastHighlightedTweetUrl = TweetDeckBridge.LastHighlightedTweetUrl;
            lastHighlightedQuoteUrl = TweetDeckBridge.LastHighlightedQuoteUrl;

            if (!TwitterUtils.IsTweetDeckWebsite(frame) || browser.IsLoading)
            {
                lastHighlightedTweetUrl = string.Empty;
                lastHighlightedQuoteUrl = string.Empty;
            }

            if (!string.IsNullOrEmpty(lastHighlightedTweetUrl) && (parameters.TypeFlags & (ContextMenuType.Editable | ContextMenuType.Selection)) == 0)
            {
                model.AddItem(MenuOpenTweetUrl, "Open tweet in browser");
                model.AddItem(MenuCopyTweetUrl, "Copy tweet address");
                model.AddItem(MenuScreenshotTweet, "Screenshot tweet to clipboard");

                if (!string.IsNullOrEmpty(lastHighlightedQuoteUrl))
                {
                    model.AddSeparator();
                    model.AddItem(MenuOpenQuotedTweetUrl, "Open quoted tweet in browser");
                    model.AddItem(MenuCopyQuotedTweetUrl, "Copy quoted tweet address");
                }

                model.AddSeparator();
            }

            if ((parameters.TypeFlags & (ContextMenuType.Editable | ContextMenuType.Selection)) == 0)
            {
                AddSeparator(model);

                IMenuModel globalMenu = model.Count == 0 ? model : model.AddSubMenu(MenuGlobal, Program.BrandName);

                globalMenu.AddItem(CefMenuCommand.Reload, TitleReloadBrowser);
                globalMenu.AddCheckItem(MenuMute, TitleMuteNotifications);
                globalMenu.SetChecked(MenuMute, Program.UserConfig.MuteNotifications);
                globalMenu.AddSeparator();

                globalMenu.AddItem(MenuSettings, TitleSettings);
                globalMenu.AddItem(MenuPlugins, TitlePlugins);
                globalMenu.AddItem(MenuAbout, TitleAboutProgram);

                if (HasDevTools)
                {
                    globalMenu.AddSeparator();
                    AddDebugMenuItems(globalMenu);
                }
            }

            RemoveSeparatorIfLast(model);

            form.InvokeAsyncSafe(() => form.TriggerAnalyticsEvent(AnalyticsFile.Event.BrowserContextMenu));
        }