${watchStatusIndicator}
@@ -400,6 +425,53 @@ function createPlayer(button) {
divPlayer.innerHTML = markup;
}
+// function sendSponsorBlockVote(uuid, vote) {
+// var videoId = getVideoPlayerVideoId();
+// postSponsorSegmentVote(videoId, uuid, vote);
+// }
+
+// var sponsorBlockTimestamps = [];
+// function sendSponsorBlockSegment() {
+// var videoId = getVideoPlayerVideoId();
+// var currentTime = getVideoPlayerCurrentTime();
+// var sponsorBlockElement = document.getElementById("sponsorblock");
+// if (sponsorBlockTimestamps[1]) {
+// if (sponsorBlockTimestamps[1] > sponsorBlockTimestamps[0]) {
+// postSponsorSegment(videoId, sponsorBlockTimestamps[0], sponsorBlockTimestamps[1]);
+// sponsorBlockElement.innerHTML = `
+//
Timestamps sent! (Not really)
+// `;
+// setTimeout(function(){
+// sponsorBlockElement.innerHTML = `
+//
Start
+// `;
+// }, 3000);
+// } else {
+// sponsorBlockElement.innerHTML = `
+//
Invalid Timestamps!
+// `;
+// setTimeout(function(){
+// sponsorBlockElement.innerHTML = `
+//
Start
+// `;
+// }, 3000);
+// }
+// sponsorBlockTimestamps = [];
+// } else if (sponsorBlockTimestamps[0]) {
+// sponsorBlockTimestamps.push(currentTime);
+// sponsorBlockElement.innerHTML = `
+//
${sponsorBlockTimestamps[0].toFixed(1)} s |
+//
${sponsorBlockTimestamps[1].toFixed(1)} s |
+//
Confirm
+// `;
+// } else {
+// sponsorBlockTimestamps.push(currentTime);
+// sponsorBlockElement.innerHTML = `
+//
End
+// `;
+// }
+// }
+
// Add video tag to video page when passed a video id, function loaded on page load `video.html (115-117)`
function insertVideoTag(videoData, videoProgress) {
var videoTag = createVideoTag(videoData, videoProgress);
@@ -488,6 +560,32 @@ function onVideoProgress() {
var videoId = getVideoPlayerVideoId();
var currentTime = getVideoPlayerCurrentTime();
var duration = getVideoPlayerDuration();
+ var videoElement = getVideoPlayer();
+ // var sponsorBlockElement = document.getElementById("sponsorblock");
+ var notificationsElement = document.getElementById("notifications");
+ if (sponsorBlock) {
+ for(let i in sponsorBlock) {
+ if(sponsorBlock[i].segment[0] <= currentTime + 0.3 && sponsorBlock[i].segment[0] >= currentTime) {
+ videoElement.currentTime = sponsorBlock[i].segment[1];
+ notificationsElement.innerHTML += ``;
+ }
+ // if(currentTime >= sponsorBlock[i].segment[1] && currentTime <= sponsorBlock[i].segment[1] + 0.2) {
+ // if(sponsorBlock[i].locked != 1) {
+ // sponsorBlockElement.innerHTML += `
+ // `;
+ // }
+ // }
+ if(currentTime > sponsorBlock[i].segment[1] + 10) {
+ var notificationsElementUUID = document.getElementById("notification-" + sponsorBlock[i].UUID);
+ if(notificationsElementUUID) {
+ notificationsElementUUID.outerHTML = '';
+ }
+ }
+ }
+ }
if ((currentTime % 10).toFixed(1) <= 0.2) { // Check progress every 10 seconds or else progress is checked a few times a second
postVideoProgress(videoId, currentTime);
if (!getVideoPlayerWatchStatus()) { // Check if video is already marked as watched
@@ -542,6 +640,32 @@ function formatNumbers(number) {
return numberFormatted;
}
+// Formats times in seconds for frontend
+function formatTime(time) {
+ var hoursUnformatted = time / 3600;
+ var minutesUnformatted = (time % 3600) / 60;
+ var secondsUnformatted = time % 60;
+
+ var hoursFormatted = Math.trunc(hoursUnformatted);
+ if(minutesUnformatted < 10 && hoursFormatted > 0) {
+ var minutesFormatted = "0" + Math.trunc(minutesUnformatted);
+ } else {
+ var minutesFormatted = Math.trunc(minutesUnformatted);
+ }
+ if(secondsUnformatted < 10) {
+ var secondsFormatted = "0" + Math.trunc(secondsUnformatted);
+ } else {
+ var secondsFormatted = Math.trunc(secondsUnformatted);
+ }
+
+ var timeUnformatted = '';
+ if(hoursFormatted > 0) {
+ timeUnformatted = hoursFormatted + ":"
+ }
+ var timeFormatted = timeUnformatted.concat(minutesFormatted, ":", secondsFormatted);
+ return timeFormatted;
+}
+
// Gets video data when passed video ID
function getVideoData(videoId) {
var apiEndpoint = "/api/video/" + videoId + "/";
@@ -599,6 +723,30 @@ function postVideoProgress(videoId, videoProgress) {
}
}
+// Send sponsor segment when given video id and and timestamps
+function postSponsorSegment(videoId, startTime, endTime) {
+ var apiEndpoint = "/api/video/" + videoId + "/sponsor/";
+ var data = {
+ "segment": {
+ "startTime": startTime,
+ "endTime": endTime
+ }
+ };
+ apiRequest(apiEndpoint, "POST", data);
+}
+
+// Send sponsor segment when given video id and and timestamps
+function postSponsorSegmentVote(videoId, uuid, vote) {
+ var apiEndpoint = "/api/video/" + videoId + "/sponsor/";
+ var data = {
+ "vote": {
+ "uuid": uuid,
+ "yourVote": vote
+ }
+ };
+ apiRequest(apiEndpoint, "POST", data);
+}
+
// Makes api requests when passed an endpoint and method ("GET", "POST", "DELETE")
function apiRequest(apiEndpoint, method, data) {
const xhttp = new XMLHttpRequest();