Greasy Fork

Greasy Fork is available in English.

动画疯跳过广告和年龄确认

巴哈姆特动画疯跳过广告和年龄确认

当前为 2025-04-05 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         动画疯跳过广告和年龄确认
// @namespace    Schwi
// @version      0.1
// @description  巴哈姆特动画疯跳过广告和年龄确认
// @author       Schwi
// @match        https://ani.gamer.com.tw/animeVideo.php?sn=*
// @icon         https://i2.bahamut.com.tw/favicon.svg
// @grant        none
// @noframes
// @supportURL   https://github.com/cyb233/script
// @license      GPL-3.0
// ==/UserScript==

(function () {
  'use strict';

  let accSkipped = false;
  let adSkipped = false;
  let userMuted = null;
  let adMuted = false;

  const skipAgreement = () => {
    const accAgreement = document.querySelector('#adult');
    if (accAgreement) {
      console.log('跳过年龄确认');
      accAgreement.click();
      accSkipped = true;
    }
  };

  const skipAd = (video) => {
    const adSkipButton = document.querySelector('#adSkipButton.vast-skip-button');
    if (adSkipButton) {
      if (adSkipButton.classList.contains('enable')) {
        console.log('跳过广告');
        adSkipButton.click();
        adSkipped = true;
      } else if (!adMuted) {
        console.debug('广告未跳过,静音广告');
        video.muted = true;
        adMuted = true;
      }
    }
  };

  const restoreMuteStatus = (video) => {
    if (userMuted !== null) {
      console.log('恢复用户静音状态');
      video.muted = !!userMuted;
      userMuted = null;
      adSkipped = false;
      adMuted = false;
    }
  };

  const interval = setInterval(() => {
    const video = document.querySelector('#ani_video_html5_api');
    if (!video) {
      console.debug('未找到视频元素');
      return;
    }

    if (userMuted === null) {
      console.debug('记录用户初始静音状态:', video.muted);
      userMuted = video.muted;
    }

    if (!accSkipped) {
      skipAgreement();
    }

    skipAd(video);

    if (adSkipped) {
      restoreMuteStatus(video);
    }

    if (accSkipped) {
      console.debug('年龄确认已跳过,持续检测广告');
      // 不清理定时器,持续检测广告
    }
  }, 1000);
})();