From 2cec0789b152c673cdc3a21a351508b6a444b92a Mon Sep 17 00:00:00 2001 From: SukkaW Date: Mon, 24 Jul 2023 20:56:43 +0800 Subject: [PATCH] Build reject hosts stats --- Build/build-reject-domainset.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Build/build-reject-domainset.js b/Build/build-reject-domainset.js index 8322331ce..654597980 100644 --- a/Build/build-reject-domainset.js +++ b/Build/build-reject-domainset.js @@ -198,6 +198,9 @@ const domainSuffixSet = new Set(); console.time('* Write reject.conf'); + /** @type {Record} */ + const rejectDomainsStats = {}; + const sorter = (a, b) => { if (a.domain > b.domain) { return 1; @@ -209,7 +212,9 @@ const domainSuffixSet = new Set(); }; const sortedDomainSets = dudupedDominArray .map((v) => { - return { v, domain: getDomain(v.charCodeAt(0) === 46 ? v.slice(1) : v) || v }; + const domain = getDomain(v.charCodeAt(0) === 46 ? v.slice(1) : v) || v; + rejectDomainsStats[domain] = (rejectDomainsStats[domain] || 0) + 1; + return { v, domain }; }) .sort(sorter) .map((i) => i.v); @@ -234,6 +239,14 @@ const domainSuffixSet = new Set(); pathResolve(__dirname, '../List/domainset/reject.conf') ); + await fs.promises.writeFile( + pathResolve(__dirname, '../List/internal/reject-stats.txt'), + Object.entries(rejectDomainsStats) + .sort((a, b) => b[1] - a[1]) + .map(([domain, count]) => `${domain}${' '.repeat(100 - domain.length)}${count}`) + .join('\n') + ); + // Copy reject_sukka.conf for backward compatibility await fse.copy(pathResolve(__dirname, '../Source/domainset/reject_sukka.conf'), pathResolve(__dirname, '../List/domainset/reject_sukka.conf'));