Remove old code

This commit is contained in:
HighImKevin
2025-09-09 00:29:57 -04:00
parent 55b4d4b00e
commit e3c0ca9441
+1 -177
View File
@@ -1,4 +1,4 @@
// Jellyfin Watchlist Enhancement Script
// Jellyfin Watchlist Script
// Adds watchlist functionality throughout Jellyfin interface
// Requires: cardBuilder.js module to be loaded before this script
@@ -14,182 +14,6 @@
/************ Helpers ************/
function formatPremiereDate(dateStr) {
if (!dateStr) return "";
return new Date(dateStr).toLocaleDateString(undefined, { weekday: "long", month: "long", day: "numeric" });
}
function setCardData(items, options) {
// Stub function for compatibility
}
function buildCard(index, item, apiClient, options) {
// Check if cardBuilder is available
if (typeof window.cardBuilder !== 'undefined' && window.cardBuilder.buildCard) {
// Use cardBuilder to create a proper Jellyfin card
const cardElement = window.cardBuilder.buildCard(item);
cardElement.setAttribute('data-index', index);
cardElement.classList.add('discover-card');
// Convert DOM element to HTML string
return cardElement.outerHTML;
} else {
// Fallback to simple card if cardBuilder is not available
WARN("cardBuilder not available, using fallback card creation");
return buildFallbackCard(index, item, apiClient, options);
}
}
function buildFallbackCard(index, item, apiClient, options) {
var serverUrl = apiClient.serverAddress();
var imgUrl = serverUrl + "/Items/" + item.Id + "/Images/Primary?maxWidth=200&tag=" + item.PrimaryImageTag;
var itemUrl = getItemDetailUrl(item);
var html = '';
html += '<div class="card overflowPortraitCard card-hoverable card-withuserdata discover-card" data-index="' + index + '">';
html += ' <div class="cardBox cardBox-bottompadded">';
html += ' <div class="cardScalable discoverCard-' + item.SourceType + '">';
html += ' <div class="cardPadder cardPadder-overflowPortrait lazy-hidden-children"></div>';
html += ' <canvas aria-hidden="true" width="20" height="20" class="blurhash-canvas lazy-hidden"></canvas>';
html += ' <a href="' + itemUrl + '" class="cardImageContainer coveredImage cardContent itemAction lazy blurhashed lazy-image-fadein-fast" aria-label="" style="background-image: url(' + imgUrl + ');"></a>';
html += ' <div class="cardOverlayContainer itemAction" data-action="link">';
html += ' <div class="cardOverlayButton-br flex">';
html += ' <button is="discover-requestbutton" type="button" data-action="none" class="discover-requestbutton cardOverlayButton cardOverlayButton-hover itemAction paper-icon-button-light emby-button" data-id="' + item.id + '" data-media-type="' + item.SourceType + '">';
html += ' <span class="material-icons cardOverlayButtonIcon cardOverlayButtonIcon-hover add" aria-hidden="true"></span>';
html += ' </button>';
html += ' </div>';
html += ' </div>';
html += ' </div>';
html += ' <div class="cardText cardTextCentered cardText-first">';
html += ' <bdi>';
html += ' <a target="_blank" href="' + item.id + '/' + item.SourceType + '/' + item.id + '" class="itemAction textActionButton" title="' + item.Name + '" data-action="link">' + item.Name + '</a>';
html += ' </bdi>';
html += ' </div>';
html += ' <div class="cardText cardTextCentered cardText-secondary">';
html += ' <bdi>';
var date = new Date(item.PremiereDate);
html += ' <a target="_blank" href="' + item.id + '/' + item.SourceType + '/' + item.id + '" class="itemAction textActionButton" title="' + date.getFullYear() + '" data-action="link">' + date.getFullYear() + '</a>';
html += ' </bdi>';
html += ' </div>';
html += ' </div>';
html += '</div>';
return html;
}
async function toggleFavorite(itemId, btn) {
const apiClient = window.ApiClient;
const userId = apiClient.getCurrentUserId();
const serverUrl = apiClient.serverAddress();
const token = apiClient.accessToken();
const isFav = btn.textContent === "♡";
try {
await fetch(`${serverUrl}/Users/${userId}/FavoriteItems/${itemId}?IsFavorite=${isFav}`, {
method: "POST",
headers: { "Authorization": `MediaBrowser Token=\"${token}\"` }
});
btn.textContent = isFav ? "♥" : "♡";
} catch (err) {
ERR("Favorite toggle failed", err);
}
}
function buildCardsHtmlInternal(items, options) {
setCardData(items, options);
let html = "";
let itemsInRow = 0;
let currentIndexValue;
let hasOpenRow = false;
let hasOpenSection = false;
const sectionTitleTagName = options.sectionTitleTagName || "div";
const apiClient = window.ApiClient;
let lastServerId;
for (const [i, item] of items.entries()) {
const serverId = item.ServerId || options.serverId;
if (serverId !== lastServerId) lastServerId = serverId;
let newIndexValue = "";
if (options.indexBy === "PremiereDate") {
newIndexValue = formatPremiereDate(item.PremiereDate);
} else if (options.indexBy === "ProductionYear") {
newIndexValue = item.ProductionYear;
} else if (options.indexBy === "CommunityRating") {
const rounded = item.CommunityRating % 1 >= 0.5 ? 0.5 : 0;
newIndexValue = item.CommunityRating ? (Math.floor(item.CommunityRating) + rounded) + "+" : "";
}
// Handle section changes
if (newIndexValue !== currentIndexValue) {
// Close previous row and section if open
if (hasOpenRow) {
html += "</div>";
hasOpenRow = false;
itemsInRow = 0;
}
if (hasOpenSection) {
html += "</div>";
hasOpenSection = false;
}
// Start new section (always horizontal)
html += "<div class=\"horizontalSection\">";
html += `<${sectionTitleTagName} class="sectionTitle">${newIndexValue}</${sectionTitleTagName}>`;
currentIndexValue = newIndexValue;
hasOpenSection = true;
}
// Handle row creation for multi-row layouts
if (options.rows && itemsInRow === 0) {
html += "<div class=\"cardColumn\">";
hasOpenRow = true;
}
// Build the card with direct linking
html += buildCard(i, item, apiClient, options);
itemsInRow++;
// Close row if we've reached the row limit
if (options.rows && itemsInRow >= options.rows) {
html += "</div>";
hasOpenRow = false;
itemsInRow = 0;
}
}
// Close any remaining open elements
if (hasOpenRow) html += "</div>";
if (hasOpenSection) html += "</div>";
return html;
}
function buildCardWithLink(index, item, apiClient, options) {
// Generate the URL for the item detail page
const itemUrl = getItemDetailUrl(item);
// Build the original card content
const cardContent = buildCard(index, item, apiClient, options);
// Wrap the card in a clickable link
return `<a href="${itemUrl}" class="card-link" style="text-decoration: none; color: inherit;">${cardContent}</a>`;
}
function getItemDetailUrl(item) {
// Construct the URL to the item's detail page
// Adjust this based on your Jellyfin setup and routing
const baseUrl = window.location.origin;
const serverId = item.ServerId;
// Standard Jellyfin item detail URL format
return `${baseUrl}/web/#/details?id=${item.Id}&serverId=${serverId}`;
}
async function fetchLikedItems(type) {
const apiClient = window.ApiClient;
const userId = apiClient.getCurrentUserId();