1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-01 08:34:11 +02:00

Bypass t.co links in context menu and hide url options for # links

This commit is contained in:
chylex 2016-04-24 22:13:48 +02:00
parent c5b3bc1a0b
commit 2a1dc8beab
4 changed files with 35 additions and 6 deletions

View File

@ -14,7 +14,7 @@ abstract class ContextMenuBase : IContextMenuHandler{
public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){ public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){
RemoveSeparatorIfLast(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)MenuOpenUrlInBrowser,"Open in browser");
model.AddItem((CefMenuCommand)MenuCopyUrl,"Copy link address"); model.AddItem((CefMenuCommand)MenuCopyUrl,"Copy link address");
model.AddSeparator(); model.AddSeparator();
@ -35,7 +35,7 @@ public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser br
break; break;
case MenuCopyUrl: case MenuCopyUrl:
Clipboard.SetText(parameters.UnfilteredLinkUrl,TextDataFormat.UnicodeText); Clipboard.SetText(string.IsNullOrEmpty(TweetDeckBridge.LastRightClickedLink) ? parameters.UnfilteredLinkUrl : TweetDeckBridge.LastRightClickedLink,TextDataFormat.UnicodeText);
break; break;
case MenuOpenImageInBrowser: case MenuOpenImageInBrowser:

View File

@ -2,6 +2,8 @@
namespace TweetDck.Core.Handling{ namespace TweetDck.Core.Handling{
class TweetDeckBridge{ class TweetDeckBridge{
public static string LastRightClickedLink = string.Empty;
private readonly FormBrowser form; private readonly FormBrowser form;
public string BrandName{ public string BrandName{
@ -44,6 +46,12 @@ public void LoadNotificationHeadContents(string headContents){
}); });
} }
public void SetLastRightClickedLink(string link){
form.InvokeSafe(() => {
LastRightClickedLink = link;
});
}
public void OpenSettingsMenu(){ public void OpenSettingsMenu(){
form.InvokeSafe(() => { form.InvokeSafe(() => {
form.OpenSettings(); form.OpenSettings();

View File

@ -178,7 +178,7 @@
})(); })();
// //
// Block: Expand shortened links. // Block: Expand shortened links on hover.
// //
(function(){ (function(){
var cutStart = function(str, search){ var cutStart = function(str, search){
@ -188,7 +188,7 @@
$(document.body).delegate("a[data-full-url]","mouseenter mouseleave",function(e){ $(document.body).delegate("a[data-full-url]","mouseenter mouseleave",function(e){
var me = $(this); var me = $(this);
if (e.type == "mouseenter"){ if (e.type === "mouseenter"){
var text = me.text(); var text = me.text();
if (text.charCodeAt(text.length-1) !== 8230){ // horizontal ellipsis if (text.charCodeAt(text.length-1) !== 8230){ // horizontal ellipsis
@ -204,7 +204,7 @@
me.attr("td-prev-text",text); me.attr("td-prev-text",text);
me.text(expanded); me.text(expanded);
} }
else{ else if (e.type === "mouseleave"){
var prevText = me.attr("td-prev-text"); var prevText = me.attr("td-prev-text");
if (prevText){ 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 // Block: Hook into mp4 video element clicking
// //

View File

@ -1,6 +1,6 @@
(function($TD){ (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){ document.body.addEventListener("click",function(e){
if (e.target.tagName == "A"){ if (e.target.tagName == "A"){
@ -8,4 +8,18 @@
e.preventDefault(); 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); })($TD);