Files
Docker/uniapp/Google Chrome/Resources/video_grab.js
T
2026-11-03 09:19:50 +08:00

61 lines
1.7 KiB
JavaScript

// 点击"下载视频"时执行:读取当前 <video> 的播放源,并把嗅探到的候选地址一起返回给宿主。
(function () {
try {
var vids = Array.prototype.slice.call(document.querySelectorAll("video"));
var best = null;
for (var i = 0; i < vids.length; i++) {
var v = vids[i];
if (v.videoWidth > 0 || !isNaN(v.duration)) {
best = v;
break;
}
}
if (!best) best = vids[0];
var current = "";
var playable = true;
if (best) {
current = best.currentSrc || best.src || "";
if (!current) {
var s = best.querySelector && best.querySelector("source");
if (s) current = s.src || s.getAttribute("src") || "";
}
if (best.networkState === 0 || (best.msKeySystemLoaded && !best.src))
playable = false;
}
var title = document.title || "";
var h1 = document.querySelector("h1");
if (h1 && h1.innerText) title = h1.innerText;
var anchors = [];
var links = document.querySelectorAll("a[href]");
for (var j = 0; j < links.length; j++) {
var h = links[j].href;
if (
window.__reportMedia &&
/\.(mp4|flv|m3u8|mov|mkv|webm|ts)(\?|#|$)/i.test(h)
)
anchors.push(h);
}
return JSON.stringify({
current: current || "",
playable: playable,
usesMse: !!window.__usesMse || /^blob:/i.test(current),
title: title,
pageUrl: location.href,
sniffed: (window.__mediaUrls || []).slice(-60),
anchors: anchors.slice(-20),
m3u8Blobs: (window.__m3u8Blobs || []).slice(-1),
});
} catch (e) {
return JSON.stringify({
current: "",
title: document.title || "",
pageUrl: location.href,
error: String(e),
});
}
})();