forked from Pranav-95/Random-Joke-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (32 loc) · 1.09 KB
/
script.js
File metadata and controls
41 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const body = document.querySelector("body");
const toggle = document.querySelector(".toggle");
const copy = document.querySelector("#copy_joke");
const jokeContainer = document.getElementById("joke");
const btn = document.getElementById("btn");
const url = "https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit&type=single";
let getJoke = () => {
jokeContainer.classList.remove("fade");
fetch(url)
.then(data => data.json())
.then(item =>{
jokeContainer.textContent = `${item.joke}`;
jokeContainer.classList.add("fade");
});
}
btn.addEventListener("click",getJoke);
getJoke();
// Fade in
setTimeout(function(){
jokeEl.innerHTML = joke.joke;
jokeEl.style.opacity = 1;
},500);
toggle.addEventListener("click", () => {
body.classList.toggle("dark")
? (toggle.firstElementChild.className = "far fa-moon")
: (toggle.firstElementChild.className = "far fa-sun");
});
//master
copy.addEventListener("click", () => {
const text = jokeContainer.textContent;
navigator.clipboard.writeText(text);
});