Advertisement
geraldandy

Hide top bar on video pages ........... works but takes forever to load

Nov 27th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Hide top bar on video pages ........... works but takes forever to load
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Hides the top bar on YouTube video pages
  6. // @author Your Name
  7. // @match *://www.youtube.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Get the top bar element
  15. var topBar = document.getElementById('masthead-container');
  16.  
  17. // Check if we're on a video page
  18. function checkPage() {
  19. if (window.location.href.indexOf('/watch') > -1) {
  20. // If so, hide the top bar
  21. if (topBar) {
  22. topBar.style.display = 'none';
  23. }
  24. } else {
  25. // If we're not on a video page, show the top bar
  26. if (topBar) {
  27. topBar.style.display = 'block';
  28. }
  29. }
  30. }
  31.  
  32. // Create a MutationObserver to continuously check for changes to the page
  33. var observer = new MutationObserver(function(mutations) {
  34. mutations.forEach(function(mutation) {
  35. if (mutation.type === 'childList') {
  36. checkPage();
  37. }
  38. });
  39. });
  40.  
  41. // Start observing the document for changes
  42. observer.observe(document.body, { childList: true, subtree: true });
  43.  
  44. // Check the page initially
  45. checkPage();
  46. })();
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement