diff --git a/src/generators/index.ts b/src/generators/index.ts index c632679..010ddcd 100644 --- a/src/generators/index.ts +++ b/src/generators/index.ts @@ -86,17 +86,9 @@ export const generateMatchHeaders = async ( const match = matches.find(m => m.includes("domain")) || "https://domain/*"; - const sites = await networkSiteScraper(); - - if (matches.includes("meta")) { - const metaSites = sites.flatMap(({ site, ...rest }) => { - return collapse && (site.includes("stackexchange") || site.includes("stackapps")) - ? [] - : [{ ...rest, site: site.replace(/^(.+?\.(?=.+\.)|)/, "$1meta.") }]; - }); - - sites.push(...metaSites); - } + const sites = (await networkSiteScraper()) + // only inclue meta sites if requested + .filter(({ isMeta }) => matches.includes("meta") || !isMeta); const all = sites.map(({ site }) => { const domain diff --git a/src/utils/scraper.ts b/src/utils/scraper.ts index b876418..52ae4f5 100644 --- a/src/utils/scraper.ts +++ b/src/utils/scraper.ts @@ -2,11 +2,13 @@ export interface NetworkSiteInfo { icon: string; site: string; name: string; + isMeta: boolean; } interface ApiItems { icon_url: string; site_url: string; + site_type: "main_site" | "meta_site"; name: string; } @@ -23,7 +25,7 @@ export const scrapeNetworkSites = async () => { const url = new URL("https://api.stackexchange.com/2.3/sites"); url.searchParams.set("key", "52HhpSRv*u6t*)tOFwEIHw(("); url.searchParams.set("pagesize", "100"); - url.searchParams.set("filter", "!SldCuNUOe7I(DQo2T0"); + url.searchParams.set("filter", "!SldCsaEs0vkmNDgMK_"); const siteInfo: NetworkSiteInfo[] = []; @@ -42,11 +44,12 @@ export const scrapeNetworkSites = async () => { } items - .forEach(({ icon_url: icon, site_url: site, name }) => { + .forEach(({ icon_url: icon, site_url: site, name, site_type: siteType }) => { siteInfo.push({ icon, site: site.replace(/^https?:\/\//, "").replace(/\/$/, ""), name, + isMeta: siteType === "meta_site" }); }); diff --git a/test/common.spec.ts b/test/common.spec.ts index 79351dd..6e460ad 100644 --- a/test/common.spec.ts +++ b/test/common.spec.ts @@ -121,6 +121,26 @@ describe("common", () => { expect(matches).length.to.be.greaterThan(1); }); + it('"match" with "all meta" should expand to all meta sites', async () => { + const headers = await generateMatchHeaders( + ["all", "meta", "https://domain/questions/*"], + (async () => [ + { site: "stackoverflow.com" }, + { site: "chess.stackexchange.com" }, + { site: "meta.stackexchange.com" }, + { site: "pt.meta.stackoverflow.com" } + ]) as typeof scrapeNetworkSites + ); + + const matches = headers.map(([, m]) => m); + expect(matches).to.include("https://*.stackexchange.com/questions/*"); + + expect(matches).to.not.include("https://pt.meta.meta.stackoverflow.com/questions/*"); + expect(matches).to.include("https://pt.meta.stackoverflow.com/questions/*"); + + expect(matches.length).to.equal(3); + }); + it('@require headers should be generated', async () => { const content = await generate("tampermonkey", { ...directCommon,