Youtube Comments And Secondary Video Recommender Element Switcher

Switches the positions of two elements on a web page

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Youtube Comments And Secondary Video Recommender Element Switcher
// @namespace    http://your-namespace.com
// @version      1.0.5
// @description  Switches the positions of two elements on a web page
// @match        *://*.youtube.com/*
// @grant        none
// @author       Anuraag Gupta
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    let checkElementsInterval;
    function switchElements(element1, element2) {
        // Get the parent node of both elements
        var parent1 = element1.parentNode;
        var parent2 = element2.parentNode;

        // Get the next sibling of both elements
        var next1 = element1.nextSibling;
        var next2 = element2.nextSibling;

        // Swap the positions of the elements by inserting them in their new positions
        parent1.insertBefore(element2, next1);
        parent2.insertBefore(element1, next2);
        clearInterval(checkElementsInterval);
    }
    // Wait for the document to be fully loaded
    window.addEventListener('load', function() {
        checkElementsInterval = setInterval(function() {
            var comments = document.getElementById('comments'); // Replace 'element1' with the ID of your first element
            var secondary = document.getElementById('secondary'); // Replace 'element2' with the ID of your second element

            if (comments && secondary) {
                switchElements(comments, secondary);
                secondary.style = "width:100%";
                // Youtube uses hardcoded px for video tags. This seemed easier for Mac's screeen
                comments.style = "width:426px; height: 100vh;overflow: auto;";
            }
        }, 500); // Adjust the delay (in milliseconds) as needed
    })
})();