diff options
Diffstat (limited to 'recipes/gmail/webview.js')
-rw-r--r-- | recipes/gmail/webview.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/recipes/gmail/webview.js b/recipes/gmail/webview.js new file mode 100644 index 0000000..95d28e7 --- /dev/null +++ b/recipes/gmail/webview.js | |||
@@ -0,0 +1,31 @@ | |||
1 | const path = require("path"); | ||
2 | |||
3 | module.exports = (Franz) => { | ||
4 | // if the user is on gmail's landing page, go to the login page. | ||
5 | if (location.hostname == 'www.google.com' && location.href.includes("gmail/about/")) { | ||
6 | location.href = 'https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/'; | ||
7 | } | ||
8 | |||
9 | const getMessages = function getMessages() { | ||
10 | let count = 0; | ||
11 | |||
12 | if (document.getElementsByClassName('J-Ke n0').length > 0) { | ||
13 | if (document.getElementsByClassName('J-Ke n0')[0].getAttribute('aria-label') != null) { | ||
14 | count = parseInt(document.getElementsByClassName('J-Ke n0')[0].getAttribute('aria-label').replace(/[^0-9.]/g, ''), 10); | ||
15 | } | ||
16 | } | ||
17 | |||
18 | // Just incase we don't end up with a number, set it back to zero (parseInt can return NaN) | ||
19 | count = parseInt(count, 10); | ||
20 | if (isNaN(count)) { | ||
21 | count = 0; | ||
22 | } | ||
23 | |||
24 | // set Franz badge | ||
25 | Franz.setBadge(count); | ||
26 | }; | ||
27 | |||
28 | Franz.injectCSS(path.join(__dirname, 'service.css')); | ||
29 | // check for new messages every second and update Franz badge | ||
30 | Franz.loop(getMessages); | ||
31 | }; | ||