Youtube: Remove Overlays

10/27/2021, 12:22:39 AM

目前为 2021-10-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube: Remove Overlays
  3. // @namespace https://greasyfork.org/en/users/221281-klaufir
  4. // @match https://www.youtube.com/embed/*
  5. // @match https://www.youtube.com/watch?v=*
  6. // @grant none
  7. // @version 1.4
  8. // @author -
  9. // @description 10/27/2021, 12:22:39 AM
  10. // ==/UserScript==
  11.  
  12. function removeElements(elems) {
  13. if (elems)
  14. Array.from(elems).map(e => e.remove());
  15. }
  16.  
  17. function removeElement(elem) {
  18. elem?.remove();
  19. }
  20.  
  21. function retrier(queryFn, onSuccess, tries, retryInterval) {
  22. if (tries <= 0)
  23. return;
  24.  
  25. var queryResult = queryFn()
  26. if (!queryResult || (queryResult?.length ?? -1) == 0) {
  27. setTimeout(function() {retrier(queryFn, onSuccess, tries-1, retryInterval); }, retryInterval);
  28. return;
  29. }
  30. onSuccess(queryResult);
  31. }
  32.  
  33.  
  34. // Remove "More Videos" overlay on paused embeds
  35. function getMoreVideosOverlay() {
  36. return document?.querySelector(".ytp-pause-overlay.ytp-scroll-min");
  37. }
  38. retrier(getMoreVideosOverlay,
  39. removeElement,
  40. /* tries: */ 10,
  41. /* retryInterval:*/ 1000);
  42.  
  43. // Remove covering overlays at the end of the video
  44. function getCoveringOverlays() {
  45. return document?.querySelectorAll('.ytp-ce-element');
  46. }
  47. retrier(getCoveringOverlays,
  48. removeElements,
  49. /* tries: */ 10,
  50. /* retryInterval:*/ 1000);
  51.  
  52. // Remove paid promotion notification overlay in the bottom left corner
  53. function getPaidPromotionsOverlay() {
  54. return document?.querySelector('.ytp-paid-content-overlay-text');
  55. }
  56. retrier(getPaidPromotionsOverlay,
  57. removeElement,
  58. /* tries: */ 10,
  59. /* retryInterval:*/ 1000);
  60.  
  61.  
  62. // Remove info cards in the top right corner
  63. function getCardsTeaser() {
  64. return document?.querySelector('.ytp-cards-teaser');
  65. }
  66. retrier(getCardsTeaser,
  67. removeElement,
  68. /* tries: */ 10,
  69. /* retryInterval:*/ 1000);
  70.  
  71.  
  72. // Remove branding overlay in the bottom right corner
  73. function getBranding() {
  74. return document?.querySelector('.iv-branding');
  75. }
  76. retrier(getBranding,
  77. removeElement,
  78. /* tries: */ 10,
  79. /* retryInterval:*/ 1000);
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.