TEMPORARY DIAGNOSTICS: Integrate querySelectorAllShadow in Disney+ specific functions

This commit is contained in:
Timo
2026-07-02 13:45:36 +02:00
parent 705fbc146b
commit a9f5c0b9bf
2 changed files with 63 additions and 28 deletions
+61 -28
View File
@@ -140,7 +140,7 @@
return matchesPlayerUrls(['disneyplus.com']);
}
function getSeekableRange(video) {
function getSeekableRange(video) {
try {
const ranges = video.seekable;
if (!ranges || ranges.length === 0) return null;
@@ -199,7 +199,7 @@
'p',
'div'
].join(',');
const nodes = Array.from(document.querySelectorAll(selectors)).slice(0, 2000);
const nodes = querySelectorAllShadow(selectors).slice(0, 2000);
const textParts = [];
const candidates = [];
let best = null;
@@ -208,7 +208,7 @@
function considerTimeline(parsed, source, weight = 0) {
if (!parsed) return;
const score = weight +
(parsed.duration >= 20 * 60 ? 200 : 0) +
(parsed.duration >= 20 * 60 ? 200 : 0) +
(parsed.current > 0 ? 50 : 0) -
Math.abs((parsed.duration / 2) - parsed.current) / 100;
candidates.push({ ...parsed, source, score: Math.round(score) });
@@ -1679,40 +1679,73 @@
if (video && currentTitle && sameEpisode(currentTitle, expectedTitle)
&& video.currentTime < 5 && video.readyState >= 1) {
// Match! Pause at start and report ready.
if (!video.paused) {
_setSuppress('paused');
video.pause();
}
stopLobbyPoll();
chrome.runtime.sendMessage({
type: 'EPISODE_READY_LOCAL',
payload: { title: currentTitle }
}).catch(() => {});
reportLog(`Episode lobby: Ready for "${currentTitle}"`, 'success');
return true;
}
return false;
}
function startLobbyPoll(expectedTitle) {
_setSuppress('paused');
video.pause();
}
stopLobbyPoll();
chrome.runtime.sendMessage({
type: 'EPISODE_READY_LOCAL',
payload: { title: currentTitle }
}).catch(() => {});
stopLobbyPoll();
_pendingLobbyTitle = expectedTitle;
// NOTE: Do NOT pause here. Three callers reach this function:
// 1. PAUSE_FOR_LOBBY (initiator): already paused by that handler before calling us.
// 2. EPISODE_LOBBY (non-initiator): peer may still be on the PREVIOUS episode — pausing
// would freeze them mid-episode. The pause happens inside checkAndReportLobbyReady()
return true;
}
return false;
}
// only once their title actually matches.
// 3. CONTENT_BOOT recovery: same reasoning as (2).
// Check immediately
if (checkAndReportLobbyReady(expectedTitle)) return;
// Poll every 2 seconds — no log spam, internal only
lobbyPollTimer = setInterval(() => {
checkAndReportLobbyReady(expectedTitle);
}, 2000);
+2
View File
@@ -94,6 +94,8 @@ function loadTimelineFns(hostname, document = makeDocument()) {
'let lastKnownDisneyPlusDuration = 0;',
'let lastKnownDisneyPlusScale = 1;',
'let lastKnownDisneyPlusStart = 0;',
extractFunction('scanShadowDom', source),
extractFunction('querySelectorAllShadow', source),
extractFunction('hostMatchesUrl', source),
extractFunction('matchesPlayerUrls', source),
extractFunction('isDisneyPlusHost', source),