aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/circuit/webview.js
blob: b5e3fd5bbadadf82a17dae2267ff46ed8992140e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"use strict";

module.exports = Ferdi => {
  const getMessages = function getMessages() {
    // Initialize empty vars
    var match = [];
    // Get value of <title> tag where in case of new messages the number of messages appear
    const titleValue = document.querySelector('title').text;
    // Extract the number from the tag
    match = titleValue.match(/\d+/);
    unread = match != null && match.length > 0 ? match[0] : 0;
    // Set unread msgs badge

    Ferdi.setBadge(Ferdi.safeParseInt(unread));
  };

  const loopFunc = () => {
    getMessages();
  };

  Ferdi.loop(loopFunc);

};