From ba8325ad8dffb42c500ea2cb27a44696ecbf7b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Apr 2016 02:08:15 +0200 Subject: [PATCH] webframe: add context menu on links to open or copy their location --- webframe.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/webframe.js b/webframe.js index 6ede79b..c3157c7 100644 --- a/webframe.js +++ b/webframe.js @@ -11,3 +11,31 @@ window._zoomOut = function () { window._zoomActualSize = function() { webFrame.setZoomFactor(1); }; + +var remote = require('remote'); +var Menu = remote.require('menu'); +var MenuItem = remote.require('menu-item'); +var linkMenu = new Menu(); + +linkMenu.append(new MenuItem({ + label: 'Open Link', + accelerator: 'CommandOrControl+O', + click: function (evt) { + window.open(document.activeElement.href); + } +})); + +linkMenu.append(new MenuItem({ + label: 'Copy Link', + accelerator: 'CommandOrControl+C', + click: function (evt) { + require('electron').clipboard.writeText(document.activeElement.href); + } +})); + +window.addEventListener('contextmenu', function (event) { + if (document.activeElement.tagName == 'A' && document.activeElement.href.length > 0) { + event.preventDefault(); + linkMenu.popup(remote.getCurrentWindow()); + } +}, false);