mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-29 19:21:33 -07:00
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import type { OverlayContentMeasurement, OverlayContentRect } from '../../types';
|
|
import type { AutoplayReadySignal } from './autoplay-ready-gate';
|
|
|
|
export type VisibleOverlayAutoplayReadinessDeps = {
|
|
getVisibleOverlayVisible: () => boolean;
|
|
isOverlayWindowReady: () => boolean;
|
|
getLatestVisibleMeasurement: () => OverlayContentMeasurement | null;
|
|
};
|
|
|
|
function hasArea(rect: OverlayContentRect): boolean {
|
|
return rect.width > 0 && rect.height > 0;
|
|
}
|
|
|
|
function hasMeasuredInteractiveContent(measurement: OverlayContentMeasurement): boolean {
|
|
const rects =
|
|
Array.isArray(measurement.interactiveRects) && measurement.interactiveRects.some(hasArea)
|
|
? measurement.interactiveRects
|
|
: measurement.contentRect
|
|
? [measurement.contentRect]
|
|
: [];
|
|
|
|
return rects.some(hasArea);
|
|
}
|
|
|
|
export function isVisibleOverlayAutoplayTargetReady(
|
|
deps: VisibleOverlayAutoplayReadinessDeps,
|
|
signal: AutoplayReadySignal,
|
|
): boolean {
|
|
if (!deps.getVisibleOverlayVisible()) {
|
|
return true;
|
|
}
|
|
|
|
const subtitleText = signal.payload.text.trim();
|
|
if (!subtitleText) {
|
|
return false;
|
|
}
|
|
|
|
if (!deps.isOverlayWindowReady()) {
|
|
return false;
|
|
}
|
|
|
|
if (subtitleText === '__warm__') {
|
|
return true;
|
|
}
|
|
|
|
const measurement = deps.getLatestVisibleMeasurement();
|
|
if (!measurement || measurement.measuredAtMs < signal.requestedAtMs) {
|
|
return false;
|
|
}
|
|
|
|
return hasMeasuredInteractiveContent(measurement);
|
|
}
|