From 36ab52af0714daae25d88a757c1622ce01763e36 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Wed, 5 Oct 2022 15:19:05 +0530 Subject: Allow custom recipe to trapLinks and open them within Ferdium --- recipes/franz-custom-website/package.json | 2 +- recipes/franz-custom-website/webview.js | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'recipes/franz-custom-website') diff --git a/recipes/franz-custom-website/package.json b/recipes/franz-custom-website/package.json index d9f9f70..d3dcbba 100644 --- a/recipes/franz-custom-website/package.json +++ b/recipes/franz-custom-website/package.json @@ -1,7 +1,7 @@ { "id": "franz-custom-website", "name": "Custom Website", - "version": "1.2.0", + "version": "1.3.0", "license": "MIT", "repository": "https://github.com/meetfranz/recipe-custom-website", "config": { diff --git a/recipes/franz-custom-website/webview.js b/recipes/franz-custom-website/webview.js index afe3605..072fed5 100644 --- a/recipes/franz-custom-website/webview.js +++ b/recipes/franz-custom-website/webview.js @@ -4,6 +4,27 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -module.exports = Ferdium => { +module.exports = (Ferdium, settings) => { Ferdium.injectCSS(_path.default.join(__dirname, 'style.css')); + + // TODO: See how this can be moved into the main ferdium app and sent as an ipc message for opening with a new window or same Ferdium recipe's webview based on user's preferences + document.addEventListener('click', event => { + const link = event.target.closest('a[href^="http"]'); + const button = event.target.closest('button[title^="http"]'); + + if (link || button) { + const url = link ? link.getAttribute('href') : button.getAttribute('title'); + + if (!Ferdium.isImage(link)) { + event.preventDefault(); + event.stopPropagation(); + + if (settings.trapLinkClicks === true) { + window.location.href = url; + } else { + Ferdium.openNewWindow(url); + } + } + } + }, true); }; -- cgit v1.2.3-54-g00ecf