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.5
  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. // Remove "More Videos" overlay on paused embeds
  34. function getMoreVideosOverlay() {
  35. return document?.querySelector(".ytp-pause-overlay.ytp-scroll-min");
  36. }
  37. retrier(getMoreVideosOverlay,
  38. removeElement,
  39. /* tries: */ 10,
  40. /* retryInterval:*/ 1000);
  41.  
  42. // Remove covering overlays at the end of the video
  43. function getCoveringOverlays() {
  44. return document?.querySelectorAll('.ytp-ce-element');
  45. }
  46. retrier(getCoveringOverlays,
  47. removeElements,
  48. /* tries: */ 10,
  49. /* retryInterval:*/ 1000);
  50.  
  51. // Remove paid promotion notification overlay in the bottom left corner
  52. function getPaidPromotionsOverlay() {
  53. return document?.querySelector('.ytp-paid-content-overlay-text');
  54. }
  55. retrier(getPaidPromotionsOverlay,
  56. removeElement,
  57. /* tries: */ 10,
  58. /* retryInterval:*/ 1000);
  59.  
  60.  
  61. // Remove info cards in the top right corner
  62. function getCardsTeaser() {
  63. return document?.querySelector('.ytp-cards-teaser');
  64. }
  65. retrier(getCardsTeaser,
  66. removeElement,
  67. /* tries: */ 10,
  68. /* retryInterval:*/ 1000);
  69.  
  70.  
  71. // Remove branding overlay in the bottom right corner
  72. function getBranding() {
  73. return document?.querySelector('.iv-branding');
  74. }
  75. retrier(getBranding,
  76. removeElement,
  77. /* tries: */ 240,
  78. /* retryInterval:*/ 1000);