Skip to content

Instantly share code, notes, and snippets.

@arthurattwell
Last active May 8, 2018 15:14
Show Gist options
  • Save arthurattwell/61ca9b025d9f50a6f23135bfc64362b8 to your computer and use it in GitHub Desktop.
Save arthurattwell/61ca9b025d9f50a6f23135bfc64362b8 to your computer and use it in GitHub Desktop.
Greasemonkey script to warn me when I open social-media sites
// ==UserScript==
// @name Avoid social media
// @version 1
// @grant none
// @include *://facebook.com*
// @include *://*.facebook.com*
// @include *://twitter.com*
// @include *://*.twitter.com*
// @run-at document-start
// ==/UserScript==
function removeContent() {
var content = document.body;
content.remove();
}
function warn() {
var choice = confirm("Whoa, tiger. Is there something better you can do with the next few precious minutes? Get up and walk around the room.");
if (choice == true) {
alert("Good for you! Close the tab and get out of there.");
window.stop();
removeContent();
} else {
alert('Okay. Be careful out there.');
hideFeeds();
return;
}
}
function hideFeeds() {
var custom_css = '[id^="topnews_main_stream"],#sideNav,.home_right_column {display: none;}';
var isFacebook = document.querySelector('html[id="facebook"]');
if (isFacebook != undefined) {
console.log('Eek! Facebook!');
alert('Hiding your Facebook home feed for your own good. Anything important will be in your notifications.');
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = custom_css;
document.getElementsByTagName('head')[0].appendChild(style);
}
var isTwitter = document.querySelector('link[href^="https://twitter.com"]');
if (isTwitter != undefined) {
console.log('Eek! Twitter!');
}
}
//-- Don't run on frames or iframes
if (window.top != window.self) {
return;
}
warn();
@arthurattwell
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment