When writing user scripts, one needs to insert @include / @match directives at the start of the script so that the script knows on which sites it should execute.

Naturally, people sometimes write scripts that are meant to work on every Q&A site on the Stack Exchange network. For that, they need to include directives that match every single site (and exclude special domains that aren’t Q&A sites). When I ran into this problem, I found myself performing a whack-a-mole of tweaking rules every now and then as I encounter different domains that aren’t matched as they should be.

I’m mostly interested in the Q&A sites, i.e. those based on normal voted question-and-answer mechanics, as those are the hardest to provide rules for; the chat, for example, is only a single domain, chat.stackexchange.com, while whether the meta sites or Area 51 are included should be easy to tweak afterwards.

Is there a definitive, future-proof list of matching rules somewhere that won’t have to be tweaked too often?

  • Related: The single source of truth for the site list is How can I get URLs and site names for a cross-site SEDE query? Mar 30 at 16:13
  • As written, this is unclear. You're asking for "definitive list" of "every site on the Stack Exchange network". Because you're asking for code, which requires exactly specified criteria, and not a full list of existing sites, it's unclear from your question what exactly you want. What list is used for matching URLs in a userscript depends on which sites, or types of sites, that script has been written to operate, which may be any of a variety of sites on the network. Ultimately, there really isn't a "definitive list" of match patterns, without more clearly specifying what you want.
    – Makyen
    Apr 4 at 20:31
  • 3
    While not all encompassing, the considerations which are not specified in your question include: A) only main SE Q&A sites? B) including child meta sites? C) including Chat sites? D) include Area51 (has substantially different layout and software, so largely incompatible for userscripts)? F) include SO Teams? G) include various other SE/SO domains (e.g. API, OpenID, SEDE, advertising, company, jobs, talent, teams info, tour, etc.)? Basically, there is no way to have a "definitive" list without at least specifying exactly what you actually want to match and what you don't want to match.
    – Makyen
    Apr 4 at 20:32
  • @Makyen Ideally, the answer is ‘all of them’ (i.e. have universal classification rules from which I can pick and choose which kinds of sites I want to cover), but the most important is the main Q&A sites. I addressed that in the edit. Apr 5 at 7:01

I currently use this to match all the Q&A sites in the network:

// @match    https://*.stackexchange.com/*
// @match    https://*.superuser.com/*
// @match    https://*.stackoverflow.com/*
// @match    https://*.mathoverflow.net/*
// @match    https://*.serverfault.com/*
// @match    https://*.askubuntu.com/*
// @match    https://stackapps.com/*
// @exclude  https://chat.stackexchange.com/*
// @exclude  https://api.stackexchange.com/*
// @exclude  https://data.stackexchange.com/*
// @exclude  https://openid.stackexchange.com/*
// @exclude  https://area51.stackexchange.com/*
// @exclude  https://stackexchange.com/*
// @exclude  https://contests.stackoverflow.com/*
// @exclude  /^https?:\/\/winterbash\d{4,}\.stackexchange\.com\//
  • What are you matching against? Where does that information come from? Some scraped page? Or from somewhere else? Mar 30 at 16:16
  • openid.stackexchange.com is not a Q&A site. How did it enter the picture? Mar 30 at 16:18
  • It will also match the meta sites. Is that intentional? Mar 30 at 16:22
  • Yes. The rationale is that the meta sites work on the same Q&A mechanics as every other site. Mar 30 at 16:23
  • @P.Mort.-forgotClayShirky_q The openid. domain is listed as excluded, for the reason you mention. Mar 30 at 16:24
  • https://*.stackoverflow.com/* (for example) also matches https://stackoverflow.com/; and https://*.stackexchange.com/* matches e.g. https://writing.meta.stackexchange.com/, right? Other than that, I’ve just confirmed that all sites on /sites are matched by these patterns. And Meta sites should also be covered with the special case of https://stackapps.com/ which doesn’t have one. Mar 30 at 16:25
  • But where did openid.stackexchange.com come from? Mar 30 at 16:25
  • @P.Mort.-forgotClayShirky_q It's a valid subdomain not related to Q&A so why does it matter where it came from?
    – charlietfl
    Apr 4 at 13:20
  • @P.Mort.-forgotClayShirky_q in the past Stack Exchange used to offer OpenID service, so that was the domain used for it. That's not relevant anymore since they closed it down 2.5 years ago, so I think this line can indeed be safely removed from any script. It's pointless. Apr 5 at 6:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .