From dc3fba527eb128ce9b57426a51b59385c00ff694 Mon Sep 17 00:00:00 2001 From: Bennett Date: Sun, 31 Oct 2021 15:50:10 +0100 Subject: Add moodle recipe --- recipes/moodle/README.md | 4 ++++ recipes/moodle/icon.svg | 15 +++++++++++++++ recipes/moodle/index.js | 1 + recipes/moodle/package.json | 9 +++++++++ recipes/moodle/service.css | 0 recipes/moodle/webview.js | 18 ++++++++++++++++++ 6 files changed, 47 insertions(+) create mode 100644 recipes/moodle/README.md create mode 100644 recipes/moodle/icon.svg create mode 100644 recipes/moodle/index.js create mode 100644 recipes/moodle/package.json create mode 100644 recipes/moodle/service.css create mode 100644 recipes/moodle/webview.js diff --git a/recipes/moodle/README.md b/recipes/moodle/README.md new file mode 100644 index 0000000..1c85a88 --- /dev/null +++ b/recipes/moodle/README.md @@ -0,0 +1,4 @@ +# Moodle for Ferdi +This is a Ferdi recipe for Moodle + +This recipe is designed to work with the default moodle Theme. If your Moodle uses a different theme, this recipe might not be able to show an unread messages count as the CSS selectors differ. diff --git a/recipes/moodle/icon.svg b/recipes/moodle/icon.svg new file mode 100644 index 0000000..4213641 --- /dev/null +++ b/recipes/moodle/icon.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/recipes/moodle/index.js b/recipes/moodle/index.js new file mode 100644 index 0000000..0a5cedb --- /dev/null +++ b/recipes/moodle/index.js @@ -0,0 +1 @@ +module.exports = Ferdi => class moodle extends Ferdi {}; diff --git a/recipes/moodle/package.json b/recipes/moodle/package.json new file mode 100644 index 0000000..b421623 --- /dev/null +++ b/recipes/moodle/package.json @@ -0,0 +1,9 @@ +{ + "id": "moodle", + "name": "Moodle", + "version": "1.0.0", + "license": "MIT", + "config": { + "hasCustomUrl": true + } +} diff --git a/recipes/moodle/service.css b/recipes/moodle/service.css new file mode 100644 index 0000000..e69de29 diff --git a/recipes/moodle/webview.js b/recipes/moodle/webview.js new file mode 100644 index 0000000..ba19f3f --- /dev/null +++ b/recipes/moodle/webview.js @@ -0,0 +1,18 @@ +var _path = _interopRequireDefault(require('path')); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +module.exports = Ferdi => { + const getMessages = () => { + const elements = [...document.querySelectorAll('[data-region="count-container"]')]; + const messages = elements.reduce( + ((count, item) => count + Number(item.textContent)), + 0 + ); + + Ferdi.setBadge(messages, 0); + }; + Ferdi.loop(getMessages); + + Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); +}; -- cgit v1.2.3-54-g00ecf From 1e89217cedb86460a9341b9402f6b75a70541c1b Mon Sep 17 00:00:00 2001 From: Bennett Date: Sun, 31 Oct 2021 15:50:42 +0100 Subject: Update all.json --- all.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/all.json b/all.json index 1e6ba42..209ab34 100644 --- a/all.json +++ b/all.json @@ -989,6 +989,15 @@ "svg": "https://cdn.jsdelivr.net/gh/getferdi/recipes/recipes/monicahq/icon.svg" } }, + { + "featured": false, + "id": "moodle", + "name": "Moodle", + "version": "1.0.0", + "icons": { + "svg": "https://cdn.jsdelivr.net/gh/getferdi/recipes/recipes/moodle/icon.svg" + } + }, { "featured": false, "id": "msteams", -- cgit v1.2.3-54-g00ecf From 2b637ea99ce5ab25af629cd6ba10a86e3babf3d0 Mon Sep 17 00:00:00 2001 From: Bennett Date: Sun, 31 Oct 2021 16:19:43 +0100 Subject: Use more explicit variable names --- recipes/moodle/webview.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipes/moodle/webview.js b/recipes/moodle/webview.js index ba19f3f..932d1ec 100644 --- a/recipes/moodle/webview.js +++ b/recipes/moodle/webview.js @@ -4,13 +4,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de module.exports = Ferdi => { const getMessages = () => { - const elements = [...document.querySelectorAll('[data-region="count-container"]')]; - const messages = elements.reduce( + const directCountSelector = [...document.querySelectorAll('[data-region="count-container"]')]; + const totalMessageCount = directCountSelector.reduce( ((count, item) => count + Number(item.textContent)), 0 ); - Ferdi.setBadge(messages, 0); + Ferdi.setBadge(totalMessageCount, 0); }; Ferdi.loop(getMessages); -- cgit v1.2.3-54-g00ecf