最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Remove ads from embedded youtube video - Stack Overflow

programmeradmin0浏览0评论

So every answers regarding this problem is like:

You cant do it unless you own the video and turn off the adsense yourself.

But i see a possibility.

This is how adblockers works. When i ran chrome inspecter with adblockplus, i saw all the ad script requests blocked,

i want to replicate the same but "in the website itself" using javascript

So that it will automatically block all ads.

Now why i want to do this ? because in my website, i dont want to annoy people with ads

Any solution ?

So every answers regarding this problem is like:

You cant do it unless you own the video and turn off the adsense yourself.

But i see a possibility.

This is how adblockers works. When i ran chrome inspecter with adblockplus, i saw all the ad script requests blocked,

i want to replicate the same but "in the website itself" using javascript

So that it will automatically block all ads.

Now why i want to do this ? because in my website, i dont want to annoy people with ads

Any solution ?

Share Improve this question edited Nov 22, 2018 at 14:37 Linda Lawton - DaImTo 117k38 gold badges220 silver badges496 bronze badges asked Nov 22, 2018 at 14:32 SubrataSubrata 571 gold badge1 silver badge8 bronze badges 3
  • you still cannot for a video embedded in an iframe (unless you own the youtube domain, which i doubt), because you can't control its javascript. If you share other people's content, you share what comes with it.. as simple as that – Kaddath Commented Nov 22, 2018 at 14:35
  • but adblockers does it right ? what am i missing ? – Subrata Commented Nov 22, 2018 at 14:37
  • possibly to hardcode a script that blocks every script received from googleads.g.doubleclick.net........ – Subrata Commented Nov 22, 2018 at 14:39
Add a comment  | 

2 Answers 2

Reset to default 15

Run this in your console.

const clear = (() => {
    const defined = v => v !== null && v !== undefined;
    const timeout = setInterval(() => {
        const ad = [...document.querySelectorAll('.ad-showing')][0];
        if (defined(ad)) {
            const video = document.querySelector('video');
            if (defined(video)) {
                video.currentTime = video.duration;
            }
        }
    }, 500);
    return function() {
        clearTimeout(timeout);
    }
})();
// clear();

The only solution to achieve this -- is to make a browser extension like all adblocker do.

They are able to work because they are injecting javascript into every page and, roughly speaking, act like their javascript was served by YouTube themselves.

发布评论

评论列表(0)

  1. 暂无评论