Add rule count tracking and formatted comment generation for DNS blocklists

This commit is contained in:
Seth 2025-01-14 21:39:29 -05:00
parent 82bf032c84
commit 39fefd04e0
No known key found for this signature in database
GPG key ID: 8B7A2C60CDF65CAC
2 changed files with 41 additions and 3 deletions

View file

@ -35,9 +35,13 @@ Bun.serve({
rules = rules.concat(listArray)
}
const originalRuleCount = rules.length;
rules = Array.from(new Set(rules));
const rulesText = rules.join('\n');
const ruleCount = originalRuleCount - rules.length;
const rulesText = makeComment(originalRuleCount, ruleCount) + rules.join('\n');
return new Response(rulesText, {
headers: {
@ -49,4 +53,26 @@ Bun.serve({
},
})
}
})
})
const makeComment = (originalRuleCount: number, ruleCount: number) => {
const now = new Date();
const second = now.getSeconds();
const minute = now.getMinutes();
const hour = now.getHours();
const day = now.getDate();
const month = now.getMonth() + 1;
const year = now.getFullYear();
return `[Adblock Plus]
! Title: HaGeZi's DNS Blocklists Combined
! Description: A collection of DNS blocklists by HaGeZi, combined into one list, with duplicates removed.
! Expires: 1 hour
! Last Modified: ${new Date().toUTCString().split(", ")[1]}
! Version: ${year}.${month}.${day}.${hour}.${minute}.${second}
! Syntax: AdBlock
! Number of Entries: ${ruleCount}
! Original Number of Entries: ${originalRuleCount}
! Total Removed Entries: ${originalRuleCount - ruleCount}\n`
}

14
test.ts
View file

@ -156,4 +156,16 @@ const filters = [];
for (const filter of test.filters) {
filters.push(filter.url);
}
console.log(filters);
console.log(filters);
// console.log year.month.day.hour.minute.second in 24 hour format
const now = new Date();
const second = now.getSeconds();
const minute = now.getMinutes();
const hour = now.getHours();
const day = now.getDate();
const month = now.getMonth() + 1;
const year = now.getFullYear();
console.log(`${year}.${month}.${day}.${hour}.${minute}.${second}`);