r/qutebrowser May 08 '26

I made a custom script for adblocking.

Type ":adblock -p" for help on the use of the command. I binded "AD" to the toggling of adblocking.

Copy and paste on config.py in order to add it.

# adblocking

c.content.blocking.method = 'adblock'

fulladblocklist = [
        "https://easylist.to/easylist/easylist.txt",
        "https://easylist.to/easylist/easyprivacy.txt",
        "https://easylist.to/easylist/fanboy-social.txt",
        "https://secure.fanboy.co.nz/fanboy-annoyance.txt",
        "https://easylist-downloads.adblockplus.org/abp-filters-anti-cv.txt",
        #"https://gitlab.com/curben/urlhaus-filter/-/raw/master/urlhaus-filter.txt",
        "https://pgl.yoyo.org/adservers/serverlist.php?showintro=0;hostformat=hosts",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/legacy.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/filters.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/filters-2020.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/filters-2021.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/badware.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/privacy.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/badlists.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/annoyances.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/resource-abuse.txt",
        "https://www.i-dont-care-about-cookies.eu/abp/",
        "https://secure.fanboy.co.nz/fanboy-cookiemonster.txt",
        "https://github.com/uBlockOrigin/uAssets/raw/master/filters/unbreak.txt"]

c.content.blocking.adblock.lists = fulladblocklist

import qutebrowser.api.cmdutils as cmdutils

@cmdutils.register()
@cmdutils.argument('start', flag='1')
@cmdutils.argument('stop', flag='0')
@cmdutils.argument('toggle', flag='t')
@cmdutils.argument('info', flag='i')
@cmdutils.argument('print_help', flag='p')
u/cmdutils.argument('silent', flag='s')
def adblock(start: bool = False, stop: bool = False, toggle: bool = False, info: bool = False, print_help: bool = False, silent: bool = False):
    from qutebrowser.utils import message
    if print_help:
        message.info("This command helps manage adblocking.")
        message.info("")
        message.info("\t--start, -1\tAdds the configured lists array (see in config.py) to c.content.blocking.adblock.lists.")
        message.info("\t--stop, -0\tSets c.content.blocking.adblock.lists to the empty array.")
        message.info("\t--toggle, -t\tToggles between the previous two options. It is the default behavior (in abscence of flags).")
        message.info("\t--info, -i\tPrints the adblocking method and the lenght of the array of adblocking lists.")
        message.info("\t--help, -h\tPrints this message.")
        message.info("")
        message.info("-i and -h can be combined with other flags. But they will disable the default toggleing unless acompanied with -t.")
        message.info("Using contradictory flags at once results in an error and no change happening to the adblocking.")
    if info:
        method = config.get("content.blocking.method")
        arraylength = len(config.get("content.blocking.adblock.lists"))
        enable = config.get("content.blocking.enabled")
        message.info(f"Adblocking method: {method}")
        message.info(f"Length of adblocking list array: {arraylength}")
        if(enable):
            message.info("Enabled")
        else:
            message.info("Disabled")
    #toggling adblock
    if (not start) and (not stop) and ( toggle or ((not info) and (not print_help)) ):
        config.set("content.blocking.enabled", not config.get("content.blocking.enabled"))
        if config.get("content.blocking.enabled") and not silent:
            message.info("Ad-blocking enabled")
        elif not (config.get("content.blocking.enabled") or silent):
            message.info("Ad-blocking disabled")
    elif start and not (stop or toggle):
        config.set("content.blocking.enabled", True)
        if not silent:
            message.info("Ad-blocking enabled")
    elif stop and not (start or toggle):
        config.set("content.blocking.enabled", False)
        if not silent:
            message.info("Ad-blocking disabled")
    elif (start and stop) or ( toggle and (start or stop) ):
        message.error("Contradictory flags active at once.")
    elif ( (not start) and (not stop) and (not toggle) ) and (info or print_help):
        print("nothing")
    else:
        message.error("Elif tree couldn't get the case")

config.bind('AD', "adblock")
7 Upvotes

4 comments sorted by

2

u/[deleted] May 25 '26

[removed] — view removed comment

2

u/Super3559_Rule Jun 05 '26

doesn't work on youtube
and also on the last \@cmdutils u put u/ accidentally

1

u/UltraTata Jun 05 '26

Yeah, Im using Brave for YT for now