Reposition Recently Uploaded Chip

Repositions the "Recently Uploaded" chip to the front

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Reposition Recently Uploaded Chip
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Repositions the "Recently Uploaded" chip to the front
// @author       RadicalDowntownUrbanite
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// @license      MIT
// ==/UserScript==

/**
 * Originally I wanted to hook unto the pushState of the site to check for the
 * position of the Recently Uploded chip, however YT uses some secret sauce I
 * am not familiar with to change page state which makes it difficult to hook
 * into it without just polling the url. Instead I use a mutation observer to
 * trigger whenever the DOM of the site changes and then update the position
 * of the Recently Uploaded chip if it's present on the page.
 */
(function() {
    'use strict';

    function debounce(func) {
        let timer;

        return (...args) => {
            clearTimeout(timer);
            timer = setTimeout(() => func.apply(this, args), 300);
        };
    }

    /**
     * Debounce the mutation observer callback because the MO can really thrash while the page is loading.
     * This will result in a slight delay before the RU chip is moved but won't affect page load performance either.
     */
    const updateRecentlyUploaded = debounce((mutations, me) => {
        if (!window.location.pathname === '/') {
            //console.debug(`=========== Not on main url ${window.location.href}`)
            return ;
        }

        const chips = [...document.querySelectorAll('iron-selector.ytd-feed-filter-chip-bar-renderer yt-chip-cloud-chip-renderer')];

        if (chips.length === 0) {
            //console.debug('=========== No chips');
            return;
        }

        const index = chips.findIndex(chip => chip.innerText === 'Recently uploaded')

        if (index > 1) {
            //console.debug('=========== Recently uploaded found and not first index');
            const chip = chips[index];
            const parent = chip.parentNode;
            parent.removeChild(chip);
            parent.prepend(chip);
         //} else if (index === 0) {
            //console.debug('=========== Recently uploaded already at first position');
         //} else {
            //console.debug('=========== Recently uploaded chip not found');
        }
    });

    // set up the mutation observer
    const observer = new MutationObserver(updateRecentlyUploaded);

    // start observing
    observer.observe(document, {
        childList: true,
        subtree: true
    });

})();