Smart rules for blacklist

Table of Contents

Userscripts are injected into web pages according to predefined rules. However, the rules do not always satisfy users for different reasons. In such cases, we need blacklist to exclude some web pages for all scripts.

Blacklist use cases

  • hostnames

    In most cases, we may want to add simply hostnames to exclude.

  • @exclude-match rules

    Since match patterns are safer to match URLs, we prefer to use @exclude-match rules to exclude URLs more flexibly.

  • @exclude rules

    They are commonly supported by userscripts, so we should just keep them work.

Blacklist patterns

Taken all use cases into account, the blacklist may have following patterns:

  • hostnames

    A string without slashes, e.g., *

  • match patterns

    A string with scheme, hostname and pathname patterns, e.g. *://*/*,

  • @exclude rules

    A string prefixed with @exclude , e.g. @exclude https://*.

  • comments

    A string starting with #, will be ignored.

Here is a full example for blacklist:

# hostnames

# @exclude-match rules

# @exclude rules

Whitelist patterns

For some people who want to disable Violentmonkey for most websites, a whitelist is needed.

To work as a whitelist, we can use following patterns:

  • @match rules

    A string prefixed with @match , and followed by a match pattern, e.g. @match*.

  • @include rules

    A string prefixed with @include , e.g. @include https://*.

If any of the rules above are matched, the URL bypasses the blacklist. To make it a whitelist, we should block all other URLs by a rule at the end: *.

Here is a full example for whitelist:

# match rules

# include rules

# block everything else

Published at April 15, 2017
Open Chat