FuckAds - A Youtube pub skipper

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

Tính đến 20-01-2024. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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
})()