FreeTube Button

Add an option to open YouTube videos in FreeTube

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         FreeTube Button
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Add an option to open YouTube videos in FreeTube
// @author       devilrajat
// @match        *://www.youtube.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to create and add the FreeTube button
    function addFreeTubeButton(videoLink) {
        // Check if the FreeTube button is already added
        if (videoLink.nextElementSibling && videoLink.nextElementSibling.classList.contains('freetube-button')) {
            return;
        }

        // Create the FreeTube button
        let freeTubeButton = document.createElement('a');
        freeTubeButton.href = 'freetube://' + videoLink.href;
        freeTubeButton.textContent = 'Open in FreeTube';
        freeTubeButton.style.marginLeft = '10px';
        freeTubeButton.style.color = '#ff0000';
        freeTubeButton.classList.add('freetube-button');

        // Insert the button after the video link
        videoLink.parentNode.insertBefore(freeTubeButton, videoLink.nextSibling);
    }

    // Add event listeners to all video links on the home page
    function addListeners() {
        let videoLinks = document.querySelectorAll('a#video-title, a#thumbnail, a[href^="/watch"]');
        videoLinks.forEach(link => {
            addFreeTubeButton(link);
        });
    }

    // Initial run and re-run when new content is loaded dynamically
    new MutationObserver(addListeners).observe(document.body, { childList: true, subtree: true });

    // Initial call to addListeners
    addListeners();
})();