diff --git a/Core/Handling/ContextMenuBase.cs b/Core/Handling/ContextMenuBase.cs index af5b2537..c4259ed1 100644 --- a/Core/Handling/ContextMenuBase.cs +++ b/Core/Handling/ContextMenuBase.cs @@ -14,7 +14,7 @@ abstract class ContextMenuBase : IContextMenuHandler{ public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){ RemoveSeparatorIfLast(model); - if (parameters.TypeFlags.HasFlag(ContextMenuType.Link)){ + if (parameters.TypeFlags.HasFlag(ContextMenuType.Link) && !parameters.UnfilteredLinkUrl.EndsWith("tweetdeck.twitter.com/#")){ model.AddItem((CefMenuCommand)MenuOpenUrlInBrowser,"Open in browser"); model.AddItem((CefMenuCommand)MenuCopyUrl,"Copy link address"); model.AddSeparator(); @@ -35,7 +35,7 @@ public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser br break; case MenuCopyUrl: - Clipboard.SetText(parameters.UnfilteredLinkUrl,TextDataFormat.UnicodeText); + Clipboard.SetText(string.IsNullOrEmpty(TweetDeckBridge.LastRightClickedLink) ? parameters.UnfilteredLinkUrl : TweetDeckBridge.LastRightClickedLink,TextDataFormat.UnicodeText); break; case MenuOpenImageInBrowser: diff --git a/Core/Handling/TweetDeckBridge.cs b/Core/Handling/TweetDeckBridge.cs index 37337f9f..ce1c8fb6 100644 --- a/Core/Handling/TweetDeckBridge.cs +++ b/Core/Handling/TweetDeckBridge.cs @@ -2,6 +2,8 @@ namespace TweetDck.Core.Handling{ class TweetDeckBridge{ + public static string LastRightClickedLink = string.Empty; + private readonly FormBrowser form; public string BrandName{ @@ -44,6 +46,12 @@ public void LoadNotificationHeadContents(string headContents){ }); } + public void SetLastRightClickedLink(string link){ + form.InvokeSafe(() => { + LastRightClickedLink = link; + }); + } + public void OpenSettingsMenu(){ form.InvokeSafe(() => { form.OpenSettings(); diff --git a/Resources/code.js b/Resources/code.js index a9de7efd..deaefd67 100644 --- a/Resources/code.js +++ b/Resources/code.js @@ -178,7 +178,7 @@ })(); // - // Block: Expand shortened links. + // Block: Expand shortened links on hover. // (function(){ var cutStart = function(str, search){ @@ -188,7 +188,7 @@ $(document.body).delegate("a[data-full-url]","mouseenter mouseleave",function(e){ var me = $(this); - if (e.type == "mouseenter"){ + if (e.type === "mouseenter"){ var text = me.text(); if (text.charCodeAt(text.length-1) !== 8230){ // horizontal ellipsis @@ -204,7 +204,7 @@ me.attr("td-prev-text",text); me.text(expanded); } - else{ + else if (e.type === "mouseleave"){ var prevText = me.attr("td-prev-text"); if (prevText){ @@ -214,6 +214,13 @@ }); })(); + // + // Block: Allow bypassing of t.co in context menus. + // + $(document.body).delegate("a","contextmenu",function(){ + $TD.setLastRightClickedLink($(this).attr("data-full-url") || ""); + }); + // // Block: Hook into mp4 video element clicking // diff --git a/Resources/notification.js b/Resources/notification.js index 711b3a11..45312aae 100644 --- a/Resources/notification.js +++ b/Resources/notification.js @@ -1,6 +1,6 @@ (function($TD){ // - // Block: Hook into links to bypass default open function + // Block: Hook into links to bypass default open function. // document.body.addEventListener("click",function(e){ if (e.target.tagName == "A"){ @@ -8,4 +8,18 @@ e.preventDefault(); } }); + + // + // Block: Allow bypassing of t.co in context menus. + // + document.body.addEventListener("contextmenu",function(e){ + var element = e.target; + + do{ + if (element.tagName == "A"){ + $TD.setLastRightClickedLink(element.getAttribute("data-full-url") || ""); + break; + } + }while((element = element.parentElement) != null); + }); })($TD); \ No newline at end of file