YouTube /embed/ forwarder

Forwards YouTube links to the youtube.com/embed/* page, so there's just the video in your window and nothing else.

21.08.2025 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        YouTube /embed/ forwarder
// @description Forwards YouTube links to the youtube.com/embed/* page, so there's just the video in your window and nothing else.
// @namespace   https://greasyfork.org/en/users/1148791-vuccala
// @author      Vuccala
// @icon        https://archive.org/download/yt_icon/yt.png
// @match       *://*.youtube.com/*
// @match       *://*.youtu.be/*
// @run-at      document-start
// @version     0.6
// @grant       none
// @license     MIT
// ==/UserScript==
(function () {
    const embedBaseUrl = 'https://www.youtube.com/embed/';

    function getVideoAndPlaylist(url) {
        const videoMatch = /(?:[?&]v=|\/(?:embed\/|v\/|shorts\/))([^&?/]+)/.exec(url);
        const listMatch = /[?&]list=([^&]+)/.exec(url);
        return {
            videoId: videoMatch ? videoMatch[1] : '',
            listId: listMatch ? listMatch[1] : ''
        };
    }

    function ensureReferrerMeta() {
        const head = document.head || document.documentElement;
        if (!head.querySelector('meta[name="referrer"]')) {
            const meta = document.createElement('meta');
            meta.name = 'referrer';
            meta.content = 'origin';
            head.prepend(meta);
        }
    }

    function updateLinks(links) {
        links.forEach(link => {
            const { videoId, listId } = getVideoAndPlaylist(link.href);
            if (videoId) {
                let embedUrl = embedBaseUrl + videoId;
                if (listId) embedUrl += '?list=' + listId;
                link.href = embedUrl;
            }
        });
    }

    function observeDOM() {
        const targetNode = document.body;
        const observer = new MutationObserver(mutationsList => {
            for (const mutation of mutationsList) {
                if (mutation.type === 'childList' && mutation.addedNodes[0]) {
                    const newLinks = mutation.addedNodes[0].querySelectorAll?.(
                        'a[href*="/watch?v="], a[href*="/shorts/"], a[href*="/watch?app=desktop&v="]'
                    );
                    if (newLinks?.length) updateLinks(newLinks);
                }
            }
        });
        observer.observe(targetNode, { childList: true, subtree: true });
    }

    const url = window.location.href;
    const { videoId, listId } = getVideoAndPlaylist(url);

    if (videoId) {
        let embedUrl = embedBaseUrl + videoId;
        if (listId) embedUrl += '?list=' + listId;

        if (embedUrl !== url) {
            ensureReferrerMeta();
            window.location.replace(embedUrl);
        }
    } else {
        observeDOM();
    }
})();