-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfsyoutube_sugarcube.js
112 lines (95 loc) · 2.63 KB
/
fsyoutube_sugarcube.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
//var a=function(){"use strict"; var Macro={};
var player_div='fsyoutube';
var macro_play_video=function(player,videoid,seconds){
show_player_div();
player.loadPlaylist(videoid,0,seconds);
player.setLoop(true);
}
var initialize_video=function(videoid,seconds){
var getWindowRenderedSize = function(){
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
return [x,y];
}
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var bodyTag = document.getElementsByTagName('body')[0];
var playerTag = document.createElement('div');
playerTag.id=player_div;
var firstChildElementTag = bodyTag.firstElementChild;
firstChildElementTag.parentNode.insertBefore(playerTag,firstChildElementTag);
var windowsize = getWindowRenderedSize();
var windowX = windowsize[0];
var windowY = windowsize[1];
var player;
window.player=player;
window.playerTag=playerTag;
show_player_div();
window.onYouTubeIframeAPIReady=function(){
var player = new YT.Player(player_div, {
playerVars: {
'autoplay': 1,
'controls': 0,
'showinfo': 0,
'modestbranding': 1},
height: windowY,
width: windowX,
events: {'onReady':
function(e){
var player=e.target;
macro_play_video(player,videoid,seconds);
}
}});
}
}
var hide_player_div = function() {
window.document.getElementById(player_div).style.display="none";
}
var show_player_div = function() {
window.document.getElementById(player_div).style.display="";
}
Macro.add('fsyoutube', {
//macros.fsyoutube={
handler: function() {
var videoid=this.args[0];
console.log(videoid);
if (typeof(YT)==="undefined") {
initialize_video(videoid,0);
} else {
var player=YT.get(player_div);
macro_play_video(player,videoid,0);
}
}}
);
Macro.add('fsyoutube_jump',{
//macros.fsyoutube_jump={
handler: function() {
var videoid=this.args[0];
var seconds=this.args[1];
if (typeof(YT)==="undefined") {
initialize_video(videoid,seconds);
} else {
var player=YT.get(player_div);
macro_play_video(player,videoid,seconds);
}
}}
);
Macro.add('fsyoutube_stop',{
//macros.fsyoutube_stop={
handler: function() {
if (typeof(YT)==="undefined") {
// Nothing to do yet :D
} else {
var player=YT.get(player_div);
player.stopVideo();
hide_player_div();
}
}}
);
};