FuckAds - A Youtube pub skipper

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

当前为 2024-01-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         FuckAds - A Youtube pub skipper
// @namespace    http://tampermonkey.net/
// @version      3.3.1
// @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 () {
  console.log('fuckads')
  let adSkipped
  const messageDiv = document.createElement('div')

  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
      messageDiv.style.zIndex = '-999'
      player.unMute()
      player.style.zIndex = '999'
      player.seekTo(0)
      player.playVideo()
    }
  }

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

  function checkPlayerState () {
    const player = document.getElementById('movie_player')
    if (player && player.getPlayerState() !== 1) { // 1 is the state code for playing
      location.reload() // Reload the page if the player is not playing
    }
  }

  setInterval(checkPlayerState, 5000) // Check player state every 5 seconds

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

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