diff options
-rw-r--r-- | docs/frontend_api.md | 100 |
1 files changed, 92 insertions, 8 deletions
diff --git a/docs/frontend_api.md b/docs/frontend_api.md index bd0bfef..5bf4ebd 100644 --- a/docs/frontend_api.md +++ b/docs/frontend_api.md | |||
@@ -1,15 +1,44 @@ | |||
1 | - [Frontend API](#frontend-api) | ||
2 | - [Ferdi Class Methods](#ferdi-class-methods) | ||
3 | - [setBadge(directMessages, [indirectMessages])](#setbadgedirectmessages-indirectmessages) | ||
4 | - [Arguments](#arguments) | ||
5 | - [Usage](#usage) | ||
6 | - [setDialogTitle(title)](#setdialogtitletitle) | ||
7 | - [Arguments](#arguments-1) | ||
8 | - [Usage](#usage-1) | ||
9 | - [injectCSS(pathToCssFile)](#injectcsspathtocssfile) | ||
10 | - [Arguments](#arguments-2) | ||
11 | - [Usage](#usage-2) | ||
12 | - [injectJSUnsafe(pathToJsFile)](#injectjsunsafepathtojsfile) | ||
13 | - [Arguments](#arguments-3) | ||
14 | - [Usage](#usage-3) | ||
15 | - [loop(action)](#loopaction) | ||
16 | - [Arguments](#arguments-4) | ||
17 | - [Usage](#usage-4) | ||
18 | - [onNotify(fn)](#onnotifyfn) | ||
19 | - [Arguments](#arguments-5) | ||
20 | - [Usage](#usage-5) | ||
21 | - [handleDarkMode(callback)](#handledarkmodecallback) | ||
22 | - [Arguments](#arguments-6) | ||
23 | - [Callback function arguments](#callback-function-arguments) | ||
24 | - [Usage](#usage-6) | ||
25 | - [clearStorageData](#clearstoragedata) | ||
26 | - [Arguments](#arguments-7) | ||
27 | - [Usage](#usage-7) | ||
28 | - [releaseServiceWorkers](#releaseserviceworkers) | ||
29 | - [safeParseInt(stringText)](#safeparseintstringtext) | ||
30 | - [Arguments](#arguments-8) | ||
31 | - [Usage](#usage-8) | ||
32 | - [setDialogTitle(title)](#setdialogtitletitle-1) | ||
33 | - [Arguments](#arguments-9) | ||
34 | - [Usage](#usage-9) | ||
35 | |||
1 | # Frontend API | 36 | # Frontend API |
2 | 37 | ||
3 | Provides a set of helper functions to integrate the service into [Ferdi](https://getferdi.com). | 38 | Provides a set of helper functions to integrate the service into [Ferdi](https://getferdi.com). |
4 | 39 | ||
5 | ## Ferdi Class Methods | 40 | ## Ferdi Class Methods |
6 | 41 | ||
7 | - [setBadge](#user-content-setbadge) | ||
8 | - [injectCSS](#user-content-injectcss) | ||
9 | - [loop](#user-content-loop) | ||
10 | - [onNotify](#user-content-onnotify) | ||
11 | - [handleDarkMode](#user-content-handleDarkMode) | ||
12 | |||
13 | ### setBadge(directMessages, [indirectMessages]) | 42 | ### setBadge(directMessages, [indirectMessages]) |
14 | 43 | ||
15 | Sets the unread message badge | 44 | Sets the unread message badge |
@@ -22,7 +51,7 @@ Sets the unread message badge | |||
22 | 51 | ||
23 | 2. `int` indirectMessages (optional) | 52 | 2. `int` indirectMessages (optional) |
24 | 53 | ||
25 | - Set a badge that defines there are new messages but they do not involve me directly to me eg. in a channel | 54 | - Set a badge that defines there are new messages but they do not involve me directly to me eg. in a channel (default value: 0) |
26 | 55 | ||
27 | #### Usage | 56 | #### Usage |
28 | 57 | ||
@@ -155,7 +184,7 @@ module.exports = Ferdi => { | |||
155 | ).length; | 184 | ).length; |
156 | const messageRequestsElement = document.querySelector('._5nxf'); | 185 | const messageRequestsElement = document.querySelector('._5nxf'); |
157 | if (messageRequestsElement) { | 186 | if (messageRequestsElement) { |
158 | count += parseInt(messageRequestsElement.textContent, 10); | 187 | count += Ferdi.safeParseInt(messageRequestsElement.textContent); |
159 | } | 188 | } |
160 | 189 | ||
161 | Ferdi.setBadge(count); | 190 | Ferdi.setBadge(count); |
@@ -234,3 +263,58 @@ Ferdi.handleDarkMode((isEnabled, helpers) => { | |||
234 | } | 263 | } |
235 | }) | 264 | }) |
236 | ``` | 265 | ``` |
266 | |||
267 | ### clearStorageData | ||
268 | |||
269 | While exiting/closing/disabling the service, if you want to clear the local storage, you can use this method to effect the same. | ||
270 | |||
271 | #### Arguments | ||
272 | |||
273 | 1. `id` of the recipe | ||
274 | 2. struct of `storages` | ||
275 | |||
276 | #### Usage | ||
277 | |||
278 | ```JavaScript | ||
279 | Ferdi.clearStorageData(settings.id, { | ||
280 | storages: [ | ||
281 | 'appcache', | ||
282 | 'serviceworkers', | ||
283 | 'cachestorage', | ||
284 | 'websql', | ||
285 | 'indexdb', | ||
286 | ], | ||
287 | }); | ||
288 | ``` | ||
289 | |||
290 | ### releaseServiceWorkers | ||
291 | |||
292 | While exiting/closing/disabling the service, if you want to release any service workers, you can use this method to effect the same. | ||
293 | |||
294 | ### safeParseInt(stringText) | ||
295 | |||
296 | A utility method that can be used to safely parse the text content (handles nulls, undefined, etc). Basically a wrapper around `parseInt` - but handles the safety checks. | ||
297 | |||
298 | #### Arguments | ||
299 | |||
300 | 1. `stringText` String to be parsed into a number. (Could be `null` or `undefined`) Defaults to `0` | ||
301 | |||
302 | #### Usage | ||
303 | |||
304 | ```JavaScript | ||
305 | Ferdi.safeParseInt(mySelector.innerText) | ||
306 | ``` | ||
307 | |||
308 | ### setDialogTitle(title) | ||
309 | |||
310 | When you want to set the title of the Ferdi window (while this service is active or in focus), you can use this function | ||
311 | |||
312 | #### Arguments | ||
313 | |||
314 | 1. `title`: The title to be set (for eg: the chat message person/group name in whatsapp) | ||
315 | |||
316 | #### Usage | ||
317 | |||
318 | ```JavaScript | ||
319 | Ferdi.setDialogTitle(element ? element.textContent : null); | ||
320 | ``` | ||