Last active
February 20, 2022 23:13
-
-
Save q00u/e1ddb4794bf3148863085e83dd1af273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YouTube - All, Recently Uploaded, Mixes | |
// @namespace https://gist.github.com/q00u | |
// @version 0.3 | |
// @description Re-order the YouTube button bar so that Recently Uploaded and Mixes are easier to reach | |
// @author Phoenix G | |
// @run-at document-idle | |
// @match https://www.youtube.com/ | |
// @icon http://f1.allesedv.com/16/youtube.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// console.log('Starting YouTube Recently'); | |
const priority = ['Recently uploaded']; // Array of button titles you want moved to the start | |
// This is where we handle the chips array (whenever it loads) | |
function handleChips(chips) { | |
// console.log('Got chips:', chips); | |
const chipschildren = chips.children; // Get all child elements (the buttons themselves) | |
// console.log('Got chips children:', chipschildren); | |
for (let i = 0; i < chipschildren.length; i++) { // For each child (button)... | |
const child = chipschildren[i]; // Set child to this button | |
const childTitle = child.firstChild.nextSibling.getAttribute('title'); // Get the title of this button | |
// console.log('Looking at', childTitle); | |
if (priority.includes(childTitle)) { // Is this title in the priority list? | |
chips.insertBefore(child, chips.firstChild.nextSibling.nextSibling); // Move to front | |
} | |
} | |
} | |
// Set up mutation observer | |
const observer = new MutationObserver(function (mutations, me) { | |
// `mutations` is an array of mutations that occurred | |
// `me` is the MutationObserver instance | |
const chips = document.getElementById('chips'); | |
if (chips) { | |
handleChips(chips); | |
me.disconnect(); // I'm done | |
return; | |
} | |
}); | |
// start observing | |
observer.observe(document, { | |
childList: true, | |
subtree: true, | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
v 0.3:
Put it in an observer, to wait until the chips array exists