-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackoverflow-chat.js
More file actions
137 lines (113 loc) · 4.84 KB
/
stackoverflow-chat.js
File metadata and controls
137 lines (113 loc) · 4.84 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
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
{
var youtube;
document.documentElement.style.cssText = 'width:100%;height:100%;';
var par = document.createElement('div');
par.style.cssText = 'position:fixed;left:0;top:0;width:100%;height:100%;z-index:-1';opacity:0.3;;
document.body.append(par);
var script = document.createElement('script');
script.src = "https://www.youtube.com/iframe_api";
document.head.appendChild(script);
function onYouTubeIframeAPIReady(){
youtube = new YT.Player(par,{
width : '100%',
height : '100%',
videoId : 'hrotHC9OPr4',
playerVars : {
autoplay : 1,
controls : 1,
disablekb : 1,
enablejsapi : 1,
fs : 0,
iv_load_policy : 3,
loop : 1,
modestbranding : 1,
playsinline : 1,
rel : 0
},
events : {
onReady : ready,
}
});
console.log(youtube);
}//onload
function ready(event){
var {w,h,scale} = resize();
var iframe = youtube.g; // document.querySelector('iframe');
iframe.style.width = w+'px';
iframe.style.height = h+'px';
iframe.style.transform = scale;
iframe.style.transformOrigin = 'top left';
youtube.unMute();
youtube.setVolume(20);
youtube.playVideo();
play();
}//ready
function resize(){
var aspect = 16/9;
var winw = window.innerWidth;
var winh = window.innerHeight;
var w = winw;
var h = winw/aspect;
var sf = winh/h;
var scale = 'scaleY('+sf+')';
var t = sf*h;
if(h>winh){
h = winh;
w = winh*aspect;
sf = winw/w;
scale = 'scaleX('+sf+')';
t = sf*w;
}
return {w,h,scale};
}//resize
function play(){
var btn=document.createElement('button');
btn.style.cssText = `
position:fixed;left:0px;right:0;top:20px;width:150px;
padding:10px;margin:auto;font-size:24px;z-index:999999;
border:3px solid rgb(252,15,192);border-radius:5px;
`;
btn.textContent = 'play';
btn.onclick = e=>{
youtube.playVideo();
youtube.unMute();
btn.remove();
};
document.body.append(btn);
}//play
var styletxt=`
.mine .messages {
background-color : rgba(251,242,217,0.6);
}
.messages {
background-color : rgba(246,246,246,0.6);
}
.messages {
border-radius : 6px;
border : none;
padding : 5px 5px 5px 0px;
float : left;
word-wrap : break-word;
width : 87%;
color : #222;
font-weight : bold;
}
`;
var style = document.createElement('style');
style.textContent = styletxt;
document.body.append(style);
}
/*
youtube.mute();
youtube.unMute();
youtube.setVolume(10); // 0-100
youtube.playVideo();
youtube.stopVideo();
youtube.loadVideoById('VLfPUJCPDqY') // Cozy Cottage by the Sea
youtube.loadVideoById('QOf1Gf6FPGI') // Thunderstorm Rain on Tin Roof
youtube.loadVideoById('hrotHC9OPr4') // City Nights - Deep House Mix
youtube.loadVideoById('vfl5La6G9tQ') // Heavy Thunderstorm
youtube.loadVideoById('Mw9qiV7XlFs') // train ride switzerland
youtube.g.remove();
https://developers.google.com/youtube/iframe_api_reference
*/