Greasy Fork 还支持 简体中文。

FuckAds - A Youtube pub skipper

Automatically skips YouTube ads and mutes/unmutes video for Firefox (quickly tested) and Opera (extensively tested).

2024-01-20 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         FuckAds - A Youtube pub skipper
// @namespace    http://tampermonkey.net/
// @version      4.7.3
// @description  Automatically skips YouTube ads and mutes/unmutes video for Firefox (quickly tested) and Opera (extensively tested).
// @author       John Doe
// @match        *://www.youtube.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  const player = document.getElementById('movie_player')
  const messageDiv = document.createElement('div')
  document.body.appendChild(messageDiv)
  messageDiv.style.cssText = 'position: fixed; top: 50%; left: 0; background: red; color: white; padding: 10px; z-index: 999;'

  let adSkipped

  function skipAd () {
    const skipButton = document.querySelector('.ytp-ad-skip-button-text')
    if (player && skipButton && adSkipped === false) {
      skipButton.click()
      adSkipped = true
    }
  }

  function startObserving () {
    adSkipped = false
    if (!player) {
      messageDiv.innerText = 'Player not detected'
      return
    }

    const skipButton = document.querySelector('.ytp-ad-skip-button-text')

    if (player.classList.contains('ad-showing')) {
      messageDiv.innerText = 'Player and ad detected'
      player.mute()
      player.style.zIndex = '-999'
      skipAd()
    }

    if (!player.classList.contains('ad-showing')) {
      messageDiv.innerText = 'No ad detected'
      player.unMute()
      player.style.zIndex = '999'
      if (player.getPlayerState() !== 1 && location.href.includes('/watch')) {
        player.seekTo(0)
        player.playVideo()
      }
      adSkipped = true
    }

    if (!skipButton) {
      messageDiv.innerText += ' no skip button available so you need to wait'
    }
  }

  function checkUrlChange () {
    if (location.href.includes('/watch') && !adSkipped) {
      adSkipped = false
      startObserving()
    }
  }

  setInterval(checkUrlChange, 1000) // Continuously check for URL change
  setInterval(startObserving, 1000) // Continuously check for ad
})()