diff options
Diffstat (limited to 'recipes/instagram')
-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); |