YOUTUBE: hide low views videos (less than 100k views) (customizable)

hide videos less than 100k views

  1. // ==UserScript==
  2. // @name YOUTUBE: hide low views videos (less than 100k views) (customizable)
  3. // @namespace https://github.com/KenKaneki73985
  4. // @license MIT
  5. // @match https://www.youtube.com/feed/subscriptions
  6. // @match https://www.youtube.com
  7. // @description hide videos less than 100k views
  8. // @version 0.0.1.20250307132736
  9. // ==/UserScript==
  10. // user_script = "moz-extension://762e4395-b145-4620-8dd9-31bf09e052de/options.html#nav=e203b9b5-3a24-4566-b0e8-3d6bbb72aed0+editor"
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to hide low view videos
  16. function HIDE_LOW_VIEW_VIDEOS() {
  17. // Find all elements with the specified class
  18. const viewsElements = document.querySelectorAll('.inline-metadata-item');
  19. // Filter elements that contain the word "views"
  20. const viewElements = Array.from(viewsElements).filter(el => el.textContent.includes('views'));
  21.  
  22. // Filter for elements with less than 100K views
  23. const lowViewElements = viewElements.filter(el => {
  24. // Extract the numeric part
  25. const viewText = el.textContent.replace(' views', '');
  26. // Check if the element contains 'K'
  27. if (el.textContent.includes('K')) {
  28. // Extract the number before 'K'
  29. const viewCount = parseFloat(viewText.split('K')[0]);
  30. // Return true if views are less than 100
  31. return viewCount < 100;
  32. // return viewCount < 500;
  33. }
  34. // If no 'K', it means less than 1000 views
  35. // Parse the number directly
  36. const viewCount = parseInt(viewText.replace(/,/g, ''), 10);
  37. // Return true if views are less than 1000
  38. return viewCount < 1000;
  39. });
  40.  
  41. // Hide the low view count elements
  42. if (lowViewElements.length > 0) {
  43. lowViewElements.forEach(el => {
  44. // Find the closest ancestor "ytd-rich-item-renderer"
  45. const videoItem = el.closest('ytd-rich-item-renderer');
  46. // If the video item is found, hide it
  47. if (videoItem) {
  48. videoItem.style.display = 'none';
  49. }
  50. });
  51. }
  52. }
  53.  
  54. // Run on initial page load
  55. HIDE_LOW_VIEW_VIDEOS();
  56.  
  57. // Run on Alt+H key press
  58. document.addEventListener('keydown', function(event) {
  59. if (event.altKey && event.key === 'h') {
  60. HIDE_LOW_VIEW_VIDEOS();
  61. }
  62. });
  63.  
  64. // Observe scroll and dynamically loaded content
  65. const observerOptions = {
  66. childList: true,
  67. subtree: true
  68. };
  69.  
  70. const observer = new MutationObserver((mutations) => {
  71. // Check if new videos have been added
  72. const newVideos = mutations.some(mutation =>
  73. mutation.type === 'childList' &&
  74. mutation.addedNodes.length > 0
  75. );
  76.  
  77. if (newVideos) {
  78. // Small delay to ensure new content is fully rendered
  79. setTimeout(HIDE_LOW_VIEW_VIDEOS, 100);
  80. }
  81. });
  82.  
  83. // Start observing the page for changes
  84. const targetNode = document.body;
  85. observer.observe(targetNode, observerOptions);
  86. })();