aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/instagram/webview.js
diff options
context:
space:
mode:
Diffstat (limited to 'recipes/instagram/webview.js')
-rw-r--r--recipes/instagram/webview.js39
1 files changed, 35 insertions, 4 deletions
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
5const _path = _interopRequireDefault(require('path')); 5const _path = _interopRequireDefault(require('path'));
6 6
7module.exports = Ferdium => { 7module.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);