YouTube More Videos on Homepage

This script allows you to increase the number of videos displayed in a single row on the YouTube homepage.

  1. // ==UserScript==
  2. // @name YouTube More Videos on Homepage
  3. // @namespace https://github.com/ToLIManl
  4. // @version 0.6
  5. // @description This script allows you to increase the number of videos displayed in a single row on the YouTube homepage.
  6. // @description:ru Этот скрипт позволяет увеличить количество видео, отображаемых в одном ряду на главной странице YouTube
  7. // @description:en This script allows you to increase the number of videos displayed in a single row on the YouTube homepage.
  8. // @author ToLIMan
  9. // @match https://www.youtube.com/
  10. // @match https://www.youtube.com/?*
  11. // @grant none
  12. // @license MIT
  13. // @compatible firefox
  14. // @compatible chrome
  15. // @compatible opera
  16. // @compatible safari
  17. // @compatible edge
  18. // @compatible opera
  19. // @name:ru Больше видео на домашней странице YouTube
  20. // @name:en YouTube More Videos on Homepage
  21. // @run-at document-idle
  22. // ==/UserScript==
  23.  
  24. (function() {
  25. 'use strict';
  26.  
  27. // Определяем язык пользователя
  28. const userLanguage = navigator.language.startsWith('ru') ? 'ru' : 'en';
  29.  
  30. // Локализация
  31. const translations = {
  32. en: {
  33. menuCommand: 'Change number of videos',
  34. promptMessage: 'Enter the number of videos per row (e.g., 6, 8, 10):',
  35. invalidInput: 'Invalid input. Please enter a number.',
  36. successMessage: (count) => `Number of videos per row changed to ${count}. Reload the page.`,
  37. consoleLog: (count) => `Set to ${count} videos per row.`,
  38. },
  39. ru: {
  40. menuCommand: 'Изменить количество видео',
  41. promptMessage: 'Введите количество видео в ряду (например, 6, 8, 10):',
  42. invalidInput: 'Некорректное значение. Введите число.',
  43. successMessage: (count) => `Количество видео в ряду изменено на ${count}. Перезагрузите страницу.`,
  44. consoleLog: (count) => `Установлено ${count} видео в ряду.`,
  45. },
  46. };
  47.  
  48. const t = translations[userLanguage];
  49.  
  50. // Функция для настройки количества видео
  51. function setupVideoCount() {
  52. const currentCount = GM_getValue('videoCount', 6); // По умолчанию 6 видео в ряду
  53. const newCount = prompt(t.promptMessage, currentCount);
  54.  
  55. if (newCount && !isNaN(newCount)) {
  56. GM_setValue('videoCount', parseInt(newCount, 10));
  57. alert(t.successMessage(newCount));
  58. } else {
  59. alert(t.invalidInput);
  60. }
  61. }
  62.  
  63. // Регистрируем команду в меню Tampermonkey
  64. GM_registerMenuCommand(t.menuCommand, setupVideoCount);
  65.  
  66. // Функция для оптимизации главной страницы YouTube
  67. function optimizeYouTube() {
  68. // Проверяем, что мы на главной странице
  69. if (!window.location.pathname.match(/^\/($|feed\/home)/)) return;
  70.  
  71. const grid = document.querySelector('ytd-rich-grid-renderer');
  72. if (grid) {
  73. // Получаем количество видео из настроек
  74. const videoCount = GM_getValue('videoCount', 6);
  75.  
  76. // Устанавливаем количество видео в строке
  77. grid.style.setProperty('--ytd-rich-grid-items-per-row', videoCount, 'important');
  78. grid.style.setProperty('--ytd-rich-grid-item-margin', '8px', 'important');
  79.  
  80. // Ограничиваем количество загруженных видео (чтобы не лагало)
  81. let videos = grid.querySelectorAll('ytd-rich-item-renderer');
  82. if (videos.length > 200) { // Ограничение: максимум 60 видео
  83. for (let i = 200; i < videos.length; i++) {
  84. videos[i].remove();
  85. }
  86. }
  87.  
  88. console.log(t.consoleLog(videoCount));
  89. }
  90. }
  91.  
  92. // Первоначальный запуск
  93. optimizeYouTube();
  94.  
  95. // Наблюдатель за изменениями DOM
  96. const observer = new MutationObserver(() => {
  97. optimizeYouTube();
  98. });
  99.  
  100. observer.observe(document.body, { childList: true, subtree: true });
  101.  
  102. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址