-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.html
159 lines (151 loc) · 5.3 KB
/
player.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,1,0" />
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="text-align:center" class="body">
<div id="player"></div>
<div style="height:2%" id="ws"></div>
<img id="thumb" class="thumbnail">
<div id="control">
<div class="ta">
<h1 id="t">Loading...</h1>
<p id="a"></p>
</div>
<input type="range" id="prog" min="0" onchange="player.seekTo(this.value,true)" style="width:75%"><br>
<div class="btns">
<span onclick="playlistItem(true)" class="material-symbols-outlined controls" style="display:none" id="sp">skip_previous</span>
<span onclick="pToggle()" id="b" class="material-symbols-outlined controls">play_circle</span>
<span onclick="playlistItem()" id="sn" class="material-symbols-outlined controls" style="display:none">skip_next</span>
</div>
</div>
<script>
prog.value = 0
var vidId = new URLSearchParams(window.location.search).get("v")
var playlistString = new URLSearchParams(window.location.search).get("list")
var theme = new URLSearchParams(window.location.search).get("theme")
if (theme) {
document.documentElement.style = atob(theme)
}
if (playlistString) {
var playlist = playlistString.split(",")
sn.style = "";
sp.style = "";
if (vidId) {
var currentVid = playlist.indexOf(vidId)
} else {
var currentVid = 0
}
vidId = playlist[currentVid]
if (currentVid == 0) {
sp.style = "visibility:hidden"
} else {
sp.style = ""
}
if (currentVid == (playlist.length - 1)) {
sn.style = "visibility:hidden"
} else {
sn.style = ""
}
}
function screenOff() {
player.playVideo()
}
function playlistItem(back) {
prog.value = 0;
thumb.src = "";
t.innerHTML = "Loading..."
a.innerHTML = ""
if (back) {
currentVid -= 1
} else {
currentVid += 1
}
if (currentVid == 0) {
sp.style = "visibility:hidden"
} else {
sp.style = ""
}
if (currentVid == (playlist.length - 1)) {
sn.style = "visibility:hidden"
} else {
sn.style = ""
}
vidId = playlist[currentVid]
player.playVideo()
}
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 player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '0',
width: '0',
videoId: vidId,
playerVars: {
'playsinline': 1
},
events: {
'onReady': function() {
player.playVideo();
timeouts.push(setTimeout(function() {t.innerHTML = "<span style='color:red'>Playback Error</span>"},1000))
},
'onStateChange': onPlayerStateChange
}
});
}
var timeouts = [];
function onPlayerStateChange(event) {
console.log(event.data)
switch (event.data) {
case YT.PlayerState.PAUSED: b.innerHTML = "play_circle";
break;
case YT.PlayerState.PLAYING: b.innerHTML = "pause_circle"; loadMeta();
break;
case YT.PlayerState.ENDED: b.innerHTML = "play_circle";clearInterval(progInt); if (playlist) {playlistItem()}
break;
case YT.PlayerState.UNSTARTED: timeouts.push(setTimeout(function() {t.innerHTML = "<span style='color:red'>Playback Error</span>"},1000))
break;
case YT.PlayerState.BUFFERING: timeouts.forEach(function(k) {clearTimeout(k)});
}
}
function pToggle() {
if (b.innerHTML == "pause_circle") {
player.pauseVideo()
} else if (b.innerHTML == "play_circle") {
player.playVideo()
}
}
var progInt;
function loadMeta() {
t.innerText = player.playerInfo.videoData.title
a.innerText = player.playerInfo.videoData.author.replace(" - Topic","")
thumb.src = "https://img.youtube.com/vi/" + vidId + "/maxresdefault.jpg"
prog.max = player.playerInfo.duration
progInt = setInterval(function () {
prog.value = player.playerInfo.currentTime
},1000)
}
if (window.top.location.href == "https://justmusic.pages.dev/") {
var toggle = document.createElement("div")
toggle.classList = "material-symbols-outlined"
toggle.id = "toggle"
toggle.onclick = function() {
if (toggle.innerHTML == "keyboard_arrow_down") {
window.top.minimize()
toggle.innerHTML = "keyboard_arrow_up"
} else {
window.top.maximize()
toggle.innerHTML = "keyboard_arrow_down"
}
}
toggle.innerHTML = "keyboard_arrow_down"
document.documentElement.appendChild(toggle)
}
</script>
</body>
</html>