diff options
author | 2022-10-10 11:29:51 +0530 | |
---|---|---|
committer | 2022-10-10 11:48:49 +0530 | |
commit | b92f4cda81630746610d9b09e4fc24dc9dc3853c (patch) | |
tree | c7df46992bf0890032dc19077d07b71b5462d432 /recipes/telegram/webview.js | |
parent | Kimai recipe now has the option for a custom domain (diff) | |
download | ferdium-recipes-b92f4cda81630746610d9b09e4fc24dc9dc3853c.tar.gz ferdium-recipes-b92f4cda81630746610d9b09e4fc24dc9dc3853c.tar.zst ferdium-recipes-b92f4cda81630746610d9b09e4fc24dc9dc3853c.zip |
Telegram links can open within Ferdium instead of default browser
Diffstat (limited to 'recipes/telegram/webview.js')
-rw-r--r-- | recipes/telegram/webview.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/recipes/telegram/webview.js b/recipes/telegram/webview.js index 544a573..288160a 100644 --- a/recipes/telegram/webview.js +++ b/recipes/telegram/webview.js | |||
@@ -4,7 +4,7 @@ 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 | const telegramVersion = document | 8 | const telegramVersion = document |
9 | .querySelector('meta[property="og:url"]') | 9 | .querySelector('meta[property="og:url"]') |
10 | ?.getAttribute('content'); | 10 | ?.getAttribute('content'); |
@@ -82,4 +82,25 @@ module.exports = Ferdium => { | |||
82 | Ferdium.loop(loopFunc); | 82 | Ferdium.loop(loopFunc); |
83 | 83 | ||
84 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); | 84 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); |
85 | |||
86 | // 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 | ||
87 | document.addEventListener('click', event => { | ||
88 | const link = event.target.closest('a[href^="http"]'); | ||
89 | const button = event.target.closest('button[title^="http"]'); | ||
90 | |||
91 | if (link || button) { | ||
92 | const url = link ? link.getAttribute('href') : button.getAttribute('title'); | ||
93 | |||
94 | if (!Ferdium.isImage(link)) { | ||
95 | event.preventDefault(); | ||
96 | event.stopPropagation(); | ||
97 | |||
98 | if (settings.trapLinkClicks === true) { | ||
99 | window.location.href = url; | ||
100 | } else { | ||
101 | Ferdium.openNewWindow(url); | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | }, true); | ||
85 | }; | 106 | }; |