Repository navigation
Expand file tree
/
Copy pathinject.js
More file actions
64 lines (50 loc) · 1.47 KB
/
Copy pathinject.js
File metadata and controls
64 lines (50 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function () {
console.log("🔥 Injected script running");
function getHeatmapSegments() {
try {
const data = window.ytInitialPlayerResponse;
const markers =
data?.playerOverlays?.playerOverlayRenderer?.decoratedPlayerBarRenderer
?.decoratedPlayerBarRenderer?.playerBar
?.multiMarkersPlayerBarRenderer?.markersMap;
if (!markers) return null;
const heatmapObj = markers.find(m => m.key === "HEATSEEKER");
if (!heatmapObj) return null;
const heatMarkers =
heatmapObj.value.heatmap.heatmapRenderer.heatMarkers;
// 🔥 Top 3 peaks
const sorted = [...heatMarkers]
.sort((a, b) =>
b.heatMarkerIntensityScoreNormalized -
a.heatMarkerIntensityScoreNormalized
)
.slice(0, 3);
return sorted.map(m => ({
start: m.timeRangeStartMillis / 1000,
end: m.timeRangeStartMillis / 1000 + 10
}));
} catch {
return null;
}
}
function fallback(video) {
const d = video.duration;
return [
{ start: d * 0.5, end: d * 0.5 + 10 },
{ start: d * 0.7, end: d * 0.7 + 10 }
];
}
function sendData() {
const video = document.querySelector("video");
let segments = getHeatmapSegments();
if (!segments) {
console.log("Fallback segments");
segments = fallback(video);
}
window.postMessage({
type: "HIGHLIGHT_DATA",
segments
}, "*");
}
setTimeout(sendData, 4000);
})();