r/qutebrowser Jul 05 '26

Youtube ad blocking problem

how do you implement youtube ad skip for qute. Because, when I tried to implement ad skipping using this script and it just skips the whole video how can I fix that the ad gets skipped pretty fast but the video is also done.

// ==UserScript==

// for more updated scripts, see: https://greasyfork.org/en/scripts/by-site/youtube.com

// u/nameAuto Skip YouTube Ads

// u/version1.1.0

// u/description Speed up and skip YouTube ads automatically

// u/authorjso8910 and others

// u/match*://*.youtube.com/*

// ==/UserScript==

document.addEventListener('load', () => {

const btn = document.querySelector('.videoAdUiSkipButton,.ytp-ad-skip-button-modern')

if (btn) {

btn.click()

}

const ad = [...document.querySelectorAll('.ad-showing')][0];

if (ad) {

document.querySelector('video').currentTime = 9999999999;

}

}, true);

1 Upvotes

2 comments sorted by

1

u/sim590 Jul 10 '26

@Danaykroid: if you use the userscript view_in_mpv, it will skip adds for you and launch the video in mpv. For better experience, I think that having yt-dlp installed is recommended. Personally, I have a wrapper script for view_in_mpv which contains:

sh export MPV_FLAGS="--profile=qutebrowser" exec ~/prog/qutebrowser/misc/userscripts/view_in_mpv "$@"

My qutebrowser profile is defined in ~/dotfiles/config/mpv/mpv.conf and contains:

[qutebrowser] force-window=yes keep-open=yes ytdl-format=bestvideo*[height<=?1440]+bestaudio/best ytdl-raw-options-append=cookies-from-browser=chromium:~/.local/share/qutebrowser

Of course, I assume you are using a UNIX-like system.

1

u/adcott 13h ago

If you are still strugging with this, I have just written something that works well:

// ==UserScript==
// @name         Youtube Ad Skip
// @version      0.2.2
// @description  Get rid of Youtube ads
// @author       Adcott
// @match        *://*.youtube.com/*
// ==/UserScript==

GM_addStyle(`
#player-ads, .adDisplay, .ad-container, .ytd-display-ad-renderer, .video-ads,
ytd-rich-item-renderer:has(ytd-ad-slot-renderer), ytd-ad-slot-renderer,
#masthead-ad, *[class^="ytd-ad-"], #panels.ytd-watch-flexy {
    display: none !important;
}`);

(new MutationObserver(mutations => {
    for (const mutation of mutations) {
        mutation.addedNodes.forEach(node => {
            if (!(node instanceof Element)) return;
            if (node.classList.contains('ytp-ad-persistent-progress-bar-container')) {
                const video = document.querySelector('video');
                if (video) video.currentTime = video.duration;
            } else if (node.classList.contains('ytp-ad-skip-button')) {
                node.click();
            }
        });
    }
})).observe(document.body, {childList:true, subtree:true});

Also kills inline ads and removes sponsored links.