Invidious (yewtu.be) embed

Replace YouTube embeds with yewtu.be embeds.

目前為 2022-01-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Invidious (yewtu.be) embed
// @description Replace YouTube embeds with yewtu.be embeds.
// @author      Backend & SkauOfArcadia
// @homepage https://skau.neocities.org/
// @contactURL https://t.me/SkauOfArcadia
// @include     *
// @exclude *://www.youtube.com/*
// @exclude *://*.google.com/*
// @exclude *://web.archive.org/web/*
// @version     2.56
// @namespace https://greasyfork.org/users/751327
// ==/UserScript==
var a = -1; //defines autoplay value on the initial page load
var b = -1; //defines autoplay for embedded videos that appear on page interaction
// -1 = will only autoplay if the embed has the "autoplay=1" parameter
// 0 = disables autoplay
// 1 = enables autoplay

var observer = new MutationObserver(mutate);
observer.observe(document, {
    childList: true,
    attributes: true,
    subtree: true
});

function mutate() {
    go(b);
}

function go(auto) {
    var frames = document.getElementsByTagName("iframe");
    frames = Object.values(frames).filter(youtubeiFrame);

    for (var i = 0; i < frames.length; i++) {
        var frame = frames[i];
        var src = frame.getAttribute('src');
        if (window.location.hostname.indexOf('duckduckgo.com') !== -1 && src.indexOf('/video_frame?url=') === 0) {
            src = decodeURIComponent(src.replace('/video_frame?url=', ''));
        }
        var invid = src.
        replace('www.', '').
        replace('youtube.com', 'yewtu.be').
        replace('youtube-nocookie.com', 'yewtu.be')
            .replace('youtu.be/', 'yewtu.be/embed/');

        let params = new URLSearchParams();
        if (invid.indexOf('?') !== -1) {
            params = new URLSearchParams(invid.split('?').pop());
            invid = invid.split('?')[0];
            params.delete('controls');
        }

        if (auto !== -1) {
            params.set('autoplay', auto);
        } else if (!params.get('autoplay')) {
            params.set('autoplay', 0);
        }

        if ((frame.width === '0' || frame.width === '1' || frame.style.width === '0px' || frame.style.width === '1px')
        && (frame.height === '0' || frame.height === '1' || frame.style.height === '0px' || frame.style.height === '1px')
        && params.get('autoplay') === '1') {
            params.set('listen', 1);
        }

        invid += '?' + params;
        frame.setAttribute('src', invid);
    }
}

function youtubeiFrame(el) {
    if (el.hasAttribute('src')) {
        return (el.getAttribute('src').indexOf('youtube') !== -1 || el.getAttribute('src').indexOf('youtu.be') !== -1);
    }
    return false;
}

go(a);