mirror of
https://github.com/ranaldsgift/KefinTweaks.git
synced 2026-11-05 15:52:47 +01:00
Update Statistics page with new graphs rendered via ChartJS
This commit is contained in:
+15
-1
@@ -184,6 +184,12 @@
|
||||
css: [
|
||||
'thirdparty/pickr/pickr-nano.min.css'
|
||||
]
|
||||
},
|
||||
chartjs: {
|
||||
js: [
|
||||
'thirdparty/chartjs/chart.js'
|
||||
],
|
||||
css: []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -500,11 +506,19 @@
|
||||
dependencies: [],
|
||||
description: 'Toast notification system using Jellyfin\'s existing toast functionality'
|
||||
},
|
||||
{
|
||||
name: 'statistics',
|
||||
script: 'statistics.js',
|
||||
css: null,
|
||||
dependencies: [],
|
||||
description: 'Watchlist statistics charts and activity analytics'
|
||||
},
|
||||
{
|
||||
name: 'watchlist',
|
||||
script: 'watchlist.js',
|
||||
css: 'watchlist.css',
|
||||
dependencies: ['cardBuilder', 'localStorageCache', 'modal', 'utils'],
|
||||
dependencies: ['cardBuilder', 'localStorageCache', 'modal', 'utils', 'statistics'],
|
||||
thirdParty: ['chartjs'],
|
||||
description: 'Adds watchlist functionality throughout Jellyfin interface'
|
||||
},
|
||||
{
|
||||
|
||||
@@ -42,6 +42,12 @@
|
||||
css: [
|
||||
'thirdparty/pickr/pickr-nano.min.css'
|
||||
]
|
||||
},
|
||||
chartjs: {
|
||||
js: [
|
||||
'thirdparty/chartjs/chart.js'
|
||||
],
|
||||
css: []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -364,11 +370,19 @@
|
||||
dependencies: [],
|
||||
description: 'Toast notification system using Jellyfin\'s existing toast functionality'
|
||||
},
|
||||
{
|
||||
name: 'statistics',
|
||||
script: 'statistics.js',
|
||||
css: null,
|
||||
dependencies: [],
|
||||
description: 'Watchlist statistics charts and activity analytics'
|
||||
},
|
||||
{
|
||||
name: 'watchlist',
|
||||
script: 'watchlist.js',
|
||||
css: 'watchlist.css',
|
||||
dependencies: ['cardBuilder', 'localStorageCache', 'modal', 'utils'],
|
||||
dependencies: ['cardBuilder', 'localStorageCache', 'modal', 'utils', 'statistics'],
|
||||
thirdParty: ['chartjs'],
|
||||
description: 'Adds watchlist functionality throughout Jellyfin interface'
|
||||
},
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+9
@@ -0,0 +1,9 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2024 Chart.js Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Vendored
+14
File diff suppressed because one or more lines are too long
+365
-6
@@ -634,7 +634,7 @@
|
||||
|
||||
.top-shows-header .material-icons {
|
||||
font-size: 20px;
|
||||
color: #ffd700;
|
||||
color: rgba(100, 181, 246, 0.95);
|
||||
}
|
||||
|
||||
.top-shows-list {
|
||||
@@ -659,16 +659,36 @@
|
||||
border-color: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
.top-show-item:first-child {
|
||||
background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(255, 215, 0, 0.05));
|
||||
border-color: rgba(255, 215, 0, 0.3);
|
||||
.top-show-item.rank-1 {
|
||||
background: linear-gradient(135deg, rgba(255, 215, 0, 0.18), rgba(255, 215, 0, 0.05));
|
||||
border-color: rgba(255, 215, 0, 0.4);
|
||||
}
|
||||
|
||||
.top-show-item:first-child .show-rank {
|
||||
.top-show-item.rank-1 .show-rank {
|
||||
color: #ffd700;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.top-show-item.rank-2 {
|
||||
background: linear-gradient(135deg, rgba(192, 192, 192, 0.18), rgba(192, 192, 192, 0.05));
|
||||
border-color: rgba(192, 192, 192, 0.4);
|
||||
}
|
||||
|
||||
.top-show-item.rank-2 .show-rank {
|
||||
color: #c0c0c0;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.top-show-item.rank-3 {
|
||||
background: linear-gradient(135deg, rgba(205, 127, 50, 0.2), rgba(205, 127, 50, 0.06));
|
||||
border-color: rgba(205, 127, 50, 0.45);
|
||||
}
|
||||
|
||||
.top-show-item.rank-3 .show-rank {
|
||||
color: #cd7f32;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.top-show-name {
|
||||
flex: 1;
|
||||
font-size: 14px;
|
||||
@@ -1317,6 +1337,344 @@ div[data-tab="statistics"][data-ready="false"] > .loading-container {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Extended activity charts / lists */
|
||||
.stats-activity-section {
|
||||
margin-top: 24px;
|
||||
padding-bottom: 32px;
|
||||
}
|
||||
|
||||
.stats-charts-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.stats-chart-card {
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 12px;
|
||||
padding: 16px 18px 12px;
|
||||
backdrop-filter: blur(10px);
|
||||
min-height: 260px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.stats-chart-card.stats-chart-wide {
|
||||
grid-column: 1 / -1;
|
||||
min-height: 300px;
|
||||
}
|
||||
|
||||
.stats-chart-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.stats-chart-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.stats-chart-header .stats-chart-subtitle {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.stats-range-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.stats-range-chip {
|
||||
appearance: none;
|
||||
border: 1px solid rgba(255, 255, 255, 0.18);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: rgba(255, 255, 255, 0.75);
|
||||
border-radius: 999px;
|
||||
padding: 4px 10px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.stats-range-chip:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stats-range-chip.is-active {
|
||||
background: rgba(100, 181, 246, 0.25);
|
||||
border-color: rgba(100, 181, 246, 0.65);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.stats-chart-subtitle {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.stats-chart-canvas-wrap {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-height: 200px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.stats-lists-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.stats-list-card {
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 12px;
|
||||
padding: 16px 18px;
|
||||
backdrop-filter: blur(10px);
|
||||
min-height: 180px;
|
||||
}
|
||||
|
||||
.stats-list-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.stats-list-header .material-icons {
|
||||
font-size: 20px;
|
||||
color: rgba(100, 181, 246, 0.95);
|
||||
}
|
||||
|
||||
.stats-list-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.stats-list-item {
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.stats-list-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.stats-list-item-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.stats-list-item-meta {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
margin-top: 2px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.stats-list-item-sub {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.45);
|
||||
margin-top: 4px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.stats-list-empty {
|
||||
font-size: 13px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
font-style: italic;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.stats-expandable-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.stats-expandable-header:hover .stats-list-item-title {
|
||||
color: rgba(100, 181, 246, 0.95);
|
||||
}
|
||||
|
||||
.stats-expand-icon {
|
||||
font-size: 20px !important;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
transition: transform 0.15s ease;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.stats-expandable.is-open .stats-expand-icon {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.stats-expandable-text {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.stats-expandable-body {
|
||||
display: none;
|
||||
margin-top: 10px;
|
||||
padding: 10px 0 4px 28px;
|
||||
}
|
||||
|
||||
.stats-expandable.is-open .stats-expandable-body {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.stats-detail-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.stats-detail-table th,
|
||||
.stats-detail-table td {
|
||||
padding: 6px 8px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.stats-detail-table th {
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
font-weight: 600;
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.stats-detail-table td {
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
}
|
||||
|
||||
.stats-detail-table td:last-child {
|
||||
white-space: nowrap;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
.stats-streak-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.stats-detail-card {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
|
||||
.stats-detail-card-name {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.stats-detail-card-meta {
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.stats-binge-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.stats-binge-item,
|
||||
.stats-favorite-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
padding: 8px 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.stats-favorite-item {
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.stats-media-icon {
|
||||
font-size: 18px !important;
|
||||
color: rgba(100, 181, 246, 0.9);
|
||||
flex-shrink: 0;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.stats-binge-item-body,
|
||||
.stats-favorite-item-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.stats-binge-item-name {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
line-height: 1.3;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.stats-binge-item-meta {
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.stats-charts-grid,
|
||||
.stats-lists-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.stats-chart-card.stats-chart-wide {
|
||||
grid-column: auto;
|
||||
}
|
||||
|
||||
.stats-expandable-body {
|
||||
padding-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
div[data-tab="watchlist"] .loading-message {
|
||||
padding-top: 85px;
|
||||
}
|
||||
@@ -1404,7 +1762,8 @@ div[data-tab="watchlist"] .loading-message {
|
||||
}
|
||||
|
||||
.show-all-btn .material-icons {
|
||||
font-size: 16px;
|
||||
font-size: 18px;
|
||||
color: rgba(100, 181, 246, 0.95);
|
||||
}
|
||||
|
||||
/* Top Shows Header */
|
||||
|
||||
+133
-71
@@ -1,6 +1,7 @@
|
||||
// Jellyfin Watchlist Script
|
||||
// Adds watchlist functionality throughout Jellyfin interface
|
||||
// Requires: cardBuilder.js, localStorageCache.js, modal.js, utils.js modules to be loaded before this script
|
||||
// Requires: cardBuilder.js, localStorageCache.js, modal.js, utils.js, statistics.js modules to be loaded before this script
|
||||
// Chart.js is loaded as a thirdParty dependency of watchlist
|
||||
// Requirement #2: Custom Tabs plugin
|
||||
/*
|
||||
In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
@@ -32,40 +33,60 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
|
||||
// Data optimization functions for localStorage storage
|
||||
function optimizeProgressDataForStorage(progressDataArray) {
|
||||
return progressDataArray.map(progress => ({
|
||||
// Series info (minimal)
|
||||
series: {
|
||||
Id: progress.series.Id,
|
||||
Name: progress.series.Name,
|
||||
ImageTags: progress.series.ImageTags,
|
||||
Status: progress.series.Status,
|
||||
ProductionYear: progress.series.ProductionYear
|
||||
},
|
||||
|
||||
// Progress metrics (pre-calculated statistics only)
|
||||
watchedCount: progress.watchedCount,
|
||||
totalEpisodes: progress.totalEpisodes,
|
||||
remainingCount: progress.remainingCount,
|
||||
percentage: progress.percentage,
|
||||
totalRuntime: progress.totalRuntime,
|
||||
watchedRuntime: progress.watchedRuntime,
|
||||
remainingRuntime: progress.remainingRuntime,
|
||||
|
||||
// Last watched episode (minimal)
|
||||
lastWatchedEpisode: progress.lastWatchedEpisode ? {
|
||||
Id: progress.lastWatchedEpisode.Id,
|
||||
Name: progress.lastWatchedEpisode.Name,
|
||||
IndexNumber: progress.lastWatchedEpisode.IndexNumber,
|
||||
ParentIndexNumber: progress.lastWatchedEpisode.ParentIndexNumber,
|
||||
UserData: progress.lastWatchedEpisode.UserData,
|
||||
ImageTags: progress.lastWatchedEpisode.ImageTags
|
||||
} : null,
|
||||
|
||||
// Binary progress data for instant rendering (compact storage)
|
||||
binaryProgress: progress.binaryProgress || {}
|
||||
|
||||
// Episodes array completely removed - will be fetched on-demand
|
||||
}));
|
||||
return progressDataArray.map(progress => {
|
||||
const episodeSource = progress.episodes || progress.playEvents || [];
|
||||
const playEvents = episodeSource
|
||||
.filter((ep) => {
|
||||
if (ep.UserData?.Played && ep.UserData?.LastPlayedDate) return true;
|
||||
// Restored compact playEvents already have LastPlayedDate at top level
|
||||
return !!(ep.LastPlayedDate && (ep.Id || ep.Name));
|
||||
})
|
||||
.map((ep) => ({
|
||||
Id: ep.Id,
|
||||
Name: ep.Name,
|
||||
LastPlayedDate: ep.UserData?.LastPlayedDate || ep.LastPlayedDate,
|
||||
RunTimeTicks: ep.RunTimeTicks || 0,
|
||||
ParentIndexNumber: ep.ParentIndexNumber != null ? ep.ParentIndexNumber : null,
|
||||
IndexNumber: ep.IndexNumber != null ? ep.IndexNumber : null
|
||||
}));
|
||||
|
||||
const seriesUserData = progress.series?.UserData
|
||||
? {
|
||||
IsFavorite: !!progress.series.UserData.IsFavorite,
|
||||
LastPlayedDate: progress.series.UserData.LastPlayedDate || null,
|
||||
PlayCount: progress.series.UserData.PlayCount || 0,
|
||||
Played: !!progress.series.UserData.Played
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
series: {
|
||||
Id: progress.series.Id,
|
||||
Name: progress.series.Name,
|
||||
ImageTags: progress.series.ImageTags,
|
||||
Status: progress.series.Status,
|
||||
ProductionYear: progress.series.ProductionYear,
|
||||
...(seriesUserData ? { UserData: seriesUserData } : {})
|
||||
},
|
||||
watchedCount: progress.watchedCount,
|
||||
totalEpisodes: progress.totalEpisodes,
|
||||
remainingCount: progress.remainingCount,
|
||||
percentage: progress.percentage,
|
||||
totalRuntime: progress.totalRuntime,
|
||||
watchedRuntime: progress.watchedRuntime,
|
||||
remainingRuntime: progress.remainingRuntime,
|
||||
lastWatchedEpisode: progress.lastWatchedEpisode ? {
|
||||
Id: progress.lastWatchedEpisode.Id,
|
||||
Name: progress.lastWatchedEpisode.Name,
|
||||
IndexNumber: progress.lastWatchedEpisode.IndexNumber,
|
||||
ParentIndexNumber: progress.lastWatchedEpisode.ParentIndexNumber,
|
||||
UserData: progress.lastWatchedEpisode.UserData,
|
||||
ImageTags: progress.lastWatchedEpisode.ImageTags
|
||||
} : null,
|
||||
binaryProgress: progress.binaryProgress || {},
|
||||
playEvents
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function optimizeMovieDataForStorage(movieDataArray) {
|
||||
@@ -176,12 +197,17 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
try {
|
||||
// Clear localStorage cache
|
||||
if (cacheName === 'progress') {
|
||||
localStorageCache.clear(`progress`);
|
||||
localStorageCache.clear(`progress_v2`);
|
||||
localStorageCache.clear(`progress`); // legacy key
|
||||
// Clear in-memory cache
|
||||
progressCache.data = [];
|
||||
progressCache.allDataLoaded = false;
|
||||
progressCache.totalPages = 0;
|
||||
tabStates.progress.isDataFetched = false;
|
||||
tabStates.statistics.isDataFetched = false;
|
||||
if (window.KefinWatchlistStats?.destroy) {
|
||||
window.KefinWatchlistStats.destroy();
|
||||
}
|
||||
} else if (cacheName === 'movies') {
|
||||
localStorageCache.clear(`movies`);
|
||||
// Clear in-memory cache
|
||||
@@ -189,6 +215,10 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
movieCache.allDataLoaded = false;
|
||||
movieCache.totalPages = 0;
|
||||
tabStates.history.isDataFetched = false;
|
||||
tabStates.statistics.isDataFetched = false;
|
||||
if (window.KefinWatchlistStats?.destroy) {
|
||||
window.KefinWatchlistStats.destroy();
|
||||
}
|
||||
} else if (cacheName === 'watchlist') {
|
||||
await invalidateAllWatchlistQueries();
|
||||
resetWatchlistItemsByType();
|
||||
@@ -1630,7 +1660,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
const optimizedData = optimizeProgressDataForStorage(progressCache.data);
|
||||
|
||||
// Update localStorage with the new data
|
||||
const success = localStorageCache.set('progress', optimizedData);
|
||||
const success = localStorageCache.set('progress_v2', optimizedData);
|
||||
if (success) {
|
||||
LOG('Updated progress data in localStorage');
|
||||
} else {
|
||||
@@ -2435,7 +2465,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
|
||||
// Check localStorage cache if in-memory cache is empty
|
||||
if (useCache && !progressCache.allDataLoaded) {
|
||||
const cachedData = localStorageCache.get(`progress`);
|
||||
const cachedData = localStorageCache.get(`progress_v2`);
|
||||
if (cachedData) {
|
||||
LOG('Using localStorage cache for progress data');
|
||||
progressCache.data = cachedData;
|
||||
@@ -2498,7 +2528,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
|
||||
// Store in localStorage for next time (optimized)
|
||||
const optimizedData = optimizeProgressDataForStorage(sortedProgressData);
|
||||
localStorageCache.set(`progress`, optimizedData);
|
||||
localStorageCache.set(`progress_v2`, optimizedData);
|
||||
LOG('Stored optimized progress data in localStorage');
|
||||
|
||||
LOG(`All progress data loaded and sorted: ${sortedProgressData.length} items, ${progressCache.totalPages} pages`);
|
||||
@@ -2511,7 +2541,8 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
// Always clear the fetching flag, even on error
|
||||
tabStates.progress.isFetching = false;
|
||||
LOG('Progress data fetch completed');
|
||||
renderStatisticsContent();
|
||||
// Do not call renderStatisticsContent here — nested re-entry while the
|
||||
// stats panel is still data-ready=false leaves Chart.js with a 0-size canvas.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2546,7 +2577,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
}
|
||||
|
||||
// Get all episodes including missing ones to get accurate TotalRecordCount
|
||||
const episodesUrl = `${serverUrl}/Shows/${series.Id}/Episodes?UserId=${userId}&Fields=UserData&EnableImageTypes=Primary`;
|
||||
const episodesUrl = `${serverUrl}/Shows/${series.Id}/Episodes?UserId=${userId}&Fields=UserData,RunTimeTicks&EnableImageTypes=Primary`;
|
||||
const episodesRes = await fetch(episodesUrl, { headers: { "Authorization": window.apiHelper.getAuthHeader() } });
|
||||
const episodesData = await episodesRes.json();
|
||||
let episodes = episodesData.Items || [];
|
||||
@@ -2797,10 +2828,11 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
|
||||
const showsHtml = topShows.map((show, index) => {
|
||||
const rank = index + 1;
|
||||
const rankClass = rank <= 3 ? ` rank-${rank}` : '';
|
||||
const episodesText = show.episodesWatched === 1 ? 'episode' : 'episodes';
|
||||
|
||||
return `
|
||||
<div class="top-show-item">
|
||||
<div class="top-show-item${rankClass}">
|
||||
<div class="show-rank">${rank}</div>
|
||||
<div class="top-show-name" title="${show.name}">${show.name}</div>
|
||||
<div class="top-show-episodes">${show.episodesWatched} of ${show.totalEpisodes} ${episodesText} (${show.percentage}%)</div>
|
||||
@@ -5029,7 +5061,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
// Update episode in localStorage when progress cache is not fully loaded
|
||||
async function updateEpisodeInLocalStorage(episode) {
|
||||
try {
|
||||
const cachedProgress = localStorageCache.get('progress');
|
||||
const cachedProgress = localStorageCache.get('progress_v2');
|
||||
if (!cachedProgress) {
|
||||
LOG('No progress data in localStorage to update');
|
||||
return;
|
||||
@@ -5086,7 +5118,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
LOG(`Updated episode ${episode.IndexNumber} in season ${season} as watched in localStorage`);
|
||||
|
||||
// Save back to localStorage
|
||||
localStorageCache.set('progress', cachedProgress);
|
||||
localStorageCache.set('progress_v2', cachedProgress);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -5125,7 +5157,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
// Update episode as unwatched in localStorage when progress cache is not fully loaded
|
||||
async function updateEpisodeInLocalStorageUnwatched(episode) {
|
||||
try {
|
||||
const cachedProgress = localStorageCache.get('progress');
|
||||
const cachedProgress = localStorageCache.get('progress_v2');
|
||||
if (!cachedProgress) {
|
||||
LOG('No progress data in localStorage to update');
|
||||
return;
|
||||
@@ -5152,7 +5184,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
LOG(`Updated episode ${episode.IndexNumber} in season ${season} as unwatched in localStorage`);
|
||||
|
||||
// Save back to localStorage
|
||||
localStorageCache.set('progress', cachedProgress);
|
||||
localStorageCache.set('progress_v2', cachedProgress);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -5660,32 +5692,62 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
}
|
||||
}
|
||||
|
||||
let statisticsRenderPromise = null;
|
||||
|
||||
async function renderStatisticsContent() {
|
||||
LOG('Rendering Statistics content');
|
||||
|
||||
const watchlistSection = getWatchlistSection();
|
||||
const statisticsTab = watchlistSection ? watchlistSection.querySelector('div[data-tab="statistics"]') : null;
|
||||
if (!statisticsTab) return;
|
||||
|
||||
try {
|
||||
statisticsTab.setAttribute('data-ready', 'false');
|
||||
|
||||
await Promise.all([
|
||||
fetchAllProgressData(true),
|
||||
fetchWatchedMovies(true)
|
||||
]);
|
||||
|
||||
tabStates.progress.isDataFetched = true;
|
||||
tabStates.history.isDataFetched = true;
|
||||
|
||||
await updateProgressStatistics(progressCache.data);
|
||||
statisticsTab.setAttribute('data-ready', 'true');
|
||||
|
||||
LOG('Statistics content rendered successfully');
|
||||
} catch (err) {
|
||||
ERR('Error rendering statistics content:', err);
|
||||
statisticsTab.setAttribute('data-ready', 'false');
|
||||
// Coalesce concurrent calls (e.g. init + switchTab both firing)
|
||||
if (statisticsRenderPromise) {
|
||||
return statisticsRenderPromise;
|
||||
}
|
||||
|
||||
statisticsRenderPromise = (async () => {
|
||||
LOG('Rendering Statistics content');
|
||||
|
||||
const watchlistSection = getWatchlistSection();
|
||||
const statisticsTab = watchlistSection ? watchlistSection.querySelector('div[data-tab="statistics"]') : null;
|
||||
if (!statisticsTab) return;
|
||||
|
||||
try {
|
||||
statisticsTab.setAttribute('data-ready', 'false');
|
||||
|
||||
await Promise.all([
|
||||
fetchAllProgressData(true),
|
||||
fetchWatchedMovies(true)
|
||||
]);
|
||||
|
||||
tabStates.progress.isDataFetched = true;
|
||||
tabStates.history.isDataFetched = true;
|
||||
|
||||
// Reveal layout before Chart.js measures canvas size (hidden → 0-height blank charts)
|
||||
statisticsTab.setAttribute('data-ready', 'true');
|
||||
await new Promise((resolve) => {
|
||||
requestAnimationFrame(() => requestAnimationFrame(resolve));
|
||||
});
|
||||
|
||||
if (window.KefinWatchlistStats && typeof window.KefinWatchlistStats.render === 'function') {
|
||||
window.KefinWatchlistStats.render(statisticsTab, {
|
||||
progress: progressCache.data,
|
||||
movies: movieCache.data
|
||||
});
|
||||
if (typeof window.KefinWatchlistStats.resize === 'function') {
|
||||
window.KefinWatchlistStats.resize();
|
||||
requestAnimationFrame(() => window.KefinWatchlistStats.resize());
|
||||
}
|
||||
} else {
|
||||
WARN('KefinWatchlistStats unavailable; falling back to summary cards only');
|
||||
await updateProgressStatistics(progressCache.data);
|
||||
}
|
||||
|
||||
LOG('Statistics content rendered successfully');
|
||||
} catch (err) {
|
||||
ERR('Error rendering statistics content:', err);
|
||||
statisticsTab.setAttribute('data-ready', 'false');
|
||||
}
|
||||
})().finally(() => {
|
||||
statisticsRenderPromise = null;
|
||||
});
|
||||
|
||||
return statisticsRenderPromise;
|
||||
}
|
||||
|
||||
function renderPaginationControls(currentPage, totalPages, tabName = 'progress') {
|
||||
@@ -6203,7 +6265,7 @@ In the Custom Tabs plugin, add a new tab with the following HTML content:
|
||||
|
||||
try {
|
||||
LOG(`Fetching episodes from API for series: ${seriesId}`);
|
||||
const episodesUrl = `${serverUrl}/Shows/${seriesId}/Episodes?UserId=${userId}&Fields=UserData&EnableImageTypes=Primary`;
|
||||
const episodesUrl = `${serverUrl}/Shows/${seriesId}/Episodes?UserId=${userId}&Fields=UserData,RunTimeTicks&EnableImageTypes=Primary`;
|
||||
const episodesRes = await fetch(episodesUrl, { headers: { "Authorization": window.apiHelper.getAuthHeader() } });
|
||||
const episodesData = await episodesRes.json();
|
||||
let episodes = episodesData.Items || [];
|
||||
|
||||
Reference in New Issue
Block a user