-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfnfscript.js
More file actions
104 lines (92 loc) · 2.33 KB
/
Copy pathfnfscript.js
File metadata and controls
104 lines (92 loc) · 2.33 KB
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
var songs = [
"18--CryqPp8", //done
"n-mw_03jWaY", //done
"ydrRQE1r1NA", //done
"y0D1yCCl5Xc", //done
"woieXASPZxQ", //done
"GTbwHQ4zU2Y", //done
"UM4ttc1eLas", //done
"BKuucLrUL6g", //done
"WMjytiClUzw", //done
"7ZxaTLpdwD0", //done
"-KjGi6eNRyE", //done
"1d2vojMHvC0", //done
"MLNAHrHreCY", //done
"pHdObRZyAdI", //done
"Rk7GquhH7Wc", //done
"T33bLx9b43s", //done
"LhqUNpPPz5c" //done
]
var songCounter = document.getElementById("song-counter")
songCounter.innerHTML = songs.length
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() {
var videoId;
if (localStorage.getItem("currentSong-FNF")) {
videoId = localStorage.getItem("currentSong-FNF");
}
else {
videoId = songs[getRndInteger(0, songs.length-1)];
}
player = new YT.Player('video', {
height: '390',
width: '640',
videoId: videoId,
playerVars: {
'playsinline': 1
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
console.log("coolio")
startNewSong()
}
}
function startNewSong() {
var newSong = getNewSong()
localStorage.setItem("currentSong-FNF", newSong)
player.loadVideoById(newSong, 0)
}
function stopVideo() {
player.stopVideo();
}
document.addEventListener("beforeunload", function () {
if (player.getPlayerState() == 1) {
localStorage.setItem("song_timestamp", player.getElapsedTime())
}
})
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getSongId() {
var str = player.getVideoUrl()
str = str.substring(32)
return str
}
function getNewSong() {
var newSong = songs[getRndInteger(0, songs.length-1)]
if (!(newSong == getSongId())) {
return newSong
}
else {
newSong = getNewSong()
return newSong
}
}