chore: don't need to load script.js anymore

This commit is contained in:
Sean Norwood 2022-04-06 18:48:12 +00:00
parent 42ff29c13d
commit 4e4db8f0ae
2 changed files with 556 additions and 551 deletions

View File

@ -1,6 +1,5 @@
function sortChange(sortValue) {
var payload = JSON.stringify({'sort_order': sortValue});
var payload = JSON.stringify({ sort_order: sortValue });
sendPost(payload);
setTimeout(function () {
location.reload();
@ -22,11 +21,11 @@ function updateVideoWatchStatus(input1, videoCurrentWatchStatus) {
if (videoCurrentWatchStatus == "watched") {
var watchStatusIndicator = createWatchStatusIndicator(videoId, "unwatched");
var payload = JSON.stringify({'un_watched': videoId});
var payload = JSON.stringify({ un_watched: videoId });
sendPost(payload);
} else if (videoCurrentWatchStatus == "unwatched") {
var watchStatusIndicator = createWatchStatusIndicator(videoId, "watched");
var payload = JSON.stringify({'watched': videoId});
var payload = JSON.stringify({ watched: videoId });
sendPost(payload);
}
@ -71,7 +70,7 @@ function removeProgressBar(videoId) {
function isWatchedButton(button) {
youtube_id = button.getAttribute("data-id");
var payload = JSON.stringify({'watched': youtube_id});
var payload = JSON.stringify({ watched: youtube_id });
button.remove();
sendPost(payload);
setTimeout(function () {
@ -95,17 +94,17 @@ function isWatchedButton(button) {
// }
function unsubscribe(id_unsub) {
var payload = JSON.stringify({'unsubscribe': id_unsub});
var payload = JSON.stringify({ unsubscribe: id_unsub });
sendPost(payload);
var message = document.createElement('span');
var message = document.createElement("span");
message.innerText = "You are unsubscribed.";
document.getElementById(id_unsub).replaceWith(message);
}
function subscribe(id_sub) {
var payload = JSON.stringify({'subscribe': id_sub});
var payload = JSON.stringify({ subscribe: id_sub });
sendPost(payload);
var message = document.createElement('span');
var message = document.createElement("span");
message.innerText = "You are subscribed.";
document.getElementById(id_sub).replaceWith(message);
}
@ -113,7 +112,7 @@ function subscribe(id_sub) {
function changeView(image) {
var sourcePage = image.getAttribute("data-origin");
var newView = image.getAttribute("data-value");
var payload = JSON.stringify({'change_view': sourcePage + ":" + newView});
var payload = JSON.stringify({ change_view: sourcePage + ":" + newView });
sendPost(payload);
setTimeout(function () {
location.reload();
@ -138,8 +137,8 @@ function toggleCheckbox(checkbox) {
// download page buttons
function rescanPending() {
var payload = JSON.stringify({'rescan_pending': true});
animate('rescan-icon', 'rotate-img');
var payload = JSON.stringify({ rescan_pending: true });
animate("rescan-icon", "rotate-img");
sendPost(payload);
setTimeout(function () {
checkMessages();
@ -147,8 +146,8 @@ function rescanPending() {
}
function dlPending() {
var payload = JSON.stringify({'dl_pending': true});
animate('download-icon', 'bounce-img');
var payload = JSON.stringify({ dl_pending: true });
animate("download-icon", "bounce-img");
sendPost(payload);
setTimeout(function () {
checkMessages();
@ -156,15 +155,15 @@ function dlPending() {
}
function toIgnore(button) {
var youtube_id = button.getAttribute('data-id');
var payload = JSON.stringify({'ignore': youtube_id});
var youtube_id = button.getAttribute("data-id");
var payload = JSON.stringify({ ignore: youtube_id });
sendPost(payload);
document.getElementById('dl-' + youtube_id).remove();
document.getElementById("dl-" + youtube_id).remove();
}
function downloadNow(button) {
var youtube_id = button.getAttribute('data-id');
var payload = JSON.stringify({'dlnow': youtube_id});
var youtube_id = button.getAttribute("data-id");
var payload = JSON.stringify({ dlnow: youtube_id });
sendPost(payload);
document.getElementById(youtube_id).remove();
setTimeout(function () {
@ -173,15 +172,15 @@ function downloadNow(button) {
}
function forgetIgnore(button) {
var youtube_id = button.getAttribute('data-id');
var payload = JSON.stringify({'forgetIgnore': youtube_id});
var youtube_id = button.getAttribute("data-id");
var payload = JSON.stringify({ forgetIgnore: youtube_id });
sendPost(payload);
document.getElementById("dl-" + youtube_id).remove();
}
function addSingle(button) {
var youtube_id = button.getAttribute('data-id');
var payload = JSON.stringify({'addSingle': youtube_id});
var youtube_id = button.getAttribute("data-id");
var payload = JSON.stringify({ addSingle: youtube_id });
sendPost(payload);
document.getElementById("dl-" + youtube_id).remove();
setTimeout(function () {
@ -190,8 +189,8 @@ function addSingle(button) {
}
function deleteQueue(button) {
var to_delete = button.getAttribute('data-id');
var payload = JSON.stringify({'deleteQueue': to_delete});
var to_delete = button.getAttribute("data-id");
var payload = JSON.stringify({ deleteQueue: to_delete });
sendPost(payload);
setTimeout(function () {
location.reload();
@ -200,76 +199,76 @@ function deleteQueue(button) {
}
function stopQueue() {
var payload = JSON.stringify({'queue': 'stop'});
var payload = JSON.stringify({ queue: "stop" });
sendPost(payload);
document.getElementById('stop-icon').remove();
document.getElementById("stop-icon").remove();
}
function killQueue() {
var payload = JSON.stringify({'queue': 'kill'});
var payload = JSON.stringify({ queue: "kill" });
sendPost(payload);
document.getElementById('kill-icon').remove();
document.getElementById("kill-icon").remove();
}
// settings page buttons
function manualImport() {
var payload = JSON.stringify({'manual-import': true});
var payload = JSON.stringify({ "manual-import": true });
sendPost(payload);
// clear button
var message = document.createElement('p');
message.innerText = 'processing import';
var toReplace = document.getElementById('manual-import');
toReplace.innerHTML = '';
var message = document.createElement("p");
message.innerText = "processing import";
var toReplace = document.getElementById("manual-import");
toReplace.innerHTML = "";
toReplace.appendChild(message);
}
function reEmbed() {
var payload = JSON.stringify({'re-embed': true});
var payload = JSON.stringify({ "re-embed": true });
sendPost(payload);
// clear button
var message = document.createElement('p');
message.innerText = 'processing thumbnails';
var toReplace = document.getElementById('re-embed');
toReplace.innerHTML = '';
var message = document.createElement("p");
message.innerText = "processing thumbnails";
var toReplace = document.getElementById("re-embed");
toReplace.innerHTML = "";
toReplace.appendChild(message);
}
function dbBackup() {
var payload = JSON.stringify({'db-backup': true});
var payload = JSON.stringify({ "db-backup": true });
sendPost(payload);
// clear button
var message = document.createElement('p');
message.innerText = 'backing up archive';
var toReplace = document.getElementById('db-backup');
toReplace.innerHTML = '';
var message = document.createElement("p");
message.innerText = "backing up archive";
var toReplace = document.getElementById("db-backup");
toReplace.innerHTML = "";
toReplace.appendChild(message);
}
function dbRestore(button) {
var fileName = button.getAttribute("data-id");
var payload = JSON.stringify({'db-restore': fileName});
var payload = JSON.stringify({ "db-restore": fileName });
sendPost(payload);
// clear backup row
var message = document.createElement('p');
message.innerText = 'restoring from backup';
var message = document.createElement("p");
message.innerText = "restoring from backup";
var toReplace = document.getElementById(fileName);
toReplace.innerHTML = '';
toReplace.innerHTML = "";
toReplace.appendChild(message);
}
function fsRescan() {
var payload = JSON.stringify({'fs-rescan': true});
var payload = JSON.stringify({ "fs-rescan": true });
sendPost(payload);
// clear button
var message = document.createElement('p');
message.innerText = 'File system scan in progress';
var toReplace = document.getElementById('fs-rescan');
toReplace.innerHTML = '';
var message = document.createElement("p");
message.innerText = "File system scan in progress";
var toReplace = document.getElementById("fs-rescan");
toReplace.innerHTML = "";
toReplace.appendChild(message);
}
function resetToken() {
var payload = JSON.stringify({'reset-token': true});
var payload = JSON.stringify({ "reset-token": true });
sendPost(payload);
var message = document.createElement("p");
message.innerText = "Token revoked";
@ -279,7 +278,7 @@ function resetToken() {
// delete from file system
function deleteConfirm() {
to_show = document.getElementById("delete-button");
document.getElementById("delete-item").style.display = 'none';
document.getElementById("delete-item").style.display = "none";
to_show.style.display = "block";
}
@ -311,8 +310,8 @@ function deletePlaylist(button) {
var payload = JSON.stringify({
"delete-playlist": {
"playlist-id": playlist_id,
"playlist-action": playlist_action
}
"playlist-action": playlist_action,
},
});
sendPost(payload);
setTimeout(function () {
@ -322,22 +321,22 @@ function deletePlaylist(button) {
}
function cancelDelete() {
document.getElementById("delete-button").style.display = 'none';
document.getElementById("delete-item").style.display = 'block';
document.getElementById("delete-button").style.display = "none";
document.getElementById("delete-item").style.display = "block";
}
// player
function createPlayer(button) {
var videoId = button.getAttribute('data-id');
var videoId = button.getAttribute("data-id");
var videoData = getVideoData(videoId);
var videoProgress = getVideoProgress(videoId).position;
var videoName = videoData.data.title;
var videoTag = createVideoTag(videoData, videoProgress);
var playlist = '';
var playlist = "";
var videoPlaylists = videoData.data.playlist; // Array of playlists the video is in
if (typeof(videoPlaylists) != 'undefined') {
if (typeof videoPlaylists != "undefined") {
var subbedPlaylists = getSubbedPlaylists(videoPlaylists); // Array of playlist the video is in that are subscribed
if (subbedPlaylists.length != 0) {
var playlistData = getPlaylistData(subbedPlaylists[0]); // Playlist data for first subscribed playlist
@ -356,7 +355,7 @@ function createPlayer(button) {
// document.getElementById(videoId).outerHTML = ''; // Remove watch indicator from video info
// If cast integration is enabled create cast button
var castButton = '';
var castButton = "";
if (videoData.config.application.enable_cast) {
var castButton = `<google-cast-launcher id="castbutton"></google-cast-launcher>`;
}
@ -368,13 +367,15 @@ function createPlayer(button) {
var watchStatusIndicator = createWatchStatusIndicator(videoId, "unwatched");
}
var playerStats = `<div class="thumb-icon player-stats"><img src="/static/img/icon-eye.svg" alt="views icon"><span>${videoViews}</span>`;
if (videoData.data.stats.like_count) {
var likes = formatNumbers(videoData.data.stats.like_count);
playerStats += `<span>|</span><img src="/static/img/icon-thumb.svg" alt="thumbs-up"><span>${likes}</span>`;
}
if (videoData.data.stats.dislike_count && videoData.config.downloads.integrate_ryd) {
if (
videoData.data.stats.dislike_count &&
videoData.config.downloads.integrate_ryd
) {
var dislikes = formatNumbers(videoData.data.stats.dislike_count);
playerStats += `<span>|</span><img class="dislike" src="/static/img/icon-thumb.svg" alt="thumbs-down"><span>${dislikes}</span>`;
}
@ -412,9 +413,12 @@ function createVideoTag(videoData, videoProgress) {
var videoId = videoData.data.youtube_id;
var videoUrl = videoData.data.media_url;
var videoThumbUrl = videoData.data.vid_thumb_url;
var subtitles = '';
var subtitles = "";
var videoSubtitles = videoData.data.subtitles; // Array of subtitles
if (typeof(videoSubtitles) != 'undefined' && videoData.config.downloads.subtitle) {
if (
typeof videoSubtitles != "undefined" &&
videoData.config.downloads.subtitle
) {
for (var i = 0; i < videoSubtitles.length; i++) {
let label = videoSubtitles[i].name;
if (videoSubtitles[i].source == "auto") {
@ -476,7 +480,10 @@ function getVideoPlayerWatchStatus() {
var watchButtons = document.getElementsByClassName("watch-button");
for (let i = 0; i < watchButtons.length; i++) {
if (watchButtons[i].getAttribute("data-id") == videoId && watchButtons[i].getAttribute("data-status") == "watched") {
if (
watchButtons[i].getAttribute("data-id") == videoId &&
watchButtons[i].getAttribute("data-status") == "watched"
) {
watched = true;
}
}
@ -488,9 +495,11 @@ function onVideoProgress() {
var videoId = getVideoPlayerVideoId();
var currentTime = getVideoPlayerCurrentTime();
var duration = getVideoPlayerDuration();
if ((currentTime % 10).toFixed(1) <= 0.2) { // Check progress every 10 seconds or else progress is checked a few times a second
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
if (!getVideoPlayerWatchStatus()) {
// Check if video is already marked as watched
if (watchedThreshold(currentTime, duration)) {
updateVideoWatchStatus(videoId, "unwatched");
}
@ -501,19 +510,24 @@ function onVideoProgress() {
// Runs on video end, marks video as watched
function onVideoEnded() {
var videoId = getVideoPlayerVideoId();
if (!getVideoPlayerWatchStatus()) { // Check if video is already marked as watched
if (!getVideoPlayerWatchStatus()) {
// Check if video is already marked as watched
updateVideoWatchStatus(videoId, "unwatched");
}
}
function watchedThreshold(currentTime, duration) {
var watched = false;
if (duration <= 1800){ // If video is less than 30 min
if ((currentTime / duration) >= 0.90) { // Mark as watched at 90%
if (duration <= 1800) {
// If video is less than 30 min
if (currentTime / duration >= 0.9) {
// Mark as watched at 90%
var watched = true;
}
} else { // If video is more than 30 min
if (currentTime >= (duration - 120)) { // Mark as watched if there is two minutes left
} else {
// If video is more than 30 min
if (currentTime >= duration - 120) {
// Mark as watched if there is two minutes left
var watched = true;
}
}
@ -531,11 +545,14 @@ function onVideoPause() {
function formatNumbers(number) {
var numberUnformatted = parseFloat(number);
if (numberUnformatted > 999999999) {
var numberFormatted = (numberUnformatted / 1000000000).toFixed(1).toString() + "B";
var numberFormatted =
(numberUnformatted / 1000000000).toFixed(1).toString() + "B";
} else if (numberUnformatted > 999999) {
var numberFormatted = (numberUnformatted / 1000000).toFixed(1).toString() + "M";
var numberFormatted =
(numberUnformatted / 1000000).toFixed(1).toString() + "M";
} else if (numberUnformatted > 999) {
var numberFormatted = (numberUnformatted / 1000).toFixed(1).toString() + "K";
var numberFormatted =
(numberUnformatted / 1000).toFixed(1).toString() + "K";
} else {
var numberFormatted = numberUnformatted;
}
@ -585,9 +602,9 @@ function getSubbedPlaylists(videoPlaylists) {
function postVideoProgress(videoId, videoProgress) {
var apiEndpoint = "/api/video/" + videoId + "/progress/";
var duartion = getVideoPlayerDuration();
if (!isNaN(videoProgress) && duartion != 'undefined') {
if (!isNaN(videoProgress) && duartion != "undefined") {
var data = {
"position": videoProgress
position: videoProgress,
};
if (videoProgress == 0) {
apiRequest(apiEndpoint, "DELETE");
@ -622,7 +639,7 @@ function removePlayer() {
var videoId = getVideoPlayerVideoId();
postVideoProgress(videoId, currentTime);
setProgressBar(videoId, currentTime, duration);
var playerElement = document.getElementById('player');
var playerElement = document.getElementById("player");
if (playerElement.hasChildNodes()) {
var youtubeId = playerElement.childNodes[1].getAttribute("data-id");
var playedStatus = document.createDocumentFragment();
@ -630,9 +647,9 @@ function removePlayer() {
if (playedBox) {
playedStatus.appendChild(playedBox);
}
playerElement.innerHTML = '';
playerElement.innerHTML = "";
// append played status
var videoInfo = document.getElementById('video-info-' + youtubeId);
var videoInfo = document.getElementById("video-info-" + youtubeId);
videoInfo.insertBefore(playedStatus, videoInfo.firstChild);
}
}
@ -652,14 +669,12 @@ function setProgressBar(videoId, currentTime, duration) {
}
// progressBar = document.getElementById("progress-" + videoId);
}
// multi search form
function searchMulti(query) {
if (query.length > 1) {
var payload = JSON.stringify({'multi_search': query});
var payload = JSON.stringify({ multi_search: query });
var http = new XMLHttpRequest();
http.onreadystatechange = function () {
if (http.readyState === 4) {
@ -712,7 +727,6 @@ function populateMultiSearchResults(allResults) {
}
}
function createVideo(video, viewStyle) {
// create video item div from template
const videoId = video.youtube_id;
@ -725,7 +739,7 @@ function createVideo(video, viewStyle) {
var watchStatusIndicator = createWatchStatusIndicator(videoId, "watched");
} else {
var watchStatusIndicator = createWatchStatusIndicator(videoId, "unwatched");
};
}
const channelId = video.channel.channel_id;
const channelName = video.channel.channel_name;
// build markup
@ -757,7 +771,6 @@ function createVideo(video, viewStyle) {
return videoDiv;
}
function createChannel(channel, viewStyle) {
// create channel item div from template
const channelId = channel.channel_id;
@ -833,7 +846,6 @@ function createPlaylist(playlist, viewStyle) {
return playlistDiv;
}
// generic
function sendPost(payload) {
var http = new XMLHttpRequest();
@ -843,7 +855,6 @@ function sendPost(payload) {
http.send(payload);
}
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");
@ -857,30 +868,29 @@ function getCookie(c_name) {
return "";
}
// animations
function textReveal() {
var textBox = document.getElementById('text-reveal');
var button = document.getElementById('text-reveal-button');
var textBox = document.getElementById("text-reveal");
var button = document.getElementById("text-reveal-button");
var textBoxHeight = textBox.style.height;
if (textBoxHeight === 'unset') {
textBox.style.height = '0px';
button.innerText = 'Show';
if (textBoxHeight === "unset") {
textBox.style.height = "0px";
button.innerText = "Show";
} else {
textBox.style.height = 'unset';
button.innerText = 'Hide';
textBox.style.height = "unset";
button.innerText = "Hide";
}
}
function showForm() {
var formElement = document.getElementById('hidden-form');
var formElement = document.getElementById("hidden-form");
var displayStyle = formElement.style.display;
if (displayStyle === "") {
formElement.style.display = 'block';
formElement.style.display = "block";
} else {
formElement.style.display = "";
}
animate('animate-icon', 'pulse-img');
animate("animate-icon", "pulse-img");
}
function showOverwrite() {
@ -888,7 +898,7 @@ function showOverwrite() {
if (overwriteDiv.classList.contains("hidden-overwrite")) {
overwriteDiv.classList.remove("hidden-overwrite");
} else {
overwriteDiv.classList.add("hidden-overwrite")
overwriteDiv.classList.add("hidden-overwrite");
}
}

View File

@ -28,11 +28,6 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: AppProps) {
strategy="lazyOnload"
src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"
/> */}
<Script
onError={(e) => console.log(`Error loading script.js: ${e}`)}
strategy="lazyOnload"
src="/js/script.js"
/>
{/** TODO: Detect casting before loading this? */}
{/* <ClientOnlyScript strategy="lazyOnload" src="/js/cast-videos.js" /> */}