防止某些网站上的广告声音

时间:2017-10-19 05:30:12

标签: javascript audio

我尝试使用此代码在StackExchange中找到here,以防止在某些网站上播放广告。

Array.prototype.slice.call(document.querySelectorAll('audio')).forEach((audio)=>{
    audio.muted = true;
});

我用这种方式实现了代码:

// ==UserScript==
// @name        addicto
// @namespace   nms
// @include     http://*
// @include     https://*
// @version     1
// @grant       none
// ==/UserScript==

addEventListener('DOMContentLoaded', ()=>{
  let sites = ['mako.co.il'];
  let href = window.location.href;
  for (let i = 0; i < sites.length; i++) {
    if (href.includes(sites[i])) {
      Array.prototype.slice.call(document.querySelectorAll('audio')).forEach((audio)=>{
        audio.muted = true;
      });
    }
  }

  // If href includes the value of the iteration on the "sites" array, do stuff.
});

这不起作用,我仍然听到来自网站的声音(mako.co.il)。也许这是因为当声音来自广告脚本时,代码不起作用?

如果是这样,也许一个不错的解决方案是在所需网站上禁用我脚本旁边的任何其他脚本?或者别的什么?

0 个答案:

没有答案
相关问题