-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.html
126 lines (87 loc) · 3.49 KB
/
search.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="zxx">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8" />
<title>Movies-Wiki</title>
<script>
addEventListener("load", function () {
setTimeout(hideURLbar, 0);
}, false);
function hideURLbar() {
window.scrollTo(0, 1);
}
</script>
<!--/Style-CSS -->
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<!--//Style-CSS -->
<!-- font-awesome-icons -->
<link href="css/font-awesome.css" rel="stylesheet">
<!-- //font-awesome-icons -->
</head>
<body onload="mainfun()">
<section class="section">
<div id="main" class="main">
<div class="wrapper">
<div class="top">
<div class="form">
<a href="index.html">
<h1>MoviesWiki</h1>
</a>
<form action="#" method="GET" onsubmit="mainfun()" class="d-flex coming-form">
<input id="text" name="text" type="text" placeholder="Search for any movies, series etc.,">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
<center style="padding-top: 50px;">
<div id="results" class="row">
</div>
</center>
<center style="padding-top: 4%;" id="show">
</center>
</div>
</div>
</section>
</body>
<script type="text/javascript">
var pagecount = 1;
//var results = document.getElementById("results");
var button = document.getElementById("show");
let searchParams = new URLSearchParams(window.location.search);
let text = searchParams.get('text');
function mainfun() {
//var text = document.getElementById("text").value;
getresults(pagecount, text);
button.innerHTML += '<button onclick="showmore()" type="submit">Show More</button>';
//console.log(myJson["Search"][0]);
}
function showmore() {
//var text = document.getElementById("text").value;
pagecount++;
getresults(pagecount, text);
}
async function getresults(pagecount, text) {
const response = await fetch('https://www.omdbapi.com/?s=' + text + '&page=' + pagecount + '&apikey=7b47238d');
const myJson = await response.json();
console.log(myJson);
if (myJson["Response"] != "False") {
for (var i = 0; i < myJson["Search"].length; i++) {
var movie = myJson["Search"][i];
if (movie["Poster"] != "N/A") {
var title = movie["Title"];
if (title.length > 15) {
title = title.substring(0, 15);
}
results.innerHTML += "<div class='col-3 card'><a href='movie.html?id=" + movie['imdbID'] + "&text=" + text + "'><img style='width:150px; height:222px;' src='" + movie['Poster'] + "'></a><div class='container'><p style='color:white;'>" + title + "</p></div></div>";
}
}
} else {
if (pagecount == 1) {
document.getElementById("main").style.height = "100vh";
}
button.innerHTML = "<br><h4 style='color:white;'>No more Results Found</h4>";
}
}
</script>
</html>