Youtube embeds: Remove "More Videos" & ending covering overlays

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

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

  1. // ==UserScript==
  2. // @name Youtube embeds: Remove "More Videos" & ending covering overlays
  3. // @namespace https://greasyfork.org/en/users/221281-klaufir
  4. // @match https://www.youtube.com/embed/*
  5. // @grant none
  6. // @version 1.2
  7. // @author -
  8. // @description 10/27/2021, 12:22:39 AM
  9. // ==/UserScript==
  10.  
  11. function removeElements(elems) {
  12. if (elems)
  13. Array.from(elems).map(e => e.remove());
  14. }
  15.  
  16. function removeElement(elem) {
  17. elem?.remove();
  18. }
  19.  
  20. function retrier(queryFn, onSuccess, tries, retryInterval) {
  21. if (tries <= 0)
  22. return;
  23.  
  24. var queryResult = queryFn()
  25. if (!queryResult || (queryResult?.length ?? -1) == 0) {
  26. setTimeout(function() {retrier(queryFn, onSuccess, tries-1, retryInterval); }, retryInterval);
  27. return;
  28. }
  29. onSuccess(queryResult);
  30. }
  31.  
  32. function getMoreVideosOverlay() {
  33. return document?.querySelector(".ytp-pause-overlay.ytp-scroll-min");
  34. }
  35.  
  36. function getCoveringOverlays() {
  37. return document?.querySelectorAll('.ytp-ce-element');
  38. }
  39.  
  40. retrier(getMoreVideosOverlay,
  41. removeElement,
  42. /* tries: */ 10,
  43. /* retryInterval:*/ 1000);
  44.  
  45. retrier(getCoveringOverlays,
  46. removeElements,
  47. /* tries: */ 10,
  48. /* retryInterval:*/ 1000);