diff --git a/tubearchivist/home/templates/home/channel_id.html b/tubearchivist/home/templates/home/channel_id.html index 1198a15..3a84037 100644 --- a/tubearchivist/home/templates/home/channel_id.html +++ b/tubearchivist/home/templates/home/channel_id.html @@ -124,9 +124,9 @@
Last refreshed: {{ video.vid_last_refresh }}
Watched: {% if video.player.watched %} - + {% else %} - + {% endif %}
{% if video.active %} diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index acc592a..6e5c818 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -8,21 +8,62 @@ function sortChange(sortValue) { }, 500); } -function isWatched(youtube_id) { - postVideoProgress(youtube_id, 0); // Reset video progress on watched; - removeProgressBar(youtube_id); - var payload = JSON.stringify({'watched': youtube_id}); - sendPost(payload); - var seenIcon = document.createElement('img'); - seenIcon.setAttribute('src', "/static/img/icon-seen.svg"); - seenIcon.setAttribute('alt', 'seen-icon'); - seenIcon.setAttribute('id', youtube_id); - seenIcon.setAttribute('title', "Mark as unwatched"); - seenIcon.setAttribute('onclick', "isUnwatched(this.id)"); - seenIcon.classList = 'seen-icon'; - document.getElementById(youtube_id).replaceWith(seenIcon); +// Updates video watch status when passed a video id and it's current state (ex if the video was unwatched but you want to mark it as watched you will pass "unwatched") +function updateVideoWatchStatus(input1, videoCurrentWatchStatus) { + if (videoCurrentWatchStatus) { + videoId = input1; + } else if (input1.getAttribute("data-id")) { + videoId = input1.getAttribute("data-id"); + videoCurrentWatchStatus = input1.getAttribute("data-status"); + } + + postVideoProgress(videoId, 0); // Reset video progress on watched/unwatched; + removeProgressBar(videoId); + + if (videoCurrentWatchStatus == "watched") { + var watchStatusIndicator = createWatchStatusIndicator(videoId, "unwatched"); + var payload = JSON.stringify({'un_watched': videoId}); + sendPost(payload); + } else if (videoCurrentWatchStatus == "unwatched") { + var watchStatusIndicator = createWatchStatusIndicator(videoId, "watched"); + var payload = JSON.stringify({'watched': videoId}); + sendPost(payload); + } + + var watchButtons = document.getElementsByClassName("watch-button"); + for (let i = 0; i < watchButtons.length; i++) { + if (watchButtons[i].getAttribute("data-id") == videoId) { + watchButtons[i].outerHTML = watchStatusIndicator; + } + } } +// Creates a watch status indicator when passed a video id and the videos watch status +function createWatchStatusIndicator(videoId, videoWatchStatus) { + if (videoWatchStatus == "watched") { + var seen = "seen"; + var title = "Mark as unwatched"; + } else if (videoWatchStatus == "unwatched") { + var seen = "unseen"; + var title = "Mark as watched"; + } + var watchStatusIndicator = ``; + return watchStatusIndicator; +} + +// function isWatched(youtube_id) { +// var payload = JSON.stringify({'watched': youtube_id}); +// sendPost(payload); +// var seenIcon = document.createElement('img'); +// seenIcon.setAttribute('src', "/static/img/icon-seen.svg"); +// seenIcon.setAttribute('alt', 'seen-icon'); +// seenIcon.setAttribute('id', youtube_id); +// seenIcon.setAttribute('title', "Mark as unwatched"); +// seenIcon.setAttribute('onclick', "isUnwatched(this.id)"); +// seenIcon.classList = 'seen-icon'; +// document.getElementById(youtube_id).replaceWith(seenIcon); +// } + // Removes the progress bar when passed a video id function removeProgressBar(videoId) { setProgressBar(videoId, 0, 1); @@ -39,19 +80,19 @@ function isWatchedButton(button) { }, 1000); } -function isUnwatched(youtube_id) { - postVideoProgress(youtube_id, 0); // Reset video progress on unwatched; - var payload = JSON.stringify({'un_watched': youtube_id}); - sendPost(payload); - var unseenIcon = document.createElement('img'); - unseenIcon.setAttribute('src', "/static/img/icon-unseen.svg"); - unseenIcon.setAttribute('alt', 'unseen-icon'); - unseenIcon.setAttribute('id', youtube_id); - unseenIcon.setAttribute('title', "Mark as watched"); - unseenIcon.setAttribute('onclick', "isWatched(this.id)"); - unseenIcon.classList = 'unseen-icon'; - document.getElementById(youtube_id).replaceWith(unseenIcon); -} +// function isUnwatched(youtube_id) { +// postVideoProgress(youtube_id, 0); // Reset video progress on unwatched; +// var payload = JSON.stringify({'un_watched': youtube_id}); +// sendPost(payload); +// var unseenIcon = document.createElement('img'); +// unseenIcon.setAttribute('src', "/static/img/icon-unseen.svg"); +// unseenIcon.setAttribute('alt', 'unseen-icon'); +// unseenIcon.setAttribute('id', youtube_id); +// unseenIcon.setAttribute('title', "Mark as watched"); +// unseenIcon.setAttribute('onclick', "isWatched(this.id)"); +// unseenIcon.classList = 'unseen-icon'; +// document.getElementById(youtube_id).replaceWith(unseenIcon); +// } function unsubscribe(id_unsub) { var payload = JSON.stringify({'unsubscribe': id_unsub}); @@ -327,7 +368,7 @@ function createPlayer(button) { var channelName = videoData.data.channel.channel_name; removePlayer(); - document.getElementById(videoId).outerHTML = ''; // Remove watch indicator from video info + // document.getElementById(videoId).outerHTML = ''; // Remove watch indicator from video info // If cast integration is enabled create cast button var castButton = ''; @@ -337,12 +378,11 @@ function createPlayer(button) { // Watched indicator if (videoData.data.player.watched) { - var playerState = "seen"; - var watchedFunction = "Unwatched"; + var watchStatusIndicator = createWatchStatusIndicator(videoId, "watched"); } else { - var playerState = "unseen"; - var watchedFunction = "Watched"; + var watchStatusIndicator = createWatchStatusIndicator(videoId, "unwatched"); } + var playerStats = `