-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (90 loc) · 3.82 KB
/
script.js
File metadata and controls
104 lines (90 loc) · 3.82 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const titleBtn = document.querySelector("#getTitle");
const authorBtn = document.querySelector("#getAuthor");
const input = document.querySelector("input");
const showInfo = document.querySelector(".content");
const ISBNbtn = document.querySelector("#getISBN");
const gif_API_KEY = "x3jakeVmUi2kYcyWH3flSs8Ogry8EuUC";
const addgif = document.querySelector(".gif");
const othergifs = document.querySelector(".otherGifs")
const giphy = async () => {
let inpt = input.value;
const response = await axios.get(`http://api.giphy.com/v1/gifs/random?q=cats&api_key=${gif_API_KEY}&tag=${inpt}`);
console.log(response);
const gif_array = response.data.data.fixed_height_downsampled_url;
console.log(gif_array);
const addgif = document.querySelector(".gif");
addgif.innerHTML = `
<img src="${gif_array}" /> `
}
const giphyAuthor = () => {
addgif.innerHTML = '';
othergifs.innerHTML = '';
othergifs.innerHTML = `<img src="https://media.giphy.com/media/12imXZa2uBqf28/giphy.gif" />`
}
titleBtn.addEventListener("click", async () => {
giphy();
showInfo.innerHTML = '';
addgif.innerHTML = '';
// othergifs.innerHTML = '';
othergifs.style.display = "none";
let inpt = input.value;
const response = await axios.get(`https://www.googleapis.com/books/v1/volumes?q=intitle:${inpt}&key=${API_KEY}&maxResults=40`)
const booksArr = response.data.items;
for (let i = 0; i < booksArr.length; i += 1) {
const bookCard = document.createElement('div');
bookCard.innerHTML = `
<img src= ${booksArr[i].volumeInfo.imageLinks.smallThumbnail} />
<li>${booksArr[i].volumeInfo.title}</li>
<button id ="moreInfo">More info!</button>
`
const moreInfo = bookCard.querySelector("#moreInfo");
moreInfo.addEventListener("click", function () {
location.href = booksArr[i].volumeInfo.infoLink;
})
showInfo.appendChild(bookCard);
}
console.log(booksArr);
})
authorBtn.addEventListener("click", async () => {
giphyAuthor();
showInfo.innerHTML = '';
addgif.innerHTML = '';
othergifs.style.display = "flex";
const inpt = input.value;
const response = await axios.get(`https://www.googleapis.com/books/v1/volumes?q=inauthor:${inpt}&key=${API_KEY}&maxResults=40`)
const authorArr = response.data.items;
for (let i = 0; i < authorArr.length; i += 1) {
const bookCard = document.createElement('div');
bookCard.innerHTML = `<li>
${authorArr[i].volumeInfo.authors} , ${authorArr[i].volumeInfo.title}</li>
<img src= ${authorArr[i].volumeInfo.imageLinks.smallThumbnail} />
<button id ="moreInfo">More info!</button>
`
const moreInfo = bookCard.querySelector("#moreInfo");
moreInfo.addEventListener("click", function () {
location.href = authorArr[i].volumeInfo.infoLink;
})
showInfo.appendChild(bookCard);
}
})
ISBNbtn.addEventListener("click", async () => {
showInfo.innerHTML = '';
addgif.innerHTML = '';
othergifs.style.display = "flex";
const inpt = input.value;
const response = await axios.get(`https://www.googleapis.com/books/v1/volumes?q=isbn:${inpt}&key=${API_KEY}&maxResults=40`)
const ISBNinfo = response.data.items;
for (let i = 0; i < ISBNinfo.length; i += 1) {
const bookCard = document.createElement('div');
bookCard.innerHTML = `<li>
${ISBNinfo[i].volumeInfo.title}</li>
<img src= ${ISBNinfo[i].volumeInfo.imageLinks.smallThumbnail} />
<button id ="moreInfo">More info!</button>
`
const moreInfo = bookCard.querySelector("#moreInfo");
moreInfo.addEventListener("click", function () {
location.href = ISBNinfo[i].volumeInfo.infoLink;
})
showInfo.appendChild(bookCard);
}
})