Greasy Fork is available in English.

巴哈姆特動畫瘋 - 靜音廣告

muted video ad

// ==UserScript==
// @name         巴哈姆特動畫瘋 - 靜音廣告
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  muted video ad
// @author       Rplus
// @match        https://ani.gamer.com.tw/animeVideo.php?sn=*
// ==/UserScript==

(function() {
  window.addEventListener('load', checkAd);

  let counter = 0;
  let advideo;

  function checkAd() {
    counter += 1;
    advideo = document.querySelector('video[title="Advertisement"]');
    if (advideo) {
      advideo.addEventListener('canplay', muteAd);
      addStyle();
    } else if (counter < 50) {
      setTimeout(checkAd, 100);
    }
  }

  function muteAd() {
    advideo.controls = true;
    advideo.muted = true;
    advideo.volume = .2;
    advideo.removeEventListener('canplay', muteAd);
  }

  function addStyle() {
    let style = document.createElement('style');
    style.textContent = `.video-google-AD iframe, video[title="Advertisement"] + div { pointer-events: none; }`;
    advideo.parentElement.appendChild(style);
  }
})();