mirror of
https://github.com/Michatec/ptelevision.git
synced 2026-03-31 23:46:30 +02:00
Update main.js
This commit is contained in:
147
html/main.js
147
html/main.js
@@ -4,104 +4,124 @@ var playerData;
|
|||||||
function GetURLID(link) {
|
function GetURLID(link) {
|
||||||
if (link == null) return;
|
if (link == null) return;
|
||||||
let url = link.toString();
|
let url = link.toString();
|
||||||
var regExp = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
var regExp =
|
||||||
|
/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
||||||
var match = url.match(regExp);
|
var match = url.match(regExp);
|
||||||
if (match && match[2].length == 11) {
|
if (match && match[2].length == 11) {
|
||||||
return { type: "youtube", id: match[2] };
|
return { type: "youtube", id: match[2] };
|
||||||
}
|
} else if (url.split("twitch.tv/").length > 1) {
|
||||||
else if (url.split("twitch.tv/").length > 1) {
|
|
||||||
|
|
||||||
return { type: "twitch", id: url.split("twitch.tv/")[1] };
|
return { type: "twitch", id: url.split("twitch.tv/")[1] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ChannelDisplay(channel, channelFound) {
|
function ChannelDisplay(channel, channelFound) {
|
||||||
if (channel) {
|
if (channel) {
|
||||||
var temp = 'CH<span style="font-size: 18pt !important;"> </span>'
|
var temp = 'CH<span style="font-size: 18pt !important;"> </span>';
|
||||||
if (channel > 9) {
|
if (channel > 9) {
|
||||||
temp += channel
|
temp += channel;
|
||||||
|
} else {
|
||||||
|
temp += "0" + channel;
|
||||||
}
|
}
|
||||||
else {
|
$("#overlay span").show();
|
||||||
temp += ("0" + channel)
|
$("#overlay span").html(temp);
|
||||||
}
|
} else {
|
||||||
$("#overlay span").show()
|
$("#overlay span").show();
|
||||||
$("#overlay span").html(temp)
|
$("#overlay span").html("");
|
||||||
}
|
|
||||||
else {
|
|
||||||
$("#overlay span").show()
|
|
||||||
$("#overlay span").html("")
|
|
||||||
}
|
}
|
||||||
if (channelFound) {
|
if (channelFound) {
|
||||||
$("#tv-container").hide()
|
$("#tv-container").hide();
|
||||||
}
|
} else {
|
||||||
else {
|
$("#tv-container").show();
|
||||||
$("#tv-container").show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetVideo(video_data) {
|
function SetVideo(video_data) {
|
||||||
var url = video_data.url;
|
var url = video_data.url;
|
||||||
var channel = video_data.channel;
|
var channel = video_data.channel;
|
||||||
var data = GetURLID(url)
|
var loop = video_data.loop;
|
||||||
|
var showControls = Number(video_data.showControls);
|
||||||
|
var data = GetURLID(url);
|
||||||
|
|
||||||
playerData = data
|
playerData = data;
|
||||||
if (player) {
|
if (player) {
|
||||||
player.destroy()
|
player.destroy();
|
||||||
player = null;
|
player = null;
|
||||||
}
|
}
|
||||||
if (data) {
|
if (data) {
|
||||||
if (data.type == "youtube") {
|
if (data.type == "youtube") {
|
||||||
player = new YT.Player('twitch-embed', {
|
if (loop == true) {
|
||||||
height: '100%',
|
player = new YT.Player("twitch-embed", {
|
||||||
width: '100%',
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
videoId: data.id,
|
videoId: data.id,
|
||||||
playerVars: {
|
playerVars: {
|
||||||
'playsinline': 1,
|
playsinline: 1,
|
||||||
|
loop: 1,
|
||||||
|
playlist: data.id,
|
||||||
|
controls: showControls,
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
'onReady': function(event) {
|
onReady: function (event) {
|
||||||
event.target.playVideo();
|
event.target.playVideo();
|
||||||
event.target.seekTo(video_data.time)
|
event.target.seekTo(video_data.time);
|
||||||
},
|
},
|
||||||
'onStateChange': function(event) {
|
onStateChange: function (event) {
|
||||||
if (event.data == YT.PlayerState.PLAYING) {
|
if (event.data == YT.PlayerState.PLAYING) {
|
||||||
event.target.unMute();
|
event.target.unMute();
|
||||||
|
} else if (event.data == YT.PlayerState.PAUSED) {
|
||||||
}
|
}
|
||||||
else if (event.data == YT.PlayerState.PAUSED) {
|
},
|
||||||
|
},
|
||||||
}
|
});
|
||||||
}
|
} else {
|
||||||
|
player = new YT.Player("twitch-embed", {
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
videoId: data.id,
|
||||||
|
playerVars: {
|
||||||
|
playsinline: 1,
|
||||||
|
controls: showControls,
|
||||||
|
},
|
||||||
|
events: {
|
||||||
|
onReady: function (event) {
|
||||||
|
event.target.playVideo();
|
||||||
|
event.target.seekTo(video_data.time);
|
||||||
|
},
|
||||||
|
onStateChange: function (event) {
|
||||||
|
if (event.data == YT.PlayerState.PLAYING) {
|
||||||
|
event.target.unMute();
|
||||||
|
} else if (event.data == YT.PlayerState.PAUSED) {
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (data.type == "twitch") {
|
} else if (data.type == "twitch") {
|
||||||
player = new Twitch.Player("twitch-embed", {
|
player = new Twitch.Player("twitch-embed", {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
channel: data.id,
|
channel: data.id,
|
||||||
volume: 1.0
|
volume: 1.0,
|
||||||
});
|
});
|
||||||
player.addEventListener(Twitch.Embed.VIDEO_READY, function () {
|
player.addEventListener(Twitch.Embed.VIDEO_READY, function () {
|
||||||
player.setMuted(false);
|
player.setMuted(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#overlay span").hide()
|
$("#overlay span").hide();
|
||||||
$("#tv-container").hide()
|
$("#tv-container").hide();
|
||||||
}
|
}
|
||||||
if (channel) {
|
if (channel) {
|
||||||
ChannelDisplay(channel, url)
|
ChannelDisplay(channel, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetVolume(volume) {
|
function SetVolume(volume) {
|
||||||
|
|
||||||
if (player && playerData && player.setVolume) {
|
if (player && playerData && player.setVolume) {
|
||||||
if (playerData.type == "twitch") {
|
if (playerData.type == "twitch") {
|
||||||
player.setMuted(false);
|
player.setMuted(false);
|
||||||
player.setVolume(volume / 100.0);
|
player.setVolume(volume / 100.0);
|
||||||
}
|
} else if (playerData.type == "youtube") {
|
||||||
else if (playerData.type == "youtube") {
|
|
||||||
player.unMute();
|
player.unMute();
|
||||||
player.setVolume(volume);
|
player.setVolume(volume);
|
||||||
}
|
}
|
||||||
@@ -109,34 +129,37 @@ function SetVolume(volume) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ShowNotification(channel, data) {
|
function ShowNotification(channel, data) {
|
||||||
$("#tv-container").addClass("notify")
|
$("#tv-container").addClass("notify");
|
||||||
$("#tv-container div").addClass("notify")
|
$("#tv-container div").addClass("notify");
|
||||||
var display = $('#tv-container').is(':visible')
|
var display = $("#tv-container").is(":visible");
|
||||||
$('#tv-container').show()
|
$("#tv-container").show();
|
||||||
$("#tv-container div").html("Channel #" + channel + (data ? (" ("+data.name+")") : "") + " is now " + (data ? "live!" : "offline."))
|
$("#tv-container div").html(
|
||||||
|
"Channel #" +
|
||||||
|
channel +
|
||||||
|
(data ? " (" + data.name + ")" : "") +
|
||||||
|
" is now " +
|
||||||
|
(data ? "live!" : "offline.")
|
||||||
|
);
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$("#tv-container").removeClass("notify")
|
$("#tv-container").removeClass("notify");
|
||||||
$("#tv-container div").removeClass("notify")
|
$("#tv-container div").removeClass("notify");
|
||||||
$("#tv-container div").html("NO SIGNAL")
|
$("#tv-container div").html("NO SIGNAL");
|
||||||
if (!display) {
|
if (!display) {
|
||||||
$('#tv-container').hide()
|
$("#tv-container").hide();
|
||||||
}
|
}
|
||||||
}, 3500)
|
}, 3500);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("message", function (ev) {
|
window.addEventListener("message", function (ev) {
|
||||||
if (ev.data.setVideo) {
|
if (ev.data.setVideo) {
|
||||||
SetVideo(ev.data.data)
|
SetVideo(ev.data.data);
|
||||||
|
} else if (ev.data.setVolume) {
|
||||||
|
SetVolume(ev.data.data);
|
||||||
|
} else if (ev.data.showNotification) {
|
||||||
|
ShowNotification(ev.data.channel, ev.data.data);
|
||||||
}
|
}
|
||||||
else if (ev.data.setVolume) {
|
});
|
||||||
SetVolume(ev.data.data)
|
|
||||||
}
|
|
||||||
else if (ev.data.showNotification) {
|
|
||||||
ShowNotification(ev.data.channel, ev.data.data)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
ChannelDisplay()
|
ChannelDisplay();
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user