🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

YouTube - Live Recoder

chronium based only

Stan na 04-08-2025. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         YouTube - Live Recoder
// @namespace    https://greasyfork.org/ja/users/941284-ぐらんぴ
// @version      2025-08-04
// @description  chronium based only
// @author       ぐらんぴ
// @match        https://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @run-at       document-start
// @require      https://greasyfork.org/scripts/433051-trusted-types-helper/code/Trusted-Types%20Helper.js
// @license      MIT
// ==/UserScript==

let $s = (el) => document.querySelector(el), $sa = (el) => document.querySelectorAll(el), $c = (el) => document.createElement(el)
let recorder, chunks = [], isRecording = false, seconds = 0, timerInterval;

window.addEventListener("yt-navigate-finish", e => {
    if(e.detail.pageType == "watch"){
        if(e.detail.response?.playerResponse?.videoDetails?.isLive){// live
            //filename
            const now = new Date();
            const month = String(now.getMonth() + 1).padStart(2, '0');
            const day = String(now.getDate()).padStart(2, '0');
            let name = e.detail.response.playerResponse.videoDetails?.author
            let title = e.detail.response.playerResponse.videoDetails?.title
            //let videoId = e.detail.response.playerResponse.videoDetails?.videoId

            let addon = $s('.ytp-right-controls')
            let btn = $c('button');
            btn.textContent = ` [RECORD]`;
            btn.className = "GRMP";
            btn.style.cursor = "pointer";
            btn.style.color = "white";
            btn.style.background = "none";
            btn.style.border = "none";
            btn.style.cursor = "pointer";
            btn.addEventListener("click", () => {
                const video = $s("video");
                if(!video){
                    alert("Video element not found.");
                    return;
                }

                if(video.paused || video.readyState < 3){
                    video.play().catch(err => console.warn("Video play failed:", err));
                }

                if(!isRecording){
                    try{
                        const stream = video.captureStream();
                        if(!stream){
                            alert("Failed to capture stream.");
                            return;
                        }

                        recorder = new MediaRecorder(stream);
                        chunks = [];

                        recorder.ondataavailable = e => chunks.push(e.data);
                        recorder.onstop = () => {
                            clearInterval(timerInterval);
                            btn.textContent = ` [RECORD]`;

                            const blob = new Blob(chunks, { type: 'video/webm' });
                            const url = URL.createObjectURL(blob);
                            const a = document.createElement('a');
                            a.href = url;

                            try{
                                a.download = name + "_" + title + "_" + month + "/" + day + ".webm";
                            }catch(e){ //alert('Could not get filename', e)
                                a.download = location.search.replace('?v=', '') + "_" + month + "/" + day + ".webm";
                            };
                            a.click();
                        };

                        recorder.start();
                        isRecording = true;
                        seconds = 0;
                        btn.textContent = formatTime(seconds);

                        timerInterval = setInterval(() => {
                            seconds++;
                            btn.textContent = formatTime(seconds);
                        }, 1000);

                    }catch(e){ alert("Recording failed: " + e);
                             }
                }else{
                    recorder.stop();
                    isRecording = false;
                    clearInterval(timerInterval);
                    btn.textContent = ` [RECORD]`;
                }
            });
            if(!$s('.GRMP')) addon.appendChild(btn);

            function formatTime(sec){
                const m = String(Math.floor(sec / 60)).padStart(2, '0');
                const s = String(sec % 60).padStart(2, '0');
                return ` [${m}:${s}]`;
            }
        }
    }
});