-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshiv_dev.html
118 lines (105 loc) · 2.6 KB
/
shiv_dev.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
<!DOCTYPE html>
<head>
<script src="https://www.youtube.com/iframe_api"></script>
<style>
html, body {
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
</head>
<body>
<div id="player"></div>
<script>
var player;
var createPlayer = function() {
player = new YT.Player('player', {
height: '100%',
width: '100%',
videoId: getQueryVariable('v'),
playerVars: {
'playsinline': 1,
'showinfo': 0,
'rel': 0,
'disablekb': 1,
'iv_load_policy': 3,
'origin': 'http://webrender.net'
},
events: {
'onReady': muteCheck
}
});
}
var muteCheck = function(event) {
if (getQueryVariable('mute')){
player.mute();
}
}
var getQueryVariable = function(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
}
if (YT.Player) {
createPlayer();
} else {
window.onYouTubeIframeAPIReady = function() {
createPlayer();
};
}
window.addEventListener("message", receiveMessage);
function receiveMessage(message) {
var origin = message.origin || message.originalEvent.origin; // For Chrome, the origin property is in the event.originalEvent object.
var validOrigins = {
'https://www.youtube.com': true,
'http://webrender.net': true,
'http://localhost:8080': true,
'http://popupvid.io': true
}
if (!validOrigins[origin])
return;
var commands = {
'infoDelivery': updateState,
'onReady': onReady,
'playVideo': playVideo,
'pauseVideo': pauseVideo,
'seekTo': seekTo
}
var msg = JSON.parse(message.data);
if (commands[msg.event]) {
commands[msg.event](msg);
}
}
function sendMessage(message) {
parent.postMessage(JSON.stringify(message), 'http://localhost:8080');
// parent.postMessage(JSON.stringify(message), 'http://popupvid.io');
}
var playVideo = function() {
player.playVideo();
}
var pauseVideo = function() {
player.pauseVideo();
}
var seekTo = function (msg) {
player.seekTo(msg.time);
}
var updateState = function(msg) {
sendMessage({
'event':'updateState',
'state':msg.info
});
}
var onReady = function() {
sendMessage({
'event':'playerReady'
});
}
</script>
</body>