diff options
author | 2022-10-05 15:19:05 +0530 | |
---|---|---|
committer | 2022-10-05 15:21:52 +0530 | |
commit | 36ab52af0714daae25d88a757c1622ce01763e36 (patch) | |
tree | 750867f8fad95aa80bdc32007ef87790112f6fe7 /recipes/franz-custom-website/webview.js | |
parent | recipes: add initial SimpleLogin service (diff) | |
download | ferdium-recipes-36ab52af0714daae25d88a757c1622ce01763e36.tar.gz ferdium-recipes-36ab52af0714daae25d88a757c1622ce01763e36.tar.zst ferdium-recipes-36ab52af0714daae25d88a757c1622ce01763e36.zip |
Allow custom recipe to trapLinks and open them within Ferdium
Diffstat (limited to 'recipes/franz-custom-website/webview.js')
-rw-r--r-- | recipes/franz-custom-website/webview.js | 23 |
1 files changed, 22 insertions, 1 deletions
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) { | |||
4 | return obj && obj.__esModule ? obj : { default: obj }; | 4 | return obj && obj.__esModule ? obj : { default: obj }; |
5 | } | 5 | } |
6 | 6 | ||
7 | module.exports = Ferdium => { | 7 | module.exports = (Ferdium, settings) => { |
8 | Ferdium.injectCSS(_path.default.join(__dirname, 'style.css')); | 8 | Ferdium.injectCSS(_path.default.join(__dirname, 'style.css')); |
9 | |||
10 | // 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 | ||
11 | document.addEventListener('click', event => { | ||
12 | const link = event.target.closest('a[href^="http"]'); | ||
13 | const button = event.target.closest('button[title^="http"]'); | ||
14 | |||
15 | if (link || button) { | ||
16 | const url = link ? link.getAttribute('href') : button.getAttribute('title'); | ||
17 | |||
18 | if (!Ferdium.isImage(link)) { | ||
19 | event.preventDefault(); | ||
20 | event.stopPropagation(); | ||
21 | |||
22 | if (settings.trapLinkClicks === true) { | ||
23 | window.location.href = url; | ||
24 | } else { | ||
25 | Ferdium.openNewWindow(url); | ||
26 | } | ||
27 | } | ||
28 | } | ||
29 | }, true); | ||
9 | }; | 30 | }; |