-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.js
More file actions
80 lines (60 loc) · 2.21 KB
/
preview.js
File metadata and controls
80 lines (60 loc) · 2.21 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
var viewData = JSON.parse(localStorage.getItem("viewData"));
var temporary = [];
const recomend_show = (arr)=>{
document.getElementById("recomend").innerHTML="";
arr.map((obj)=>{
var div = document.createElement("div");
div.addEventListener("click",function(){
makearrY(obj);
});
var imgdiv = document.createElement("div");
imgdiv.id="img";
var titlediv = document.createElement("div");
titlediv.id = "title";
var thumb = document.createElement("img");
thumb.src = obj.snippet.thumbnails.medium.url;
thumb.id = "thumb";
var title = document.createElement("h6");
title.textContent =obj.snippet.title;
var channel = document.createElement("span");
channel.textContent = obj.snippet.channelTitle;
imgdiv.append(thumb);
titlediv.append(title,channel);
div.append(imgdiv,titlediv);
document.getElementById("recomend").append(div);
})
}
const recomend_search = async (se)=>{
var key = "AIzaSyA3LTSJMoPaTQS4EGiGsPAwNJxOVSSZofo";
var input = se;
try{
var res3 = await fetch(`https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=20&q=${input}&type=video&key=${key}`);
var data3 = await res3.json();
var dtaarray3 = data3.items;
recomend_show(dtaarray3);
}
catch(err){
console.log(err)
}
}
const viewvideo = (arr)=>{
arr.map((obj)=>{
const {id:{videoId},} = obj;
var vide = document.getElementById("ifrem");
vide.src = `https://www.youtube.com/embed/${videoId}`;
var title = document.createElement("h6");
title.textContent =obj.snippet.title;
var channel = document.createElement("p");
channel.textContent = obj.snippet.channelTitle;
var des = document.createElement("p");
des.textContent = obj.snippet.description;
document.getElementById("videodiv").append(title,channel,des)
recomend_search(obj.snippet.channelTitle);
})
}
viewvideo(viewData);
const makearrY =(obj)=>{
temporary.push(obj);
localStorage.setItem("viewData",JSON.stringify(temporary));
window.location.href = "view.html";
}