Support include/exclude in usercss header
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-documentblocks, 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.
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.
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.
xStyle also has an exclude() function (exclude-regexp):
https://github.com/FirefoxBar/xStyle/wiki/Style-format#exclude
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.
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.
Any progess? Really want to exclude urls from code.