const _path = _interopRequireDefault(require('path')); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } module.exports = (Ferdium, settings) => { const getMessages = () => { let directCount = 0; const directCountPerServer = document.querySelectorAll( '[class*="lowerBadge-"] [class*="numberBadge-"]', ); for (const directCountBadge of directCountPerServer) { directCount += Ferdium.safeParseInt(directCountBadge.textContent); } const indirectCountPerServer = document.querySelectorAll( '[class*="modeUnread-"]', ).length; Ferdium.setBadge(directCount, indirectCountPerServer); }; Ferdium.loop(getMessages); Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); // 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'); const skipDomains = [/^https:\/\/discordapp\.com\/channels\//i, /^https:\/\/discord\.com\/channels\//i]; let stayInsideDiscord; skipDomains.every(skipDomain => { stayInsideDiscord = skipDomain.test(url); return !stayInsideDiscord; }); if (!Ferdium.isImage(link) && !stayInsideDiscord) { event.preventDefault(); event.stopPropagation(); if (settings.trapLinkClicks === true) { window.location.href = url; } else { Ferdium.openNewWindow(url); } } } }, true); };