YouTube Awesome

Get the best YouTube experience

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         YouTube Awesome
// @namespace    https://github.com/pagyew
// @version      1.0.9
// @description  Get the best YouTube experience
// @author       Vladislav Tsepilov (https://github.com/pagyew)
// @license      MIT
// @homepageURL  https://github.com/pagyew/youtube-awesome
// @supportURL   https://github.com/pagyew/youtube-awesome
// @match        https://www.youtube.com/*
// @match        https://m.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @run-at       document-body
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// ==/UserScript==

(function () {
  'use strict';

  const shortsSelectors = [
    // Menus
    'ytm-pivot-bar-item-renderer:has(.pivot-shorts)',
    'ytd-mini-guide-entry-renderer:has(a#endpoint[title*="shorts" i])',
    'ytd-guide-entry-renderer:has(a#endpoint[title*="shorts" i])',

    // Tabs
    'yt-chip-cloud-chip-renderer:has(yt-formatted-string[title*="shorts" i])',
    'yt-tab-shape[tab-title*="shorts" i]',

    // Sections
    'ytm-reel-shelf-renderer',
    'ytd-reel-shelf-renderer',
    'ytm-item-section-renderer:has(.big-shorts-singleton)',
    'ytd-rich-section-renderer:has(ytd-rich-shelf-renderer)',

    // Videos
    'ytd-video-renderer:has(a#thumbnail[href*="shorts" i])',

    // Ads
    'ytd-rich-item-renderer:has(ytd-ad-slot-renderer)',
  ];

  const mixSelectors = [
    // Tabs
    'yt-chip-cloud-chip-renderer:has(yt-formatted-string[title*=mixes i])',

    // Videos
    'ytd-rich-item-renderer:has(ytd-playlist-thumbnail):has(a[title^="Mix - "])',
    'ytd-rich-item-renderer:has(ytd-playlist-thumbnail):has(a[title="My Mix"])',
    'ytd-rich-item-renderer:has(yt-collections-stack):has([title^="Mix - "])',
    'ytd-rich-item-renderer:has(yt-collections-stack):has([title="My Mix"])',
    'ytd-radio-renderer:has(ytd-playlist-thumbnail):has(span[title^="Mix - "])',
    'ytd-compact-radio-renderer:has(yt-collections-stack):has(span[title^="Mix - "])',
  ];

  const watchedSelectors = [
    //Videos
    'ytd-rich-item-renderer:has(#progress[style="width: 100%;"])',
    'ytd-compact-video-renderer:has(#progress[style="width: 100%;"])',
  ];

  const options = [
    {
      id: 'shorts',
      title: 'Shorts',
      defaultValue: true,
      selectors: shortsSelectors,
    },
    {
      id: 'mix',
      title: 'Mixes',
      defaultValue: true,
      selectors: mixSelectors,
    },
    {
      id: 'watched',
      title: 'Watched',
      defaultValue: true,
      selectors: watchedSelectors,
    },
  ];

  function register(option) {
    const { id, ref, title } = option;
    const command = `--- ${ref.value ? '✅' : '❌'} ${title}`;

    GM_registerMenuCommand(
      command,
      () => {
        ref.value = !ref.value;
        setTimeout(update);
      },
      {
        id,
        autoClose: false,
      },
    );
  };

  function unregister(option) {
    GM_unregisterMenuCommand(option.id);
  };

  function useOption(option) {
    const { id, defaultValue } = option;

    if (typeof GM_getValue === 'undefined') {
      return { value: defaultValue };
    };

    const ref = {
      get value() {
        return GM_getValue(id, defaultValue);
      },
      set value(v) {
        GM_setValue(id, v);
      },
    };

    return { ...option, ref };
  };

  const style = document.createElement('style');
  document.body.appendChild(style);
  
  const usedOptions = options.map(useOption);
  GM_registerMenuCommand('Hide:', () => { }, { autoClose: false });

  function update() {
    usedOptions.forEach(unregister);
    usedOptions.forEach(register);

    const selectors = usedOptions
      .filter(({ ref }) => ref.value)
      .map(({ selectors }) => selectors)
      .flat();

    if (selectors.length > 0) {
      style.innerText = `${selectors.join(',')}{ display: none !important; }`;
    };
  };

  update();
})();