From b92f4cda81630746610d9b09e4fc24dc9dc3853c Mon Sep 17 00:00:00 2001 From: Vijay A Date: Mon, 10 Oct 2022 11:29:51 +0530 Subject: Telegram links can open within Ferdium instead of default browser --- recipes/telegram/package.json | 2 +- recipes/telegram/webview.js | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'recipes/telegram') diff --git a/recipes/telegram/package.json b/recipes/telegram/package.json index f873bb6..80bed06 100644 --- a/recipes/telegram/package.json +++ b/recipes/telegram/package.json @@ -1,7 +1,7 @@ { "id": "telegram", "name": "Telegram", - "version": "3.3.4", + "version": "3.3.5", "license": "MIT", "config": { "serviceURL": "https://web.telegram.org", 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) { return obj && obj.__esModule ? obj : { default: obj }; } -module.exports = Ferdium => { +module.exports = (Ferdium, settings) => { const telegramVersion = document .querySelector('meta[property="og:url"]') ?.getAttribute('content'); @@ -82,4 +82,25 @@ module.exports = Ferdium => { Ferdium.loop(loopFunc); Ferdium.injectCSS(_path.default.join(__dirname, 'service.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-70-g09d2