Insert Videos Based on Type

Cory's Avatar
Cory · in Themes & Extensions
17 replies 326 views

Inserting a video is awesome! no faffing about with tags.,paste and it’s done.. brilliant… thats what I like… things to be easy..no faffing… 🙂

On Aug 19, 2026, NeoMetallix said:

I modified the code so it includes Rumble. I figured someone else might like it. I’ve been thinking about having Odysee included too for more alternative platforms.

<script>
const videoWidth = 560;
const videoHeight = 315;
const previewDIV = document.querySelector('.tiptap-toolbar');

if (previewDIV) {
    const insertVideo = document.createElement('button');
    insertVideo.type = 'button';
    insertVideo.id = 'insert-video';
    insertVideo.className = 'btn btn-secondary btn-sm';
    insertVideo.innerText = 'Insert Video';
    previewDIV.appendChild(insertVideo);

    document.querySelector('#insert-video').addEventListener("click", () => {

        if (document.querySelector('#video-container')) {
            document.querySelector('#video-container').remove();
        }

        const videoSelector = `
        <div id="video-container" class="panel" style="border-width: 1px; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%)">
            <div class="panel__sub-header">Insert a Video:</div>
            <div style="padding: 1rem">
                Video Type:<br>
                <select>
                    <option value="-1">Select One</option>
                    <option>Dailymotion</option>
                    <option>Facebook</option>
                    <option>TikTok</option>
                    <option>Twitch</option>
                    <option>Vimeo</option>
                    <option>Rumble</option>
                </select>
                <br><br>
                Video URL (iframe only for Rumble):<br>
                <input type="text">
            </div>
            <div class="panel__sub-header">
                <button type="button" class="btn btn-secondary btn-sm submit">Submit</button>
                <button type="button" class="btn btn-secondary btn-sm cancel">Cancel</button>
            </div>
        </div>`;
        document.body.insertAdjacentHTML('beforeend', videoSelector);

        document.querySelector('#video-container button.cancel').addEventListener("click", () => {
            document.querySelector('#video-container').remove();
        });

        document.querySelector('#video-container button.submit').addEventListener("click", () => {
            const type = document.querySelector('#video-container select').value;
            const video = document.querySelector('#video-container input').value;
            document.querySelector('#video-container').remove();

            if (type !== '-1') {
                document.querySelector('.tiptap-editor p').innerHTML += `[VIDEO=${type}]${video}[/VIDEO]`;
            }
        });
    });
}

const content = document.querySelectorAll('div.content');

if (content) {
    content.forEach(post => {
        post.innerHTML = post.innerHTML.replace(/\[VIDEO=(.+?)\](.+?)\[\/VIDEO\]/g, '<span class="video $1">$2</span>');
    });

    const video = document.querySelectorAll('span.video');
    const scriptFB = document.createElement('script');
    scriptFB.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v21.0';
    document.body.appendChild(scriptFB);
    const scriptTikTok = document.createElement('script');
    scriptTikTok.src = 'https://www.tiktok.com/embed.js';
    document.body.appendChild(scriptTikTok);

    video.forEach(html => {
        const vType = html.getAttribute('class').split('video ')[1];
        let vID;

        if (vType === 'Dailymotion') {
            vID = html.innerText.split('/video/')[1];
            html.innerHTML = `<iframe src="https://geo.dailymotion.com/player.html?video=${vID}" style="width:${videoWidth}px; height:${videoHeight}px; overflow:hidden; border:none;" allowfullscreen title="Dailymotion Video Player" allow="web-share"></iframe>`;
        } else if (vType === 'Facebook') {
            vID = html.innerText.split('/videos/')[1].split('/?')[0];
            html.innerHTML = `<div class="fb-video" data-href="https://www.facebook.com/facebook/videos/${vID}/" data-width="${videoWidth}" data-height="${videoHeight}" ata-show-text="false"></div><div id="fb-root"></div>`;
        } else if (vType === 'TikTok') {
            vID = html.innerText.split('/video/')[1].split('?')[0];
            let channel = html.innerText.split('.com/')[1].split('/')[0];
            html.innerHTML = `<blockquote class="tiktok-embed" cite="https://www.tiktok.com/${channel}/video/${vID}" data-video-id="${vID}" data-embed-from="embed_page"><section></section></blockquote>`;
        } else if (vType === 'Twitch') {
            vID = html.innerText.split('/videos/')[1];
            let loc = location.href.split('https://')[1].split('/')[0];
            html.innerHTML = `<iframe src="https://player.twitch.tv/?video=v${vID}&parent=${loc}&autoplay=false" width="${videoWidth}" height="${videoHeight}" allowfullscreen></iframe>`;
        } else if (vType === 'Vimeo') {
            vID = html.innerText.substring(html.innerText.lastIndexOf('/') + 1);
            html.innerHTML = `<iframe src="https://player.vimeo.com/video/${vID}" width="${videoWidth}" height="${videoHeight}" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>`;
        } else if (vType === 'Rumble') {
            // Only allow iframe URL, no direct URL
            // Example iframe URL: https://rumble.com/embed/v6vgexp
            if (html.innerText.includes('rumble.com/embed/')) {
                html.innerHTML = `<iframe src="${html.innerText}" width="${videoWidth}" height="${videoHeight}" frameborder="0" allowfullscreen allow="autoplay; encrypted-media"></iframe>`;
            } else {
                html.innerHTML = `<p style="color:red;">Rumble iframe URL required</p>`;
            }
        }
    });
}
</script>

Nice, you mentioned adding Odysee too, would that be difficult to do?

On Aug 19, 2026, Excalibur said:

Nice, you mentioned adding Odysee too, would that be difficult to do?

Not sure, I can see. Rumble was difficult because iframe URL is different from video URL. At first it was getting the wrong video and then it was rotating on every refresh. Finally got it to work right.

Theme: FS 2.0
Create Your Community with ForumSpark

ForumSpark is a modern community platform built on custom software. It combines the familiar feel of classic forums with a fast, simple experience designed for today’s communities.