()
| 10 | import { DOMESTICS } from '../Source/non_ip/domestic'; |
| 11 | |
| 12 | export async function parseDomesticList() { |
| 13 | const allChinaDomains = new Set<string>(await parseFelixDnsmasqFromResp(await $$fetch('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf'))); |
| 14 | |
| 15 | const topDomainTrie = await getTopOneMillionDomains(); |
| 16 | |
| 17 | const resultTrie = new HostnameSmolTrie(); |
| 18 | |
| 19 | topDomainTrie.dump((domain) => { |
| 20 | const apexDomain = tldts.getDomain(domain); |
| 21 | |
| 22 | if (apexDomain && allChinaDomains.has(apexDomain)) { |
| 23 | resultTrie.add(apexDomain); |
| 24 | } |
| 25 | }); |
| 26 | |
| 27 | const callback = (domain: string, includeAllSubdomain: boolean) => resultTrie.whitelist(includeAllSubdomain ? '.' + domain : domain); |
| 28 | |
| 29 | // await Promise.all([ |
| 30 | await runAgainstSourceFile( |
| 31 | path.resolve(SOURCE_DIR, 'non_ip/domestic.conf'), |
| 32 | callback |
| 33 | ); |
| 34 | await runAgainstSourceFile( |
| 35 | path.resolve(SOURCE_DIR, 'domainset/reject.conf'), |
| 36 | callback |
| 37 | ); |
| 38 | |
| 39 | Object.values(DOMESTICS).forEach(domestic => { |
| 40 | domestic.domains.forEach(domain => { |
| 41 | switch (domain[0]) { |
| 42 | case '+': |
| 43 | case '$': { |
| 44 | resultTrie.whitelist('.' + domain.slice(1)); |
| 45 | break; |
| 46 | } |
| 47 | default: { |
| 48 | resultTrie.whitelist('.' + domain); |
| 49 | break; |
| 50 | } |
| 51 | } |
| 52 | }); |
| 53 | }); |
| 54 | |
| 55 | // noop, DOMAIN-KEYWORD handing |
| 56 | // for (const d of top5000) { |
| 57 | // if (d.includes(domain)) { |
| 58 | // notIncludedDomestic.delete(d); |
| 59 | // } |
| 60 | // } |
| 61 | // ]); |
| 62 | const dump: string[] = []; |
| 63 | resultTrie.dump((rawDomain, includeSubdomain) => { |
| 64 | const domain = domainToASCII(rawDomain); |
| 65 | if (domain) dump.push(includeSubdomain ? '.' + domain : domain); |
| 66 | }); |
| 67 | dump.sort((a, b) => (a.length - b.length) || (a < b ? -1 : a > b ? 1 : 0)); |
| 68 | |
| 69 | console.log(dump.join('\n') + '\n'); |
no test coverage detected