自动跳过 YouTube 广告

几乎立即自动跳过 YouTube 广告。非常轻量且高效。

目前为 2024-07-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Auto Skip YouTube Ads
  3. // @name:vi Tự Động Bỏ Qua Quảng Cáo YouTube
  4. // @name:zh-CN 自动跳过 YouTube 广告
  5. // @name:zh-TW 自動跳過 YouTube 廣告
  6. // @name:ja YouTube 広告を自動スキップ
  7. // @name:ko YouTube 광고 자동 건너뛰기
  8. // @name:es Saltar Automáticamente Anuncios De YouTube
  9. // @name:ru Автоматический Пропуск Рекламы На YouTube
  10. // @name:id Lewati Otomatis Iklan YouTube
  11. // @name:hi YouTube विज्ञापन स्वचालित रूप से छोड़ें
  12. // @name:th ข้ามโฆษณา YouTube อัตโนมัติ
  13. // @namespace https://github.com/tientq64/userscripts
  14. // @version 4.0.1
  15. // @description Automatically skip YouTube ads almost instantly. Very lightweight and efficient.
  16. // @description:vi Tự động bỏ qua quảng cáo YouTube gần như ngay lập tức. Rất nhẹ và hiệu quả.
  17. // @description:zh-CN 几乎立即自动跳过 YouTube 广告。非常轻量且高效。
  18. // @description:zh-TW 幾乎立即自動跳過 YouTube 廣告。非常輕巧且高效。
  19. // @description:ja YouTube 広告をほぼ瞬時に自動的にスキップします。非常に軽量で効率的です。
  20. // @description:ko YouTube 광고를 거의 즉시 자동으로 건너뜁니다. 매우 가볍고 효율적입니다.
  21. // @description:es Omita automáticamente los anuncios de YouTube casi al instante. Muy ligero y eficiente.
  22. // @description:ru Автоматически пропускайте рекламу на YouTube практически мгновенно. Очень легкий и эффективный.
  23. // @description:id Lewati iklan YouTube secara otomatis hampir seketika. Sangat ringan dan efisien.
  24. // @description:hi YouTube विज्ञापनों को लगभग तुरंत ही स्वचालित रूप से छोड़ दें। बहुत हल्का और कुशल।
  25. // @description:th ข้ามโฆษณา YouTube โดยอัตโนมัติเกือบจะในทันที น้ำหนักเบามากและมีประสิทธิภาพ
  26. // @author tientq64
  27. // @icon https://cdn-icons-png.flaticon.com/64/2504/2504965.png
  28. // @match https://www.youtube.com
  29. // @match https://www.youtube.com/*
  30. // @grant none
  31. // @license MIT
  32. // @compatible firefox
  33. // @compatible chrome
  34. // @compatible opera
  35. // @compatible safari
  36. // @compatible edge
  37. // @noframes
  38. // @homepage https://github.com/tientq64/userscripts/tree/main/scripts/auto-skip-youtube-ads
  39. // ==/UserScript==
  40.  
  41. function skipAd() {
  42. setTimeout(skipAd, document.hidden ? 1000 : 500)
  43. const adPlayer = document.querySelector('#movie_player.ad-showing')
  44. if (adPlayer) {
  45. const skipButton = document.querySelector(`
  46. .ytp-skip-ad-button,
  47. .ytp-ad-skip-button,
  48. .ytp-ad-skip-button-modern
  49. `)
  50. if (skipButton) {
  51. skipButton.click()
  52. log('Skip button clicked')
  53. } else {
  54. const adVideo = getVideo()
  55. adVideo.currentTime = 9999
  56. log('Unskippable ad video have been skipped')
  57. }
  58. }
  59. const dismissButton = document.querySelector('tp-yt-paper-dialog #dismiss-button')
  60. if (dismissButton) {
  61. log('Reload the page to bypass the ad blocker warning and the initially paused video')
  62. location.reload()
  63. }
  64. }
  65. function getVideo() {
  66. return document.querySelector('#movie_player video.html5-main-video')
  67. }
  68. function log(text) {
  69. const date = new Date()
  70. console.log(
  71. `\x1B[41;97m Auto Skip YouTube Ads \x1B[m\x1B[47;30m ${date.toLocaleTimeString()} \x1B[m\n${text}`
  72. )
  73. }
  74. skipAd()
  75. const style = document.createElement('style')
  76. style.textContent = `
  77. #player-ads,
  78. #masthead-ad,
  79. #panels:has(ytd-ads-engagement-panel-content-renderer),
  80. ytd-ad-slot-renderer,
  81. ytd-rich-item-renderer:has(.ytd-ad-slot-renderer),
  82. ytd-reel-video-renderer:has(.ytd-ad-slot-renderer),
  83. tp-yt-paper-dialog:has(#dismiss-button) {
  84. display: none !important;
  85. }`
  86. document.head.appendChild(style)
  87. log(`Initialized`)