added tracking
This commit is contained in:
@@ -113,10 +113,16 @@ function renderContinueWatching(id, list) {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'card';
|
||||
|
||||
el.onclick = () => window.location.href =
|
||||
item.source === 'anilist'
|
||||
? `/anime/${item.entry_id}`
|
||||
: `/anime/${item.source}/${item.entry_id}`;
|
||||
el.onclick = () => {
|
||||
const ep = item.progress || 1;
|
||||
|
||||
if (item.source === 'anilist') {
|
||||
window.location.href = `http://localhost:54322/watch/${item.entry_id}/${ep}`;
|
||||
} else {
|
||||
window.location.href = `http://localhost:54322/watch/${item.entry_id}/${ep}?${item.source}`;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const progressText = item.total_episodes
|
||||
? `${item.progress || 0}/${item.total_episodes}`
|
||||
|
||||
@@ -350,6 +350,20 @@ function playVideo(url, subtitles = []) {
|
||||
settings: ['captions', 'quality', 'speed']
|
||||
});
|
||||
|
||||
let alreadyTriggered = false;
|
||||
|
||||
video.addEventListener('timeupdate', () => {
|
||||
if (!video.duration) return;
|
||||
|
||||
const percent = (video.currentTime / video.duration) * 100;
|
||||
|
||||
if (percent >= 80 && !alreadyTriggered) {
|
||||
alreadyTriggered = true;
|
||||
sendProgress();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
video.play().catch(() => console.log("Autoplay blocked"));
|
||||
}
|
||||
|
||||
@@ -378,6 +392,40 @@ if (currentEpisode <= 1) {
|
||||
document.getElementById('prev-btn').disabled = true;
|
||||
}
|
||||
|
||||
|
||||
async function sendProgress() {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) return;
|
||||
|
||||
const source = extName
|
||||
? extName
|
||||
: "anilist";
|
||||
|
||||
const body = {
|
||||
entry_id: animeId,
|
||||
source: source,
|
||||
entry_type: "ANIME",
|
||||
status: 'CURRENT',
|
||||
progress: source === 'anilist'
|
||||
? Math.floor(currentEpisode)
|
||||
: currentEpisode
|
||||
};
|
||||
|
||||
try {
|
||||
await fetch('/api/list/entry', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error updating progress:', err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
loadMetadata();
|
||||
loadExtensions();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user