Skip to content

Commit

Permalink
Update create-everything-list.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gap579137 authored Sep 20, 2024
1 parent 5ee4aeb commit ae696a5
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions scripts/create-everything-list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs").promises;
const path = require("path");
const fs = require("node:fs").promises;
const path = require("node:path");

const listsToIncludeInEverythingList = [
"abuse",
Expand Down Expand Up @@ -29,29 +29,35 @@ const listsToIncludeInEverythingList = [
];

(async () => {
const files = (await fs.readdir(path.join(__dirname, ".."))).filter((file) => file.endsWith(".txt")).filter((file) => listsToIncludeInEverythingList.some((val) => file.startsWith(val))); // Array of strings, each representing a single file that ends in `.txt`
try {
const files = (await fs.readdir(path.join(__dirname, ".."))).filter(
(file) =>
file.endsWith(".txt") &&
listsToIncludeInEverythingList.some((val) => file.startsWith(val)),
);
const domains = new Set();

const domains = new Set();
await Promise.all(
files.map(async (file) => {
const fileContents = await fs.readFile(
path.join(__dirname, "..", file),
"utf8",
);
for (const line of fileContents.split("\n")) {
if (line.startsWith("0.0.0.0 ")) {
domains.add(line.replace("0.0.0.0 ", ""));
}
}
}),
);

await Promise.all(files.map(async (file) => { // For each file

const fileContents = await fs.readFile(path.join(__dirname, "..", file), "utf8"); // Get file contents as a string

fileContents.split("\n").forEach((line) => {
if (line.startsWith("0.0.0.0 ")) {
domains.add(line.replace("0.0.0.0 ", ""));
}
});
}));

let everythingListContent =
`# ------------------------------------[UPDATE]--------------------------------------
let everythingListContent = `# ------------------------------------[UPDATE]--------------------------------------
# Title: The Block List Project - Everything List
# Expires: 1 day
# Homepage: https://blocklistproject.github.io/Lists/
# Help: https://github.com/blocklistproject/lists/wiki/
# License: https://unlicense.org
# Total number of network filters:
# Total number of network filters: ${domains.size}
# ------------------------------------[SUPPORT]-------------------------------------
# You can support by:
# - reporting false positives
Expand All @@ -62,7 +68,17 @@ const listsToIncludeInEverythingList = [
# Everything list
# ------------------------------------[FILTERS]-------------------------------------
`;
domains.forEach((val) => everythingListContent += `0.0.0.0 ${val}\n`);

await fs.writeFile(path.join(__dirname, "..", "everything.txt"), everythingListContent, "utf8");
for (const val of domains) {
everythingListContent += `0.0.0.0 ${val}\n`;
}

await fs.writeFile(
path.join(__dirname, "..", "everything.txt"),
everythingListContent,
"utf8",
);
} catch (error) {
console.error("Error processing files:", error);
}
})();

0 comments on commit ae696a5

Please sign in to comment.