penge/block-site

Feature request: Support Subdomains

Closed this issue · 3 comments

Hello, this extension is working great, thanks for that, and I was thinking it can be improved even more.

Currently we can only block full URL and domains in general, but option to block (include) subdomains is not available.

Scenario: Let's say I want to block all URLs from one domain, and all subdomains that come from it.
Example URL: "https://onepunchman.fandom.com"
I can only block "fandom.com", and it works fine on that specific site, but it doesn't block any subpages.

  1. It could be improved by implementing wildcards support, like this:
    *.fandom.com
  2. Or when we add "fandom.com", it automatically includes subdomains as well

But i'd prefer option 1, because it gives us the control to choose.

Hi @Zeeex

Thank you for the suggestions. Support for both subdomains and wildcards definitely sounds nice, and I am keen on adding them both. Let's see what would be the best way to approach.

Blocking subdomains

Because wildcard in DNS does not cover root domain, *.fandom.com would block only subdomains, but not fandom.com. To block them both, both would need to be stated:

fandom.com
*.fandom.com

I think this is the control you were referring to. No hidden behaviour as well. To block only subdomains:

*.fandom.com

And to block all subdomains except one:

*.fandom.com
!pokemon.fandom.com

Can we agree this is the behaviour we would want?

Wildcards support

Besides blocking subdomains, wildcard could be used anywhere in the path, to match any directory for example. The following example would block all topics:

fandom.com/topics/*

And similarly, to block all topics except one:

fandom.com/topics/*
!fandom.com/topics/anime

Can we agree this is the behaviour we would want?

Absolutely, both blocking subdomains and wildcard support are fantastic additions! Excellent examples as well.

I'm eagerly anticipating this implementation.

Hi again @Zeeex

I have it implemented. Also added support for matching any one character using ?.

Note:
With the addition of * and ?, blocked sites no longer expand automatically. That means, blocking youtube.com does NOT block any page on youtube.com, but only youtube.com and that's it. To block youtube.com AND any page on it, we would have to write youtube.com/*.
To make it convenient for the user to block the homepage only, he can write either youtube.com or youtube.com/.

Please, feel free to check out #70. The most important file to look at, is find-rule.test.ts, where are all the test scenarios I could think of. It would be nice to double check on that!
I have also added Examples section to README.