Greasy Fork镜像 支持简体中文。

Auto Skip YouTube Ads

Auto skip YouTube ads instantly. Very lightweight and efficient.

目前為 2024-06-21 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Auto Skip YouTube Ads
  3. // @name:vi Tự Động Bỏ Qua Quảng Cáo YouTube
  4. // @namespace https://github.com/tientq64/userscripts
  5. // @version 2.1.3
  6. // @description Auto skip YouTube ads instantly. Very lightweight and efficient.
  7. // @description:vi Tự động bỏ qua quảng cáo YouTube ngay lập tức. Rất nhẹ và hiệu quả.
  8. // @author https://github.com/tientq64
  9. // @icon https://cdn-icons-png.flaticon.com/64/9639/9639954.png
  10. // @match https://www.youtube.com/*
  11. // @grant none
  12. // @license MIT
  13. // @noframes
  14. // @homepage https://github.com/tientq64/userscripts/tree/main/scripts/auto-skip-youtube-ads
  15. // ==/UserScript==
  16.  
  17. function skipAd() {
  18. const hasAd = player.classList.contains('ad-showing')
  19. if (hasAd) {
  20. const skipButton = document.querySelector('.ytp-skip-ad-button, .ytp-ad-skip-button')
  21. if (skipButton) {
  22. skipButton.click()
  23. } else {
  24. const video = player.querySelector('video')
  25. video.currentTime = video.duration
  26. }
  27. }
  28. if (popupContainer) {
  29. const dismissButton = popupContainer.querySelector('tp-yt-paper-dialog #dismiss-button')
  30. if (dismissButton) {
  31. dismissButton.click()
  32. const dialog = dismissButton.closest('tp-yt-paper-dialog')
  33. dialog.remove()
  34. }
  35. }
  36. }
  37. const player = document.querySelector('.html5-video-player')
  38. let popupContainer
  39. if (window.MutationObserver) {
  40. const adObserver = new MutationObserver(skipAd)
  41. adObserver.observe(player, { attributeFilter: ['class'] })
  42. } else {
  43. setInterval(skipAd, 1000)
  44. }
  45. skipAd()
  46. const intervalId = setInterval(tryFindPopupContainer, 100)
  47. function tryFindPopupContainer() {
  48. popupContainer = document.querySelector('ytd-popup-container')
  49. if (!popupContainer) return
  50. clearInterval(intervalId)
  51. if (window.MutationObserver) {
  52. const warningObserver = new MutationObserver(skipAd)
  53. warningObserver.observe(popupContainer, { childList: true })
  54. }
  55. skipAd()
  56. }
  57. const style = document.createElement('style')
  58. style.textContent = `
  59. #player-ads,
  60. #masthead-ad,
  61. ytd-rich-item-renderer:has(.ytd-ad-slot-renderer),
  62. ytd-reel-video-renderer:has(.ytd-ad-slot-renderer),
  63. tp-yt-paper-dialog:has(#dismiss-button) {
  64. display: none !important;
  65. }`
  66. document.head.appendChild(style)

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址