const _path = _interopRequireDefault(require('path')); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } module.exports = (Ferdium, settings) => { const getMessages = () => { let count = 0; const container = document.querySelector('[role="tablist"] > button > div'); if (container) { const children = container.children; if (children.length === 3) { const elementContainer = children[children.length - 1]; if (elementContainer) { const element = elementContainer.querySelector('[data-text-as-pseudo-element]'); if (element && element.dataset) { count = Ferdium.safeParseInt(element.dataset.textAsPseudoElement); } } } } Ferdium.setBadge(count); }; Ferdium.loop(getMessages); Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); // TODO: See how this can be moved into the main ferdium app and sent as an ipc message for opening with a new window or same Ferdium recipe's webview based on user's preferences document.addEventListener('click', event => { const link = event.target.closest('a[href^="http"]'); const button = event.target.closest('button[title^="http"]'); if (link || button) { const url = link ? link.getAttribute('href') : button.getAttribute('title'); event.preventDefault(); event.stopPropagation(); if (settings.trapLinkClicks === true) { window.location.href = url; } else { Ferdium.openNewWindow(url); } } }, true); };