diff options
author | René Bertin <rjvbertin@gmail.com> | 2023-10-11 18:40:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 17:40:49 +0100 |
commit | 2eb47c6d973c9ef1cb277fc22f4d15208e94f3c0 (patch) | |
tree | ad9a47e780e2375227c8201d96b7e2f997cd3abf | |
parent | Fix TheLounge sending notifications for muted channels (#435) (diff) | |
download | ferdium-recipes-2eb47c6d973c9ef1cb277fc22f4d15208e94f3c0.tar.gz ferdium-recipes-2eb47c6d973c9ef1cb277fc22f4d15208e94f3c0.tar.zst ferdium-recipes-2eb47c6d973c9ef1cb277fc22f4d15208e94f3c0.zip |
Ensure that links are opened according to the user's preference (#417)
* Ensure that links are opened according to the user's preference
This fixes the problem that certain links on instagram.com have started
to open in the external browser.
Also fixes an occasional nullptr dereference in getMessages().
Fixes: https://github.com/ferdium/ferdium-app/issues/1304
* Version bump for PR#417
* attempt to fix build by bumping recipe version again
* Fix lint and CI
* Fix versioning
---------
Co-authored-by: MCMXC <16797721+mcmxcdev@users.noreply.github.com>
Co-authored-by: André Oliveira <oliveira.andrerodrigues95@gmail.com>
-rw-r--r-- | recipes/instagram/package.json | 2 | ||||
-rw-r--r-- | recipes/instagram/webview.js | 39 |
2 files changed, 36 insertions, 5 deletions
diff --git a/recipes/instagram/package.json b/recipes/instagram/package.json index 5c798f3..9bdc70b 100644 --- a/recipes/instagram/package.json +++ b/recipes/instagram/package.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "id": "instagram", | 2 | "id": "instagram", |
3 | "name": "Instagram", | 3 | "name": "Instagram", |
4 | "version": "2.5.0", | 4 | "version": "2.5.1", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "serviceURL": "https://instagram.com/direct/inbox", | 7 | "serviceURL": "https://instagram.com/direct/inbox", |
diff --git a/recipes/instagram/webview.js b/recipes/instagram/webview.js index a4a5a8a..1b35c37 100644 --- a/recipes/instagram/webview.js +++ b/recipes/instagram/webview.js | |||
@@ -4,12 +4,43 @@ function _interopRequireDefault(obj) { | |||
4 | 4 | ||
5 | const _path = _interopRequireDefault(require('path')); | 5 | const _path = _interopRequireDefault(require('path')); |
6 | 6 | ||
7 | module.exports = Ferdium => { | 7 | module.exports = (Ferdium, settings) => { |
8 | // adapted from the franz-custom-website recipe, for opening | ||
9 | // links according to the user's preference (Ferdium/ext.browser) | ||
10 | document.addEventListener( | ||
11 | 'click', | ||
12 | event => { | ||
13 | const link = event.target.closest('a'); | ||
14 | const button = event.target.closest('button'); | ||
15 | |||
16 | if (link || button) { | ||
17 | const url = link | ||
18 | ? link.getAttribute('href') | ||
19 | : button.getAttribute('title'); | ||
20 | |||
21 | // check if we have a valid URL that is not a script nor an image: | ||
22 | if (url && url !== '#' && !Ferdium.isImage(link)) { | ||
23 | event.preventDefault(); | ||
24 | event.stopPropagation(); | ||
25 | |||
26 | if (settings.trapLinkClicks === true) { | ||
27 | window.location.href = url; | ||
28 | } else { | ||
29 | Ferdium.openNewWindow(url); | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | }, | ||
34 | true, | ||
35 | ); | ||
36 | |||
8 | const getMessages = () => { | 37 | const getMessages = () => { |
9 | const element = document.querySelector('a[href^="/direct/inbox"]'); | 38 | const element = document.querySelector('a[href^="/direct/inbox"]'); |
10 | Ferdium.setBadge( | 39 | if (element) { |
11 | element.textContent ? Ferdium.safeParseInt(element.textContent) : 0, | 40 | Ferdium.setBadge( |
12 | ); | 41 | element.textContent ? Ferdium.safeParseInt(element.textContent) : 0, |
42 | ); | ||
43 | } | ||
13 | }; | 44 | }; |
14 | 45 | ||
15 | Ferdium.loop(getMessages); | 46 | Ferdium.loop(getMessages); |