Provide the variants only?
Hi!
This repo is great but, what if we want to block only porn sites? or only gambling sites? :question:
All of the files have Unified hosts + Variant
I solved this by overengineering a NodeJS solution π and then realized there's a very simple way of doing it... :man_facepalming:
Simple way:
diff --unchanged-group-format='' hosts porn > output_file
My NodeJS script:
(downloads the hosts file then porn and then goes through all lines and displays the ones that are in the second file but not first.)
const fs = require("fs");
const wget = require("wget-improved");
try {
let download = wget.download(
"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts",
"hosts",
{}
);
let download2 = wget.download(
"https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts",
"porn",
{}
);
const events = [download, download2];
const promises = events.map((event) => {
return new Promise((resolve) => {
event.on("end", (paths) => {
resolve(paths);
});
});
});
Promise.all(promises).then((result) => {
// console.log("both finished", result);
// read contents of the file
const data = fs.readFileSync("hosts", "UTF-8");
const data2 = fs.readFileSync("porn", "UTF-8");
// split the contents by new line
const lines = new Set(data.split(/\r?\n/));
const lines2 = new Set(data2.split(/\r?\n/));
let count = 0;
// usint Sets avoids O(n^2)
lines2.forEach((line2) => {
if (!lines.has(line2)) {
console.log(line2);
count++;
}
});
console.log("# Size diff: ", lines2.size - lines.size);
console.log("# Diff count: ", count);
});
} catch (err) {
console.error(err);
}
Run it: node diff.js > output_file
P.S. Don't forget to: npm i wget-improved
Hello! Thank you for opening your first issue in this repo. Itβs people like you who make these host files better!
Hi Rodrigo @rodrigograca31 that's an interesting idea. Nobody has asked for this before, maybe because the base list is so useful?
Stand-alone extension files, in various combinations. I like it.
I think, it would be much better to totally refactor hosts file, so instead of putting all in one file, it would be better to split it to a lot of smaller files, that user can select what need, and connect these files as he want. For example I needed to block social webs, so I copied whole that thing with over 12k lines, and then I was delleting specific rules, that I needed to not block... for example I wanted to block all social medias expect twitter and reddit. So I used gedit, where I used replace function to remove rules I wanted to remove. If in repo, we would have folder social medias, and in this folder only social media hosts, and per social media one file, it would help much more. Btw, there can be easy way to create app, that would generate one hosts from these a lot of hosts files. Much easier for users. And easier managing hosts files.
I know....old post and all that,but it's still open so....
Linux to the rescue(no need of such a complicated JavaScripts) π :
wget https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts -O porn_only.txt
sed -i '0,/^# End yoyo/d; /^#/d; s/ #.*//g; /^$/d' porn_only.txt
And Voila...you have yourself one healthy porn only list.
Enjoy π
I know....old post and all that,but it's still open so.... Linux to the rescue(no need of such a complicated JavaScripts) π :
wget https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts -O porn_only.txtsed -i '0,/^# End yoyo/d; /^#/d; s/ #.*//g; /^$/d' porn_only.txtAnd Voila...you have yourself one healthy porn only list. Enjoy π
how make grep domain only without 0.0.0.0 ? becouse i am using for dns rpz
I just want to throw my support for this in as well. This is a wonderful project, and having the categories only would be good for situations where blocking all the ads isn't necessarily the goal. I worked in a small library before where this would be handy. This could be used in PiHole or pfBlockerNG as a quick way to help prevent adult content being viewed.