aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/freshrss/webview.js
blob: 9740b08ab7fa540ddae019e7268d52b94d0d6243 (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
24
25
26
27
28
29
30
31
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

const _path = _interopRequireDefault(require('path'));

module.exports = Ferdium => {
  const getMessages = function getMessages() {
    // Initialize empty vars
    let unread = 0;
    let match = [];
    // Define RegExp to replace occasionally &nbsp
    const re = new RegExp(String.fromCodePoint(160), 'g');
    // Get value of <title> tag where in case of new feed elements the number of elements appear
    const titleValue = document.querySelector('title').text.replaceAll(re, '');
    // Extract the number from the tag
    match = titleValue.match(/[\d\s]+/);
    // Some logic to handle the match groups
    unread = match !== null && match.length > 0 ? match[0] : 0;
    // Set unread msgs badge
    Ferdium.setBadge(Number.parseInt(unread, 10));
  };

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

  Ferdium.loop(loopFunc);

  Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
};