-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex1.js
112 lines (98 loc) · 3.26 KB
/
index1.js
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
// `https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&q=${input.value}&type=video&key=AIzaSyBPo8ftIoPViBJeLeAgOLS0sZXDq0l-IMA`
// `https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&q=trending&type=video&key=AIzaSyBPo8ftIoPViBJeLeAgOLS0sZXDq0l-IMA`;
//api key--> AIzaSyBPo8ftIoPViBJeLeAgOLS0sZXDq0l-IMA
// AIzaSyBEDJodNTah5jNOEaKc2OEWlb1K8g0MNFw
//GET https://youtube.googleapis.com/youtube/v3/search?part=string&maxResults=50&q=ICN%20Studio&type=video&key=[YOUR_API_KEY] HTTP/1.1
let btn = document.querySelector("#btn");
let right = document.querySelector(".right");
let logo = document.getElementById("logo");
// let localid = document.querySelector("id");
let localid = localStorage.getItem("id");
let call = JSON.parse(localStorage.getItem("call"));
// console.log(localid)
let url;
//when user searched for any inputs
btn.addEventListener("click", () => {
let input = document.getElementById("input");
url = `https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=20&q=${input.value}&type=video&key=AIzaSyCdkSUDMRM0nqFxIZpIujLEWkrtX7W8H6c`;
getdata(url);
});
//when localstorage id is empty;
if (localid == null) {
// console.log
url = `https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=20&q=javascript&type=video&key=AIzaSyCdkSUDMRM0nqFxIZpIujLEWkrtX7W8H6c`;
getdata(url);
}
// else{
// console.log("yo")
// getdata(url)
// }
// fetching req as per url
async function getdata(url) {
try {
let data1 = await fetch(url);
let res1 = await data1.json();
displaydata(res1.items);
} catch (error) {
console.log(error);
}
}
//displaying mainpage with results as per videos
function displaydata(videos) {
// console.log(videos)
right.innerHTML = "";
videos.forEach((video) => {
let {
id: { videoId },
snippet: {
channelId,
channelTitle,
description,
thumbnails: {
default: { url },
},
},
} = video;
// console.log(videoId)
let vdiv = document.createElement("div");
vdiv.setAttribute("class", "vcard");
vdiv.style.pos = "relative";
// let div = document.createElement("div");
// div.setAttribute("class" , "blur");
vdiv.innerHTML = `<div id="vthumb"><img src=${url} alt=""></div>
<div class="vfoot">
<h3 id="vtitle">${channelTitle}</h3>
</div>`;
vdiv.onclick = function () {
setId(video);
};
//final append
right.append(vdiv);
});
}
let itis;
function myicon(){
let left = document.querySelector(".left");
let right = document.querySelector(".right");
let span = document.getElementsByTagName("span");
if(!itis){
left.style.width = "5rem";
right.style.width = "94vw"
// left.style.margin = "0rem"
for(let i=0; i<span.length; i++){
span[i].style.fontSize = "0.8rem";
span[i].style.textAlign = "left";
}
// left.style.
itis = true;
}else{
left.style.width = "15rem";
console.log("yes");
itis = false;
}
}
// routing and saving the
function setId(video) {
localStorage.setItem("id", JSON.stringify(video));
location.href = "/clicked.html";
}