Skip to content

Instantly share code, notes, and snippets.

@kentbrew
Created May 11, 2010 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentbrew/397621 to your computer and use it in GitHub Desktop.
Save kentbrew/397621 to your computer and use it in GitHub Desktop.
Monkeying with Twitter
// ==UserScript==
// @name Monkeying with Twitter
// @namespace kentbrewster.com
// @description A teaching framework for Greasemonkey. Our target for tonight: Twitter
// @include http://twitter.com/*
// ==/UserScript==
//////////////////////////////////////////////
// make sure Greasemonkey is really working //
//////////////////////////////////////////////
alert ('Greasemonkey awaits your bidding, master.');
// COMMENT THIS OUT WHEN YOU'RE HAPPY GREASEMONKEY IS WORKING
///////////////////////////////////////////////////////////////////////////////////
// a handy shortcut, so we don't have to keep typing in "document" over and over //
///////////////////////////////////////////////////////////////////////////////////
var d = document;
//////////////////////////////
// change the main headline //
//////////////////////////////
// find it on the page
var theHeadline = d.getElementsByTagName('H3')[0];
// change it
//theHeadline.textContent = 'Yo, baby. Whassup?';
// UNCOMMENT TO SEE THIS WORK
/////////////////////////////
// change the tweet button //
/////////////////////////////
// find it on the page
var theButton = d.getElementById('tweeting_button');
// change its contents
//theButton.innerHTML = 'Sheboygan!';
// UNCOMMENT TO SEE THIS WORK
///////////////////////////
// remove elements by ID //
///////////////////////////
// the list of IDs we want to delete
var deleteById =
[ 'trends'
, 'pagination'
, 'new_results_notification'
, 'geo_status'
, 'rssfeed'
, 'following'
, 'message_count'
];
// loop through all IDs listed above in deleteById
for (var i = 0; i < deleteById.length; i++) {
// the one we're working with right now
var toDelete = deleteById[i];
// get it from the document
var me = d.getElementById(toDelete);
// go up one level in the document to its parent and remove it
// me.parentNode.removeChild(me);
// UNCOMMENT TO SEE THIS WORK
}
///////////////////////////////////
// remove elements by class name //
///////////////////////////////////
// the list of class names we're going to look at
var deleteByClass =
[ 'stats'
, 'promotion round'
];
// loop through all the class names listed above in deleteByClass
for (var i = 0; i < deleteByClass.length; i++) {
// here's the one we're working with right now
var toDelete = deleteByClass[i];
// get all elements
var theElements = d.getElementsByClassName(toDelete);
// loop through all the elements
for (var j = 0; j < theElements.length; j++) {
// here's the one we're working with right now
var me = theElements[j];
// go up one level in the document to its parent and remove it
// me.parentNode.removeChild(me);
// UNCOMMENT TO SEE THIS WORK
}
}
//////////////////////
// add a stylesheet //
//////////////////////
// IMPORTANT: uncomment the BOTTOM LINE
// and then go through and uncomment various rules (as noted)
// to see it working
// a list of styles we're going to add
var rules = [ ''
// global font mischief
// , '* { font-family:monaco, courier new, courier, monospaced; }'
// UNCOMMENT TO SEE THIS WORK
// some sidebar changes
// , '#side_base { background:#000; }'
// , '#primary_nav { margin-top:10px; }',
// , 'div.user_icon:hover, div.user_icon:hover * { color:#fff; background:#000; text-decoration:none;}'
// , '#side a { color:#ff0; }'
// , '#side a:hover { background:#ff0; color:#000; }'
// , '#side_base, #me_name, #me_tweets { color:#fff; }'
// , 'ul.sidebar-menu li.active a { background-color:#666; }'
// UNCOMMENT PREVIOUS SEVEN LINES TO SEE THIS WORK
// hide the @%!$* hovercards
// , '.hovercard { display:none; }'
// UNCOMMENT TO SEE THIS WORK
];
// join all the rules into a single string and call it 'styles'
var style = rules.join("\n");
// add !important to every rule
style = style.replace(/;/g, '!important;');
// create an empty stylesheet
var css = document.createElement('STYLE');
// set its type to text/cs
css.type = 'text/css';
// add the style we created above
css.appendChild(document.createTextNode(style));
// add it to our document body
// d.getElementsByTagName('BODY')[0].appendChild(css);
// UNCOMMENT TO SEE THIS WORK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment