Adds the ability to play youtube videos.
It still needs a bit of work, but playing and pausing are operational.
This commit is contained in:
76
add-on/youtube.js
Normal file
76
add-on/youtube.js
Normal file
@@ -0,0 +1,76 @@
|
||||
console.debug("Loading youtube.js")
|
||||
var video;
|
||||
|
||||
function onload()
|
||||
{
|
||||
video = document.getElementsByClassName('video-stream html5-main-video')[0]
|
||||
}
|
||||
|
||||
function getState()
|
||||
{
|
||||
if (!video)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
else if (video.ended)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
else if (video.paused)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function getTime()
|
||||
{
|
||||
return video.currentTime;
|
||||
}
|
||||
|
||||
function getLength()
|
||||
{
|
||||
return video.duration;
|
||||
}
|
||||
|
||||
function play()
|
||||
{
|
||||
if (video != null)
|
||||
{
|
||||
video.play();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function pause()
|
||||
{
|
||||
if (video != null)
|
||||
{
|
||||
video.pause();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function seek(time)
|
||||
{
|
||||
if (video != null)
|
||||
{
|
||||
video.currentTime = time;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (document.readyState === "complete")
|
||||
{
|
||||
onload();
|
||||
}
|
||||
else
|
||||
{
|
||||
window.addEventListener("load", onload);
|
||||
}
|
||||
Reference in New Issue
Block a user