-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
116 lines (113 loc) · 4.32 KB
/
index.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
113
114
115
116
var link = window.location.href;
function video(q){
var api = "AIzaSyDf-TCgD54NNSlg_PbqeJyhXWhn0B4WBzw";
var url = "https://www.googleapis.com/youtube/v3/search?part=id&q="+q+"&type=video&key="+api;
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
function getEl(id, value){
document.getElementById(id).innerHTML = (value);
}
function YT(id){
getEl('YTPlayer', '<iframe id="ytplayer" type="text/html" src="https://www.youtube.com/embed/'+id+'?autoplay=1&color=white&showinfo=0&rel=0" allowfullscreen frameborder="0"></iframe>');
}
function vdImage(no){
return '<a href="watch.html?'+no+'"><img class="responsive-img" src="https://i.ytimg.com/vi/'+no+'/mqdefault.jpg" /></a>';
}
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var status = xhr.status;
if ((status >= 200 && status < 300) || status === 304) {
var rss = JSON.parse(xhr.responseText);
var videoId = rss.items[0].id.videoId;
YT(videoId);
link += '~';
link += videoId;
details(videoId);
stats(videoId);
var secVid = rss.items[1].id.videoId;
var thVid = rss.items[2].id.videoId;
var frthVid = rss.items[3].id.videoId;
getEl('simHead', 'Similar Video Results');
getEl('secVid', vdImage(secVid));
getEl('thVid', vdImage(thVid));
getEl('frthVid', vdImage(frthVid));
similar(secVid, 'secVid');
similar(thVid, 'thVid');
similar(frthVid, 'frthVid');
} else {
alert("Request unsuccessful");
}
}
};
xhr.send(null);
}
function details(videoId){
var hell = new XMLHttpRequest;
var url2 = "https://www.googleapis.com/youtube/v3/videos?part=snippet&id="+videoId+"&key=AIzaSyDf-TCgD54NNSlg_PbqeJyhXWhn0B4WBzw";
hell.open("GET", url2, true);
hell.onreadystatechange = function(){
if( hell.readyState === 4 ){
var status = hell.status;
if((status >= 200 && status < 300) || status === 304){
var rss = JSON.parse(hell.responseText);
var titleY = rss.items[0].snippet.title;
document.title = (titleY);
document.getElementById('titleY').innerHTML = titleY;
var channel = rss.items[0].snippet.channelTitle;
document.getElementById('desc').innerHTML = channel;
var fbButton = document.getElementById('fb-share-button');
var url = "https://ytqck.github.io/watch.html?"+videoId;
document.getElementById('linkShare').innerHTML = url;
url += '"e='+titleY;
fbButton.addEventListener('click', function() {
window.open('https://www.facebook.com/sharer/sharer.php?u=' + url,
'facebook-share-dialog',
'width=800,height=600'
);
return false;
});
} else {
alert("Request unsuccessful");
}
}
};
hell.send(null);
}
function stats(videoId){
var hell = new XMLHttpRequest;
var url2 = "https://www.googleapis.com/youtube/v3/videos?part=statistics&id="+videoId+"&key=AIzaSyDf-TCgD54NNSlg_PbqeJyhXWhn0B4WBzw";
hell.open("GET", url2, true);
hell.onreadystatechange = function(){
if(hell.readyState === 4){
var status = hell.status;
if((status >= 200 && status < 300) || status === 304){
var rss = JSON.parse(hell.responseText);
var views = rss.items[0].statistics.viewCount;
document.getElementById('viewsCount').innerHTML = (views + ' views')
} else {
alert("Request unsuccessful");
}
}
};
hell.send(null);
}
function similar(videoId, id){
var hell = new XMLHttpRequest;
var url2 = "https://www.googleapis.com/youtube/v3/videos?part=snippet&id="+videoId+"&key=AIzaSyDf-TCgD54NNSlg_PbqeJyhXWhn0B4WBzw";
hell.open("GET", url2, true);
hell.onreadystatechange = function(){
if( hell.readyState === 4 ){
var status = hell.status;
if((status >= 200 && status < 300) || status === 304){
var rss = JSON.parse(hell.responseText);
var titleY = rss.items[0].snippet.title;
document.title = (titleY);
id = id + 'De';
document.getElementById(id).innerHTML = titleY;
} else {
alert("Request unsuccessful");
}
}
};
hell.send(null);
}