FuckAds - A Youtube pub skipper

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

目前为 2024-01-20 提交的版本。查看 最新版本

// ==UserScript==
// @name         FuckAds - A Youtube pub skipper
// @namespace    http://tampermonkey.net/
// @version      4.6
// @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 skipButton = document.querySelector('.ytp-ad-skip-button-text')

  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 = false

  function skipAd () {
    player.style.zIndex = '-999'
    player.mute()
    adSkipped = false

    if (player && skipButton && !adSkipped) {
      skipButton.click()
      adSkipped = true
      player.unMute()
      player.style.zIndex = '999'
      player.seekTo(0)
      player.playVideo()
    }
  }

  function startObserving () {
    const player = document.getElementById('movie_player')
    if (!player) {
      messageDiv.style.zIndex = '999'
      messageDiv.innerText = 'player not detected'
    }
    if (player && player.classList.contains('ad-showing')) {
      messageDiv.style.zIndex = '999'
      messageDiv.innerText = 'player and ad detected'
      player.style.zIndex = '-999'
      player.mute()
      skipAd()
    }
    if (!skipButton) {
      messageDiv.style.zIndex = '999'
      messageDiv.innerText += ' no skip button available, you need to wait'
    }
    if (!player.classList.contains('ad-showing')) {
      player.style.zIndex = '999'
      messageDiv.innerText = 'no ad detected'
      player.unMute()
      if (player.getPlayerState() !== 1 && location.url.includes('/watch') && !adSkipped) {
        player.seekTo(0)
        player.playVideo()
      }
    }
  }

  // Function to check for URL change and reset adSkipped flag
  function checkUrlChange () {
    if (location.href.includes('/watch') && !adSkipped) {
      startObserving()
    }
  }

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

QingJ © 2025

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