├── .gitignore ├── .npmignore ├── README.MD ├── bin ├── letsfun.js └── letswork.js ├── blockables ├── 9gag.js ├── cnn.js ├── facebook.js ├── hackernews.js ├── index.js ├── instagram.js ├── macrumors.js ├── producthunt.js ├── reddit.js ├── twitch.js ├── twitter.js └── youtube.js ├── lib ├── argumenthandler.js ├── commandhandler.js ├── help.js ├── hostseditor.js └── list.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reimertz/letswork/9673441323c8abd7abac629b131f3c8352368763/.npmignore -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | letswork / letsfun 2 | ===== 3 | 4 | letswork / letsfun is a tool that will help you be more effective 5 | by giving you the ability to block all those sites that consumes 6 | all your time (facebook, 9gag, reddit, twitter..). 7 | 8 | It's all done by adding/removing some magic lines to your 9 | hosts file. 10 | 11 | **Caution:** I strongly suggest that you backup your hosts file 12 | ```bash 13 | sudo cp -npRv "/etc/hosts" "/etc/hosts_letswork_backup_$(date +"%m_%d_%Y")" 14 | ``` 15 | 16 | ##Installation 17 | ```bash 18 | sudo npm install -g letswork 19 | ``` 20 | *need root privileges since it's editing /etc/hosts 21 | 22 | ##Usage 23 | ```bash 24 | letswork --help 25 | Usage: letswork -- block all 26 | letswork -- to allow certain homepages for work-related tasks ;) 27 | letswork --list --l -- shows list of blockable homepages 28 | letswork --help --h -- shows this help 29 | 30 | Usage: letsfun -- unblock all 31 | letsfun -- keep some blocked 32 | letsfun -h --h -- shows this help 33 | 34 | where is one of: 35 | 9gag,facebook,reddit,twitter 36 | 37 | Example: letswork twitter -- keeps twitter unblocked 38 | letsfun facebook -- keeps facebook blocked 39 | ``` 40 | -------------------------------------------------------------------------------- /bin/letsfun.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | "use strict"; 3 | 4 | var args = require('minimist')(process.argv.slice(2)), 5 | commandHandler = require('../lib/commandhandler'), 6 | argumentHandler = require('../lib/argumenthandler'); 7 | 8 | 9 | //Check for --help --list 10 | argumentHandler.check(args); 11 | 12 | //execute letfun command 13 | commandHandler.letsfun(args); 14 | -------------------------------------------------------------------------------- /bin/letswork.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | "use strict"; 3 | 4 | var args = require('minimist')(process.argv.slice(2)), 5 | commandHandler = require('../lib/commandhandler'), 6 | argumentHandler = require('../lib/argumenthandler'); 7 | 8 | 9 | //Check for --help --list 10 | argumentHandler.check(args); 11 | 12 | //execute letwork command 13 | commandHandler.letswork(args); -------------------------------------------------------------------------------- /blockables/9gag.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'www.9gag.com', 3 | '9gag.com' 4 | ] -------------------------------------------------------------------------------- /blockables/cnn.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'cnn.com' 3 | ] -------------------------------------------------------------------------------- /blockables/facebook.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'www.facebook.com', 3 | 'facebook.com', 4 | 'static.ak.fbcdn.net', 5 | 'www.static.ak.fbcdn.net', 6 | 'login.facebook.com', 7 | 'www.login.facebook.com', 8 | 'fbcdn.net', 9 | 'www.fbcdn.net', 10 | 'fbcdn.com', 11 | 'www.fbcdn.com', 12 | 'static.ak.connect.facebook.com', 13 | 'www.static.ak.connect.facebook.com' 14 | ] -------------------------------------------------------------------------------- /blockables/hackernews.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'news.ycombinator.com' 3 | ] 4 | -------------------------------------------------------------------------------- /blockables/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('requireindex')(__dirname); -------------------------------------------------------------------------------- /blockables/instagram.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'instagram.com' 3 | ] -------------------------------------------------------------------------------- /blockables/macrumors.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'macrumors.com' 3 | ] -------------------------------------------------------------------------------- /blockables/producthunt.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'producthunt.com' 3 | ] -------------------------------------------------------------------------------- /blockables/reddit.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'www.reddit.com', 3 | 'reddit.com' 4 | ]; 5 | -------------------------------------------------------------------------------- /blockables/twitch.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'twitch.com' 3 | ] -------------------------------------------------------------------------------- /blockables/twitter.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'twitter.com', 3 | 'www.twitter.com', 4 | 'tweetdeck.twitter.com' 5 | ]; 6 | -------------------------------------------------------------------------------- /blockables/youtube.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | 'youtube.com', 3 | 'm.youtube.com' 4 | ] -------------------------------------------------------------------------------- /lib/argumenthandler.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | check: function(args) { 3 | require('./help')(args); 4 | require('./list')(args); 5 | } 6 | } -------------------------------------------------------------------------------- /lib/commandhandler.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _ = require('lodash'), 4 | chalk = require("chalk"), 5 | Promise = require('bluebird'), 6 | hostile = require("hostile"), 7 | 8 | blockables = require('../blockables'), 9 | args = require('minimist')(process.argv.slice(2)), 10 | 11 | hostsEditor = require('../lib/hostseditor'), 12 | argumentHandler = require('../lib/argumenthandler'); 13 | 14 | 15 | function commandHandler(mode, arg){ 16 | 17 | var ignoreList = {}, 18 | resetMode = (mode === 'block') ? 'unblock' : 'block'; 19 | 20 | args._.forEach(function(item){ 21 | if (blockables[item]) { 22 | ignoreList[item] = blockables[item]; 23 | 24 | delete blockables[item]; 25 | } 26 | }); 27 | 28 | hostsEditor[resetMode](ignoreList).then(function(){ 29 | hostsEditor[mode](blockables).then(function(){ 30 | 31 | if (Object.keys(ignoreList).length > 0) { 32 | var firstColor = (mode === 'block') ? 'red' : 'green', 33 | secondColor = (firstColor === 'red') ? 'green' : 'red'; 34 | 35 | console.log(chalk[firstColor](mode + 'ed everything except ' + chalk[secondColor](Object.keys(ignoreList).join(', ')))); 36 | } 37 | else if (mode === 'block'){ 38 | console.log(chalk.red('Lets work!')); 39 | } 40 | else { 41 | console.log(chalk.green('Free at last!')); 42 | } 43 | }) 44 | }) 45 | .error(function(err){ 46 | console.log('something went wrong...'); 47 | }); 48 | 49 | } 50 | 51 | 52 | function excecuter(mode, arg) { 53 | if(mode !== 'letsfun' && mode !== 'letswork') Promise.reject('wrong mode:' + mode); 54 | 55 | return commandHandler((mode === 'letswork') ? 'block' : 'unblock', arg); 56 | 57 | } 58 | 59 | 60 | module.exports = { 61 | letsfun: function(arg){ 62 | return excecuter('letsfun', arg); 63 | }, 64 | letswork: function(arg) { 65 | return excecuter('letswork', arg); 66 | } 67 | } -------------------------------------------------------------------------------- /lib/help.js: -------------------------------------------------------------------------------- 1 | var blockables = require('../blockables'); 2 | 3 | function printHelp() { 4 | console.log(); 5 | console.log('Usage: letswork -- block all'); 6 | console.log(' letswork -- to allow certain homepages for work-related tasks ;)'); 7 | console.log(' letswork --list --l -- shows list of blockable homepages'); 8 | console.log(' letswork --help --h -- shows this help'); 9 | 10 | console.log(); 11 | console.log('Usage: letsfun -- unblock all'); 12 | console.log(' letsfun -- keep some blocked'); 13 | console.log(' letsfun -h --h -- shows this help'); 14 | console.log(); 15 | console.log('where is one of:'); 16 | console.log(' '+ Object.keys(blockables)); 17 | console.log(); 18 | console.log('Example: letswork twitter -- keeps twitter unblocked'); 19 | console.log(' letsfun facebook -- keeps facebook blocked'); 20 | } 21 | 22 | module.exports = function(args) { 23 | if (args._.indexOf('help') > -1 || args.help || args.h 24 | || (args.h && args.e && args.l && args.p) ) { 25 | 26 | printHelp(); 27 | process.exit(); 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /lib/hostseditor.js: -------------------------------------------------------------------------------- 1 | var Promise = require('bluebird'), 2 | hostile = require("hostile"), 3 | _ = require('lodash'); 4 | 5 | function hostsEditor(mode, address) { 6 | var resolver = Promise.pending(); 7 | 8 | hostile[mode]('127.0.0.1', address, function (err) { 9 | if (err) { 10 | return resolver.reject(err); 11 | } 12 | return resolver.resolve(address); 13 | }) 14 | 15 | return resolver.promise; 16 | } 17 | 18 | function isObject(mode, addressObject) { 19 | var current = Promise.resolve(); 20 | addressArray = _.chain(addressObject) 21 | .values() 22 | .flatten() 23 | .value(); 24 | 25 | 26 | return Promise.all(addressArray.map(function(address) { 27 | return current = current.then(function() { 28 | return hostsEditor(mode, address); 29 | }); 30 | })) 31 | } 32 | 33 | function excecuter(mode, arg) { 34 | if(mode !== 'set' && mode !== 'remove') Promise.reject('wrong mode:' + mode); 35 | 36 | if(_.isString(arg)) return hostsEditor(mode, arg) 37 | if(_.isObject(arg)) return isObject(mode, arg) 38 | 39 | else return Promise.reject('wrong type: ' + type); 40 | } 41 | 42 | 43 | module.exports = { 44 | block: function(arg){ 45 | return excecuter('set', arg); 46 | }, 47 | unblock: function(arg) { 48 | return excecuter('remove', arg); 49 | } 50 | } -------------------------------------------------------------------------------- /lib/list.js: -------------------------------------------------------------------------------- 1 | var blockables = require('../blockables'); 2 | 3 | function printList() { 4 | console.log(); 5 | console.log('Blockable homepages: '+ Object.keys(blockables)); 6 | } 7 | 8 | module.exports = function(args) { 9 | if (args._.indexOf('list') > -1 || args.list || args.l 10 | || (args.l && args.i && args.s && args.t)) { 11 | 12 | printList(); 13 | process.exit(); 14 | } 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "letswork", 3 | "version": "0.2.0", 4 | "description": "A tool to disable all your distractions", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:reimertz/letswork.git" 8 | }, 9 | "author": "Pierre Reimertz", 10 | "bin": { 11 | "letswork": "bin/letswork.js", 12 | "letsfun": "bin/letsfun.js" 13 | }, 14 | "files": [ 15 | "bin/*", 16 | "lib/*", 17 | "blockables/*" 18 | ], 19 | "scripts": { 20 | "test": "echo \"Error: no test specified\" && exit 1" 21 | }, 22 | "license": "ISC", 23 | "dependencies": { 24 | "bluebird": "^2.6.0", 25 | "chalk": "^0.5.1", 26 | "hostile": "^1.0.0", 27 | "lodash": "^2.4.1", 28 | "minimist": "^1.1.0", 29 | "requireindex": "^1.1.0" 30 | }, 31 | "engineStrict": true, 32 | "preferGlobal": true 33 | } 34 | --------------------------------------------------------------------------------