diff --git a/MMM-JokeAPI.js b/MMM-JokeAPI.js index a374224..3c7a463 100644 --- a/MMM-JokeAPI.js +++ b/MMM-JokeAPI.js @@ -1,6 +1,9 @@ Module.register("MMM-JokeAPI", { defaults: { - category: "Programming", + lang: "en", + category: "Any", + blacklistFlags: "", + safeMode: false, fetchInterval: 10 * 1000 }, getStyles() { @@ -48,11 +51,20 @@ Module.register("MMM-JokeAPI", { } }, getJoke() { - fetch(`https://sv443.net/jokeapi/v2/joke/${this.config.category}`).then((response) => { - response.json().then((joke) => { - this.joke = joke; - this.updateDom(); + if(this.config.safeMode){ + fetch(`https://v2.jokeapi.dev/joke/${this.config.category}?lang=${this.config.lang}&blacklistFlags=${this.config.blacklistFlags}&safe-mode`).then((response) => { + response.json().then((joke) => { + this.joke = joke; + this.updateDom(); + }); }); - }); + } else { + fetch(`https://v2.jokeapi.dev/joke/${this.config.category}?lang=${this.config.lang}&blacklistFlags=${this.config.blacklistFlags}`).then((response) => { + response.json().then((joke) => { + this.joke = joke; + this.updateDom(); + }); + }); + } } }); diff --git a/README.md b/README.md index fdff507..a92745f 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,44 @@ # MagicMirror² JokeAPI module -This is a module for `MagicMirror²`; the purpose of the module is to show you jokes from the JokeAPI. +This is a module for `MagicMirror²`; the purpose of the module is to show you jokes from the V2 JokeAPI. + + +### Preview +![Screenshot](screenshot.png) + ## Installation 1. Clone this repository into your MagicMirror `modules` folder. 2. Edit your configuration file under `config/config.js` with the following configuration. ``` +{ + module: 'MMM-JokeAPI', + position: 'middle_center', +} +``` +You can use more detailed configuration like these; See the below section. +``` { module: 'MMM-JokeAPI', position: 'middle_center', config: { - category: "Programming" + lang: "en", + category: "Programming,Miscellaneous", + blacklistFlags: "nsfw", + safeMode: true, } } ``` -### Preview -![Screenshot](screenshot.png) - - - ## Configuration options | Option | Description |------------------------|----------- -| `category` | The list of module names that are controlled by this module.
Possible values:
1. `Programming`
2. `Miscellaneous`
3. `Dark`
4. `Any`

**Type:** `string`
**Default value:** `Programming` -| `fetchInterval`| How often (in milliseconds) a new joke should be fetched.

**Type:** `number`
**Default value:** `10 * 1000` - +| `category` | Joke Categories.

Possible values:`Any, Miscellaneous, Dark, Programming, Pun, Spooky, Christmas`

**Type:** `string`
**Default value:** `Any`
Multiple catagories can be used at once, just seperate them with commas

**Example:** `category: "Programming,Miscellaneous,Pun",` +| `fetchInterval` | How often (in milliseconds) a new joke should be fetched.

**Type:** `number`
**Default value:** `10 * 1000` +| `lang` | Language the jokes are in.

Current languages suported are `cs, de, en, es, fr, pt`

**Type:** `string`
**Default value:** `en`

**Example:** `lang: "en",` +| `blacklistFlags` | Prevent jokes of this type.

These are all the available flags: `nsfw, religious, political, racist, sexist, explicit`

**Type:** `string`
**Default value:** `NULL`
Multiple blacklistFlags can be set at one, just seperate them with commas

**Example:** `blacklistFlags: "nsfw,religious",` +| `safeMode` | If enabled, JokeAPI will try its best to serve only jokes that are considered safe for everyone. Unsafe jokes are those who can be considered explicit in any way, either through the used language, its references or its blacklist flags. Jokes from the category Dark are also generally marked as unsafe.

**Type:** `bool`
**Default value:** `false`

**Example:** `safeMode: true,` #### Credits MagicMirror²: [MagicMirror²](https://github.com/MichMich/MagicMirror) -JokeAPI: [JokeAPI](https://sv443.net/jokeapi) +JokeAPI: [V2 JokeAPI](https://v2.jokeapi.dev/)