stylus icon indicating copy to clipboard operation
stylus copied to clipboard

Support include/exclude in usercss header

Open silverwind opened this issue 7 years ago • 16 comments

Initially posted at https://github.com/StylishThemes/parse-usercss/issues/7, moving it here because it's also a concern for Stylus' user interface.

I'd propose new include and exclude directives in the usercss header which support glob-based and regexp-based rules, very similar to Greasemonkey's rules.

The benefits of this include:

  • A style remains a single text file which can easily copy-pasted without having to rely on specially parsed @-moz-document blocks, which are not understood by browsers.
  • Exclude patterns will be easily realized without requiring knowledge about negative regexes.
  • With regexes being in comment form, they can be standard JS regex without CSS escaping rules.

There are a few drawbacks as well:

  • A single style can no longer include multiple blocks of CSS that apply to rules specific to each block. One could also see this as a benefit because it makes styles as a whole more readable.
  • Nesting of blocks with specific rules will no longer be possible. I've yet to see a style which uses this, this is usally better solved through selectors.

The transition to this format could be done smoothly by creating wrapper "documents sections" if a style is found to have these directives.

silverwind avatar Feb 12 '18 13:02 silverwind

That was the initial implementation (it also allowed multiple blocks via separate CSS comments with @include and @exclude) and I've decided it makes much less sense than maintaining general compatibility with the existing userstyle format. I still think so. I'm against this proposal.

tophf avatar Feb 13 '18 00:02 tophf

If we decide to deviate from the ancient Mozilla's @-moz-document specification, which might be a good idea since that spec won't get approved anytime soon if ever, I think it might be better to introduce exclude-domain(), exclude-url(), exclude-url-prefix(), exclude-regexp() CSS functions similar to the existing ones.

tophf avatar Mar 19 '18 01:03 tophf

xStyle also has an exclude() function (exclude-regexp): https://github.com/FirefoxBar/xStyle/wiki/Style-format#exclude

eight04 avatar Sep 28 '18 04:09 eight04

In the future, we may want to implement some directives to be compatible with Firemonkey. More information: https://github.com/JasonBarnabe/greasyfork/issues/656

Their directives match the userScripts API:

@match // alias of matches
@matches
@excludeMatches
@includeGlobs
@excludeGlobs

The only problem is that Firemonkey only supports single section style. I think we can wait a while and see if Firemonkey will improve their spec to support multi-sections style or just stay with the current syntax.

eight04 avatar Mar 17 '20 10:03 eight04

Multi-sections would be my preference. It would not support nesting like @-moz-document does but I guess no one really needs that feature anyways.

/* ==UserStyle==
@name        Style
@version     1.0.0
@match       https://example.com
==/UserStyle== */

.div {
  color: red;
}

/* ==UserStyle==
@match       https://another.com
==/UserStyle== */

.div {
  color: blue;
}

The first header should support all directives, subsequent ones could be limited to just the matching-related ones.

silverwind avatar Mar 17 '20 11:03 silverwind

Any progess? Really want to exclude urls from code.

wenfangdu avatar Mar 22 '24 14:03 wenfangdu