fix(watch): support PeerTube v8 /w/:slug URLs in transcript and continue watching

This commit is contained in:
Enes Yakıştır
2026-12-01 18:51:24 +03:00
parent d4b7da078a
commit 89c42e2d74
+28 -6
View File
@@ -1767,7 +1767,9 @@ try {
var isTranscriptPanelOpen = false; var isTranscriptPanelOpen = false;
function getActiveWatchVideoSlug() { function getActiveWatchVideoSlug() {
var m = window.location.pathname.match(/\/videos\/watch\/([a-zA-Z0-9_-]+)/); var m =
window.location.pathname.match(/\/videos\/watch\/([a-zA-Z0-9_-]+)/) ||
window.location.pathname.match(/\/w\/([a-zA-Z0-9_-]+)/);
return m ? m[1] : null; return m ? m[1] : null;
} }
@@ -2325,6 +2327,8 @@ try {
modal.querySelector('#yaktube-queue-clear').addEventListener('click', function () { modal.querySelector('#yaktube-queue-clear').addEventListener('click', function () {
savePlayQueue([]); savePlayQueue([]);
renderDrawer(); renderDrawer();
var closeEl = modal.querySelector('#yaktube-queue-close');
if (closeEl) closeEl.focus();
announce('Çalma sırası tamamen temizlendi.'); announce('Çalma sırası tamamen temizlendi.');
}); });
modal.querySelectorAll('.yaktube-queue-play-one').forEach(function (b) { modal.querySelectorAll('.yaktube-queue-play-one').forEach(function (b) {
@@ -8970,13 +8974,25 @@ try {
videoState.hasPlayed = false; videoState.hasPlayed = false;
videoState.explicitlyPausedByClick = true; videoState.explicitlyPausedByClick = true;
try { try {
recordContinueWatchingProgress(video, true); recordContinueWatchingProgress(video, true, true);
} catch (e) {} } catch (e) {}
try { try {
showPostVideoUpNextOverlay(); showPostVideoUpNextOverlay();
} catch (e) {} } catch (e) {}
}); });
video.addEventListener('pause', function () {
try {
recordContinueWatchingProgress(video, false, true);
} catch (e) {}
});
video.addEventListener('seeked', function () {
try {
recordContinueWatchingProgress(video, false, true);
} catch (e) {}
});
video.addEventListener('timeupdate', function () { video.addEventListener('timeupdate', function () {
updateMediaSessionPosition(video); updateMediaSessionPosition(video);
if ( if (
@@ -8988,7 +9004,7 @@ try {
video.currentTime = abLoopState.a; video.currentTime = abLoopState.a;
} }
try { try {
recordContinueWatchingProgress(video, false); recordContinueWatchingProgress(video, false, false);
} catch (e) {} } catch (e) {}
try { try {
checkSmartPrefetchOnTimeUpdate(video); checkSmartPrefetchOnTimeUpdate(video);
@@ -9159,13 +9175,13 @@ try {
} catch (e) {} } catch (e) {}
} }
function recordContinueWatchingProgress(video, isEnded) { function recordContinueWatchingProgress(video, isEnded, forceSave) {
if (!video || !isWatchUrl() || isEmbedUrl()) return; if (!video || !isWatchUrl() || isEmbedUrl()) return;
var slug = getActiveWatchVideoSlug(); var slug = getActiveWatchVideoSlug();
if (!slug) return; if (!slug) return;
var now = Date.now(); var now = Date.now();
if (!isEnded && now - lastContinueSaveTs < 4000) return; if (!isEnded && !forceSave && now - lastContinueSaveTs < 4000) return;
var dur = Number(video.duration || 0); var dur = Number(video.duration || 0);
var cur = Number(video.currentTime || 0); var cur = Number(video.currentTime || 0);
@@ -9199,7 +9215,7 @@ try {
var entry = { var entry = {
slug: slug, slug: slug,
url: '/videos/watch/' + slug, url: '/w/' + slug,
startTime: Math.floor(cur), startTime: Math.floor(cur),
duration: Math.floor(dur), duration: Math.floor(dur),
pct: Math.min(99, Math.max(2, Math.round(ratio * 100))), pct: Math.min(99, Math.max(2, Math.round(ratio * 100))),
@@ -9260,6 +9276,12 @@ try {
.join('|'); .join('|');
var shelf = document.getElementById('yaktube-continue-watching-shelf'); var shelf = document.getElementById('yaktube-continue-watching-shelf');
if (shelf && (!shelf.isConnected || !document.body.contains(shelf))) {
try {
shelf.remove();
} catch (e) {}
shelf = null;
}
if (shelf) { if (shelf) {
var curSig = shelf.getAttribute('data-render-sig'); var curSig = shelf.getAttribute('data-render-sig');
if (chipsBar && shelf.previousElementSibling !== chipsBar && chipsBar.parentElement) { if (chipsBar && shelf.previousElementSibling !== chipsBar && chipsBar.parentElement) {