diff options
author | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2023-07-26 16:35:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-26 22:05:49 +0530 |
commit | f9e2d9926e4dff14df0f13858a9c695e2118a94e (patch) | |
tree | 53f1cad4edde7436fa521deb002e14830809bb8b /recipes/telegram/webview.js | |
parent | chore: improve lint setup (#397) (diff) | |
download | ferdium-recipes-f9e2d9926e4dff14df0f13858a9c695e2118a94e.tar.gz ferdium-recipes-f9e2d9926e4dff14df0f13858a9c695e2118a94e.tar.zst ferdium-recipes-f9e2d9926e4dff14df0f13858a9c695e2118a94e.zip |
Improve lint setup (#400)
* Use strict configuration of node/npm/pnpm
* When generating a new recipe, string replace should handle all placeholders in a single file
Diffstat (limited to 'recipes/telegram/webview.js')
-rw-r--r-- | recipes/telegram/webview.js | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/recipes/telegram/webview.js b/recipes/telegram/webview.js index 5a12adb..5126e7d 100644 --- a/recipes/telegram/webview.js +++ b/recipes/telegram/webview.js | |||
@@ -2,10 +2,12 @@ function _interopRequireDefault(obj) { | |||
2 | return obj && obj.__esModule ? obj : { default: obj }; | 2 | return obj && obj.__esModule ? obj : { default: obj }; |
3 | } | 3 | } |
4 | 4 | ||
5 | const _path = _interopRequireDefault(require('path')); | 5 | const _path = _interopRequireDefault(require('path')); |
6 | 6 | ||
7 | module.exports = (Ferdium, settings) => { | 7 | module.exports = (Ferdium, settings) => { |
8 | const telegramVersion = document.querySelector('meta[property="og:url"]')?.getAttribute('content'); | 8 | const telegramVersion = document |
9 | .querySelector('meta[property="og:url"]') | ||
10 | ?.getAttribute('content'); | ||
9 | 11 | ||
10 | const isWebK = telegramVersion?.includes('/k/'); | 12 | const isWebK = telegramVersion?.includes('/k/'); |
11 | 13 | ||
@@ -67,7 +69,9 @@ module.exports = (Ferdium, settings) => { | |||
67 | const getActiveDialogTitle = () => { | 69 | const getActiveDialogTitle = () => { |
68 | let element; | 70 | let element; |
69 | 71 | ||
70 | element = isWebK ? document.querySelector('.top .peer-title') : document.querySelector('.chat-list .ListItem .title > h3'); | 72 | element = isWebK |
73 | ? document.querySelector('.top .peer-title') | ||
74 | : document.querySelector('.chat-list .ListItem .title > h3'); | ||
71 | 75 | ||
72 | Ferdium.setDialogTitle(element ? element.textContent : ''); | 76 | Ferdium.setDialogTitle(element ? element.textContent : ''); |
73 | }; | 77 | }; |
@@ -82,27 +86,33 @@ module.exports = (Ferdium, settings) => { | |||
82 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); | 86 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); |
83 | 87 | ||
84 | // 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 | 88 | // 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 |
85 | document.addEventListener('click', event => { | 89 | document.addEventListener( |
86 | const link = event.target.closest('a[href^="http"]'); | 90 | 'click', |
87 | const button = event.target.closest('button[title^="http"]'); | 91 | event => { |
88 | 92 | const link = event.target.closest('a[href^="http"]'); | |
89 | if (link || button) { | 93 | const button = event.target.closest('button[title^="http"]'); |
90 | const url = link ? link.getAttribute('href') : button.getAttribute('title'); | 94 | |
91 | 95 | if (link || button) { | |
92 | if (!Ferdium.isImage(link)) { | 96 | const url = link |
93 | event.preventDefault(); | 97 | ? link.getAttribute('href') |
94 | event.stopPropagation(); | 98 | : button.getAttribute('title'); |
95 | 99 | ||
96 | if ( | 100 | if (!Ferdium.isImage(link)) { |
97 | settings.trapLinkClicks === true | 101 | event.preventDefault(); |
98 | || url.includes('t.me') | 102 | event.stopPropagation(); |
99 | || url.includes('web.telegram.org') | 103 | |
100 | ) { | 104 | if ( |
101 | window.location.href = url; | 105 | settings.trapLinkClicks === true || |
102 | } else { | 106 | url.includes('t.me') || |
103 | Ferdium.openNewWindow(url); | 107 | url.includes('web.telegram.org') |
108 | ) { | ||
109 | window.location.href = url; | ||
110 | } else { | ||
111 | Ferdium.openNewWindow(url); | ||
112 | } | ||
104 | } | 113 | } |
105 | } | 114 | } |
106 | } | 115 | }, |
107 | }, true); | 116 | true, |
117 | ); | ||
108 | }; | 118 | }; |