Greasy Fork is available in English.

YouTube: Move "New To You" to front

Moves the "New To You" button to the front of the list, right after "All".

  1. // ==UserScript==
  2. // @name YouTube: Move "New To You" to front
  3. // @namespace https://mathemaniac.org/
  4. // @version 1.1.0
  5. // @description Moves the "New To You" button to the front of the list, right after "All".
  6. // @match https://www.youtube.com/
  7. // @copyright 2023, Sebastian Paaske Tørholm
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. 'use strict';
  13.  
  14. // Changelog:
  15. // 1.1.0: Re-do the sorting when returning to front page from a video as well.
  16.  
  17.  
  18. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  19. var config = { childList: true, characterData: false, attributes: false, subtree: true };
  20. var observer = new MutationObserver( function (mutations) {
  21. mutations.forEach( function (mutation) {
  22. if (mutation.type == 'childList') {
  23. let chips = document.querySelector('#chips');
  24. if (chips && ! chips.querySelector('yt-chip-cloud-chip-renderer:has([title="All"]) + yt-chip-cloud-chip-renderer:has([title="New to you"])')) {
  25. moveButton();
  26. }
  27. }
  28. });
  29. });
  30.  
  31. observer.observe(document.querySelector('body'), config);
  32.  
  33. var interval;
  34.  
  35. function moveButton () {
  36. let chips = document.querySelector('#chips');
  37. if (! chips) return;
  38.  
  39. let all = chips.querySelector('yt-chip-cloud-chip-renderer:has([title="All"])');
  40. let newToYou = chips.querySelector('yt-chip-cloud-chip-renderer:has([title="New to you"])');
  41.  
  42. if (!all || !newToYou) return;
  43.  
  44. newToYou.remove();
  45. all.insertAdjacentElement('afterend', newToYou);
  46. clearInterval(interval);
  47. }
  48.  
  49. interval = setInterval(moveButton, 100);