From b7c7853a98e1046baa3e0dc378f44073ffc35d09 Mon Sep 17 00:00:00 2001 From: Mars Niermann Date: Wed, 8 Mar 2023 09:33:01 +0000 Subject: [PATCH] Add info button --- src/jellyfin-quick-delete.user.js | 114 ++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 28 deletions(-) diff --git a/src/jellyfin-quick-delete.user.js b/src/jellyfin-quick-delete.user.js index 022493c..603fc30 100644 --- a/src/jellyfin-quick-delete.user.js +++ b/src/jellyfin-quick-delete.user.js @@ -29,6 +29,89 @@ .then((response) => response.json()) .then((data) => (apiKey = data.AccessToken)); // Store AccessToken + + + + + // Button to refresh the metadata of an item + function refreshButton() { + let el = document.createElement("button"); + el.className = "listItemButton paper-icon-button-light emby-button"; + let el2 = document.createElement("span"); + + // Set icon and color + el2.className = "material-icons refresh"; + el2.style.color = "#83a598"; + el.style.position = "relative"; + el.style.overflow = "hidden"; + + el.appendChild(el2); + + // Bind refresh function + el.onclick = function () { + let url = `${window.origin}/Items/${this.parentElement.dataset.id}/Refresh?Recursive=true&ImageRefreshMode=FullRefresh&MetadataRefreshMode=FullRefresh&ReplaceAllImages=true&ReplaceAllMetadata=true`; + console.log(`Refreshing ${url}`); + + // Send refresh request + fetch(url, { + method: "POST", + headers: { + "X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Chrome", DeviceId="test", Version="10.8.9", Token="${apiKey}"`, + }, + }); + // Replace empty image with rotating spinner + this.parentElement.firstChild.firstChild.classList.remove("audiotrack") + this.parentElement.firstChild.firstChild.classList.add("sync", "rotating") + var style = document.createElement('style'); + style.innerHTML = ` + .rotating { + animation: rotate 1s infinite; + } + + @keyframes rotate { + from { transform: rotate(0deg); } + to { transform: rotate(360deg); } + }`; + // Add style element to document head + document.head.appendChild(style); + }; + //Return complete element + return el; + } + + // Button to display bitrate of item + function infoButton() { + let el = document.createElement("button"); + el.className = "listItemButton paper-icon-button-light emby-button"; + let el2 = document.createElement("span"); + + // Set icon and color + el2.className = "material-icons info"; + el2.style.color = "#fbf1c7"; + el.appendChild(el2); + + // Bind get function + el.onclick = function () { + let bitrate; + let url = `${window.origin}/Users/${userid}/Items/${this.parentElement.dataset.id}`; + console.log(`Fetching ${url}`); + + // Send deletion request + fetch(url, { + method: "GET", + headers: { + "X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Chrome", DeviceId="test", Version="10.8.9", Token="${apiKey}"`, + }, + }).then((response) => response.json()) + .then((data) => (bitrate = data.MediaSources[0].MediaStreams[0].BitRate.toString().substring(0, 3)));; + console.log(bitrate) + // Remove parent to provide feedback and prevent double deletion + alert(`Bitrate: ${bitrate}`) + }; + //Return complete element + return el; + } + // Helper function to create delete button function delButton() { let el = document.createElement("button"); @@ -57,33 +140,7 @@ this.parentElement.remove(); }; //Return complete element - return el2; - } - - // Button to refresh the metadata of an item - function refreshButton() { - let el = document.createElement("button"); - el.className = "listItemButton paper-icon-button-light emby-button"; - let el2 = document.createElement("span"); - - // Set icon and color - el2.className = "material-icons refresh"; - el2.style.color = "#83a598"; - el.appendChild(el2); - - el.onclick = function () { - let url = `${window.origin}/Items/${this.parentElement.dataset.id}/Refresh?Recursive=true&ImageRefreshMode=FullRefresh&MetadataRefreshMode=FullRefresh&ReplaceAllImages=true&ReplaceAllMetadata=true`; - console.log(`Deleting ${url}`); - - // Send deletion request - fetch(url, { - method: "POST", - headers: { - "X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Chrome", DeviceId="test", Version="10.8.9", Token="${apiKey}"`, - }, - }); - }; - return el2; + return el; } // Insert buttons @@ -95,6 +152,7 @@ // Append buttons to list curr.appendChild(refreshButton()); + curr.appendChild(infoButton()); curr.appendChild(delButton()); } } @@ -107,4 +165,4 @@ } } document.addEventListener("keydown", onKeydown, true); -})(); +})(); \ No newline at end of file