From 5598d4b3bfc2956a6ccd16ceb1fad9e67ccff10e Mon Sep 17 00:00:00 2001 From: Maxime Marty-Dessus Date: Thu, 4 Nov 2021 18:05:00 +0100 Subject: Add recipe for Chatwoot (#760) --- recipes/chatwoot/icon.svg | 12 ++++++++++++ recipes/chatwoot/index.js | 1 + recipes/chatwoot/package.json | 11 +++++++++++ recipes/chatwoot/webview.js | 14 ++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 recipes/chatwoot/icon.svg create mode 100644 recipes/chatwoot/index.js create mode 100644 recipes/chatwoot/package.json create mode 100644 recipes/chatwoot/webview.js (limited to 'recipes') diff --git a/recipes/chatwoot/icon.svg b/recipes/chatwoot/icon.svg new file mode 100644 index 0000000..1652967 --- /dev/null +++ b/recipes/chatwoot/icon.svg @@ -0,0 +1,12 @@ + + + + woot-log + Created with Sketch. + + \ No newline at end of file diff --git a/recipes/chatwoot/index.js b/recipes/chatwoot/index.js new file mode 100644 index 0000000..653b54c --- /dev/null +++ b/recipes/chatwoot/index.js @@ -0,0 +1 @@ +module.exports = (Ferdi) => Ferdi; diff --git a/recipes/chatwoot/package.json b/recipes/chatwoot/package.json new file mode 100644 index 0000000..6c024e7 --- /dev/null +++ b/recipes/chatwoot/package.json @@ -0,0 +1,11 @@ +{ + "id": "chatwoot", + "name": "Chatwoot", + "version": "1.0.0", + "license": "MIT", + "repository": "https://github.com/maximeMD/ferdi-chatwoot", + "config": { + "serviceURL": "https://app.chatwoot.com/app/login" + } + } + \ No newline at end of file diff --git a/recipes/chatwoot/webview.js b/recipes/chatwoot/webview.js new file mode 100644 index 0000000..05e33b3 --- /dev/null +++ b/recipes/chatwoot/webview.js @@ -0,0 +1,14 @@ +module.exports = (Ferdi) => { + const getMessages = function getMessages() { + const unreadBadges = document.querySelectorAll("span.unread"); + const unreadBadgesArray = [...unreadBadges]; + const unreadMessagesCount = unreadBadgesArray.reduce( + (previousValue, currentBadge) => + previousValue + Ferdi.safeParseInt(currentBadge.textContent), + 0, + ); + Ferdi.setBadge(unreadMessagesCount); + }; + + Ferdi.loop(getMessages); +}; -- cgit v1.2.3-54-g00ecf