-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (68 loc) · 2.74 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="index.css">
<link href="https://fonts.googleapis.com/css2?family=Abril+Fatface&family=Catamaran:wght@200&family=Courgette&family=Dancing+Script:wght@700&family=Edu+TAS+Beginner:wght@700&family=Lato:wght@300;900&family=Mukta:wght@700&family=Mulish:wght@300&family=Open+Sans&family=PT+Sans:ital,wght@1,700&family=Poppins:wght@300&family=Raleway:wght@100&family=Roboto&family=Roboto+Condensed:wght@700&family=Roboto+Slab&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/f30fac2c61.js" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<nav>
<div class="logo">
<h1>Movie's</h1>
</div>
<div class="searchBar">
<input type="text" placeholder="Search Here." id="searchInput">
<button id="searchBtn">Search</button>
</div>
</nav>
</div>
<div class="card">
</div>
<script>
let searchInput = document.getElementById("searchInput");
let searchBtn = document.getElementById("searchBtn");
let APIKey = "17f8307a";
const getData = async (movie) => {
try{
let data = await fetch(`http://www.omdbapi.com/?apikey=${APIKey}&t=${movie}`);
let jsonData = await data.json();
document.querySelector(".card").innerHTML = "";
searchInput.value=""
console.log(jsonData.Error == "Movie not found!");
console.log(jsonData.Ratings[0].Value);
let div = document.createElement("div");
div.classList.add("movieCard");
div.innerHTML = `
<img src=${jsonData.Poster} alt="">
<div class="cardText">
<h1> ${jsonData.Title}</h1>
<p class="rating">Rating : <span>${jsonData.Ratings[0].Value.slice( 0, 3)}</span> </p>
<a href="" class="types">${jsonData.Genre}</a>
<p>Released : <span>${jsonData.Released}</span> </p>
<p>Duration : <span>${jsonData.Runtime}</span> </p>
<p>Plot : <span>${jsonData.Plot}</span> </p>
</div>
`;
document.querySelector(".card").appendChild(div);
}
catch(error){
document.querySelector(".card").innerHTML="<h1>Movie Not Found</h1>";
console.log(error);
}
}
document.querySelector(".card").innerHTML="<h1>Search Movie Information Here.</h1>";
searchBtn.addEventListener("click", function () {
let movieName = searchInput.value;
if (movieName != "") {
getData(movieName);
} else {
document.querySelector(".card").innerHTML="<h1>Search Movie Name</h1>";
}
});
</script>
</body>
</html>