|
|
@ -1,20 +1,20 @@ |
|
|
|
class JokeService { |
|
|
|
class JokeService { |
|
|
|
|
|
|
|
|
|
|
|
constructor(category = ['programming', 'coding', 'development'], lang = 'en') { |
|
|
|
constructor(categories = ['programming', 'coding', 'development'], lang = 'en') { |
|
|
|
this.category = Array.isArray(category) ? category : [category]; |
|
|
|
this.categories = Array.isArray(categories) ? categories : [categories]; |
|
|
|
this.lang = lang; |
|
|
|
this.lang = lang; |
|
|
|
this.apiBaseUrl = 'https://v2.jokeapi.dev/joke/' |
|
|
|
this.apiBaseUrl = 'https://v2.jokeapi.dev/joke/' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setCategory(category) { |
|
|
|
setCategory(category) { |
|
|
|
this.category = Array.isArray(category) ? category : [category]; |
|
|
|
this.categories = Array.isArray(category) ? category : [category]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tell() { |
|
|
|
tell() { |
|
|
|
let service = this; |
|
|
|
let service = this; |
|
|
|
|
|
|
|
|
|
|
|
axios.get( |
|
|
|
axios.get( |
|
|
|
service.apiBaseUrl + getRandomItem(service.category) + '?lang=' + service.lang |
|
|
|
service.apiBaseUrl + service.categories.join(',') + '?lang=' + service.lang |
|
|
|
).then((response) => { |
|
|
|
).then((response) => { |
|
|
|
if (response.data.error === false) { |
|
|
|
if (response.data.error === false) { |
|
|
|
service.show(response.data); |
|
|
|
service.show(response.data); |
|
|
@ -43,10 +43,6 @@ function showNotification(text) { |
|
|
|
body: text |
|
|
|
body: text |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// alert(text);
|
|
|
|
console.warn('Notifications sind nicht erlaubt.') |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getRandomItem(items) { |
|
|
|
|
|
|
|
return items[Math.floor(Math.random()*items.length)]; |
|
|
|
|
|
|
|
} |
|
|
|
|