Elamigos - Embed YouTube Video

Embed YouTube videos on elamigos.site/data/* pages if a YouTube link is present.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Elamigos - Embed YouTube Video
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Embed YouTube videos on elamigos.site/data/* pages if a YouTube link is present.
// @author       Drigtime
// @match        https://elamigos.site/data/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=elamigos.site
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract the YouTube video ID from a YouTube link
    function extractVideoId(url) {
        const match = url.match(/(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?feature=player_embedded&v=))([^&\n?#]+)/);
        return match && match[1];
    }

    // Find all links on the page
    const allParagraphs = document.querySelectorAll('p');

    // Loop through each link
    allParagraphs.forEach(paragraph => {
        const text = paragraph.textContent;
        const videoId = extractVideoId(text);
        if (videoId) {
            // Create an iframe to embed the YouTube video
            const iframe = document.createElement('iframe');
            iframe.width = '560';
            iframe.height = '315';
            iframe.src = `https://www.youtube.com/embed/${videoId}`;
            iframe.frameborder = '0';
            iframe.allow = 'fullscreen';

            // Replace the link with the embedded video
            paragraph.parentNode.replaceChild(iframe, paragraph);
        }
    });
})();