FuckAds - A Youtube pub skipper

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

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

// ==UserScript==
// @name         FuckAds - A Youtube pub skipper
// @namespace    http://tampermonkey.net/
// @version      3.3.8
// @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 () {
  let adSkipped

  function checkUrlChange () {
    if (location.href.includes('/watch')) {
      console.log('URL includes /watch')
      adSkipped = false
      skipAd()
    }
  }

  function skipAd () {
    if (adSkipped === false) {
      const player = document.getElementById('movie_player')
      const skipButton = document.querySelector('.ytp-ad-skip-button-text')
      if (player && skipButton) {
        skipButton.click()
        console.log('Ad skipped')
      }
      adSkipped = true
      player.style.zIndex = '999'
      player.unMute()
      player.seekTo(0)
      player.playVideo()
    }
  }

  function startObserving () {
    const player = document.getElementById('movie_player')
    if (player && player.classList.contains('ad-showing')) {
      skipAd()
    }
  }
  startObserving()

  function checkPlayerState () {
    const player = document.getElementById('movie_player')
    if (player && player.getPlayerState() !== 1) { // 1 is the state code for playing
      player.playVideo()
    }
  }
  setInterval(checkPlayerState, 5000) // Check player state every 5 seconds

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

QingJ © 2025

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