-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.html
176 lines (163 loc) · 4.38 KB
/
video.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
<style>
body {
overflow-x: hidden;
}
#searchResults {
width: 96%;
display: grid;
grid-template-columns: repeat(4, 20%);
grid-gap: 1%;
justify-content: space-between;
margin-top: 5%;
}
#thumb {
width: 340px;
height: 240px;
}
#iframe {
/* margin-top:0px; */
}
#top {
width: 99.4%;
border: 1px solid black;
height: 60px;
display: flex;
/* position: fixed; */
background-color: white;
margin-top: none;
}
#container {
/* margin-top: -8px; */
/* margin-left: -7px; */
width: 100%;
height: 1000px;
border: 1px solid black;
margin: auto;
text-align: center;
}
#search {
height: 30px;
margin-left: 200px;
width: 1000px;
margin-top: 15px;
}
#butt {
height: 35px;
margin-left: 10px;
margin-top: 16px;
width: 150px;
margin-right: 50px;
}
#bottom{
/* border: 1px solid black; */
width:100%;
}
#logo {
height: 25px;
margin-top: 18px;
}
#icons {
height: 20px;
margin-left: 100px;
width: 500px;
margin-top: 20px;
font-size:30px;
}
.material-icons {
margin-left: 20px;
}
#rec {
margin-top: 20px;
margin-right: 20px;
}
#iframe {
border: 1px solid black;
}
</style>
</head>
<body>
<div id="container">
<div id="top">
<span id="rec" class="material-icons"> reorder </span>
<!-- <h1>Youtube</h1> -->
<img
id="logo"
src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/YouTube_Logo_2017.svg/2560px-YouTube_Logo_2017.svg.png"
alt=""
/>
<input type="text" id="search" />
<button onclick="searchVideos()" id="butt">Search</button>
<div id="icons">
<span class="material-icons">video_call</span>
<span class="material-icons"> apps </span>
<span class="material-icons"> notifications_none </span>
<span class="material-icons"> face </span>
</div>
</div>
<div id="bottom">
<div id="searchResults"></div>
</div>
</div>
</body>
</html>
<script>
let api = "AIzaSyBRVuhKhZJhJ-2XBiKTvUvqKerJf01rYoI";
let localData = JSON.parse(localStorage.getItem("videoData"));
let searchResults = document.getElementById("searchResults");
async function searchVideos() {
try {
let inp = document.getElementById("search").value;
let res = await fetch(
`https://youtube.googleapis.com/youtube/v3/search?q=${inp}&type=video&key=${api}&maxResults=20&part=snippet`
);
let data = await res.json();
console.log(data);
let array_videos = data.items;
appendVideos(array_videos);
} catch (err) {
console.log(err);
}
}
const showData = () => {
console.log(localData);
let x = document.getElementById("");
let iframe = document.createElement("iframe");
iframe.src = `https://www.youtube.com/embed/${localData}`;
iframe.width = "860px";
iframe.height = "500px";
iframe.setAttribute("allowfullscreen", true);
iframe.setAttribute("id", "iframe");
searchResults.append(iframe);
};
showData();
const appendVideos = (list) => {
searchResults.textContent = "";
list.forEach((item) => {
// console.log(videoId);
let div = document.createElement("div");
let videoId = item.id.videoId;
console.log(videoId);
let iframe = document.createElement("iframe");
iframe.src = `https://www.youtube.com/embed/${videoId}`;
iframe.width = "560px";
iframe.height = "250px";
iframe.setAttribute("allowfullscreen", true);
iframe.setAttribute("id", "iframe")
div.append(iframe);
searchResults.append(div);
});
};
// function appendVideos(list) {
// }
</script>