Youtube 2020 improvements

All Youtube improvements in one pack

As of 2021-01-03. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Youtube 2020 improvements
// @version      0.5
// @description  All Youtube improvements in one pack
// @author       Burlaka.net
// @match        *://*.youtube.com/*
// @match        *://youtube.com/*
// @require      https://code.jquery.com/jquery-latest.js
// @grant        none
// @namespace    http://tampermonkey.net/
// ==/UserScript==

(function() {
  'use strict';

  // hide three dots in list so we can see date when video published (on narrow screens)
  function hideThreeDots() {
    if ($('#menu-container yt-icon-button#button.dropdown-trigger').length > 0) {
      $('#menu-container yt-icon-button#button.dropdown-trigger').remove();
      clearInterval(hideThreeDotsTimer);
    }
  }
  var hideThreeDotsTimer = setInterval(hideThreeDots, 1000);

  //$('ytd-playlist-panel-renderer#playlist .header').addClass('hidden');//.css('backgroundColor', '#ff6600') //hide();

  // Убирает заголовок плейлиста
  //$('#playlist .header').addClass('hidden').hide();

  //Убирает блок "Для этого видео запись чата отключена."
  //$('ytd-message-renderer.ytd-live-chat-frame').addClass('hidden').hide();
  //$('.ytd-live-chat-frame').addClass('hidden').hide();

  $('body').append('<style>\
#playlist .header {display:none !important;}\
ytd-live-chat-frame#chat {display:none !important;}\
/*#player-theater-container, .html5-video-player {width: 100%;max-width: 854px;height:100%;max-height:480px; margin: 0 auto;}\
#player-theater-container {max-height: 480px !important;}\
#player-container {width: 100%;max-width: 854px;height:100%;max-height:480px; margin: 0 auto;}\
.html5-video-player {width:100%; height:100%}*/\
#container.ytd-masthead {height:34px}\
#page-manager.ytd-app{margin-top:34px}\
  </style>');
/*
ytd-watch-flexy[theater] #player-theater-container.ytd-watch-flexy, ytd-watch-flexy[fullscreen] #player-theater-container.ytd-watch-flexy {height: 480px;}\
*/

  $('ytd-mini-guide-renderer div.ytd-mini-guide-renderer').append('<ytd-mini-guide-entry-renderer class="style-scope ytd-mini-guide-renderer"><!--css-build:shady--><a id="endpoint" role="tab" class="yt-simple-endpoint style-scope ytd-mini-guide-entry-renderer" aria-selected="false" title="В тренде" href="/playlist?list=WL" aria-label="Смотреть позже"><yt-icon id="icon" class="guide-icon style-scope ytd-mini-guide-entry-renderer"><svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" class="style-scope yt-icon" style="pointer-events: none; display: block; width: 100%; height: 100%;"><g class="style-scope yt-icon"><path d="M12 3.67c-4.58 0-8.33 3.75-8.33 8.33s3.75 8.33 8.33 8.33 8.33-3.75 8.33-8.33S16.58 3.67 12 3.67zm3.5 11.83l-4.33-2.67v-5h1.25v4.34l3.75 2.25-.67 1.08z" class="style-scope yt-icon"></path></g></svg><!--css-build:shady--></yt-icon><span class="title style-scope ytd-mini-guide-entry-renderer">Смотреть позже</span><paper-tooltip animation-delay="0" offset="4" position="right" class="style-scope ytd-mini-guide-entry-renderer" role="tooltip" tabindex="-1" hidden="" style="--paper-tooltip-delay-in:0ms;"><!--css-build:shady--><div id="tooltip" class="hidden style-scope paper-tooltip">Смотреть позже</div></paper-tooltip></a></ytd-mini-guide-entry-renderer>');
  //$('#container.ytd-masthead').css('height','34px');
  //$('#page-manager.ytd-app').css('margin-top', '34px');

  //$('#player-theater-container, .html5-video-player').css('width', '854px').css('height', '480px').css('margin', '0 auto');

  // comment autoexpand onmouseover
  $(document).on('mouseover', '.ytd-item-section-renderer .ytd-comment-renderer ytd-expander', function(e) {
    var $this = $(this);
    $this.removeAttr('collapsed');
    $this.parent().find('#more').attr('hidden');
  });

  // video info autoexpand onmouseover
  $(document).on('mouseover', 'ytd-expander.ytd-video-secondary-info-renderer', function(e) {
    var $this = $(this);
    $this.removeAttr('collapsed');
    $this.find('#collapsible').removeAttr('hidden');
    $this.find('#less').removeAttr('hidden');
    $this.find('#more').attr('hidden');
  });

  // set opacity to viewed videos
  $(document).on('scroll', function() {
    $('#progress.ytd-thumbnail-overlay-resume-playback-renderer').parent().parent().parent().parent().css('opacity', '0.5');
  });

  var viewed_videos_interval;
  function viewed_videos_func() {
    var viewed_set = $('.ytd-thumbnail-overlay-resume-playback-renderer')
    if (viewed_set.length > 0) {
      viewed_set.parent().parent().parent().css('opacity', '0.5');
      clearInterval(viewed_videos_interval);
    }
  }

  // add video date to video views title
  var video_date_interval;
  function video_date_func() {
    var date = $('#date.ytd-video-primary-info-renderer yt-formatted-string.ytd-video-primary-info-renderer')
    if (date.length > 0) {
      $('#count.ytd-video-primary-info-renderer yt-view-count-renderer.ytd-video-primary-info-renderer').attr('title', $(date).text());
      clearInterval(video_date_interval);
    }
  }

  function everywhere_init() { // run on all pages
    viewed_videos_interval = setInterval(viewed_videos_func, 2000);
  }

  function on_video_init() { // run on video pages
    video_date_interval = setInterval(video_date_func, 1000);
  }

  function initLocationWatcher () {
    let lastLocation;

    setInterval(() => {
      let currentLocation = window.location.href;

      if (currentLocation !== lastLocation) {
        everywhere_init(); // run on all pages

        if (currentLocation.search(/watch\?v=/) != -1) { // run on video pages
          on_video_init();
        }

        lastLocation = currentLocation;
      }
    }, 1000);
  }
  initLocationWatcher ();
})();