Login
Home
Eoin Bailey . com
Tech, Research, Code, Work, and Fun
  • Home
  • Eoin's CV
  • About Eoin
  • Ph.D.
  • Blog
  • Galleries
  • Training
  • Polls
  • Tags
  • Weblinks
  • Site map
  • Contact

Tag Cloud

algorithm antarctica apple banking browser code copyright cycle data centre devel Dijkstra drupal drupalcamp economics escapades facebook firefox galway Google iphone ipod livigno theme training weights
more tags

A Random Image

IMG_3565

Greasemonkey

in
  • Code-Work
  • General-Personal
  • General-Work
  • greasemonkey
  • javascript
  • twitter

After Aaron pointed me towards twilog.org, I got interested in changing the way twitter looks to me, but without going via a third-party site and the API. The answer of course is Greasemonkey!

Here is version 0.01 of my script to change the way twitter looks. At the moment, it doesn't do very much! A lot of the work is in there, just a few changes and tweaks needed and it should be up and running though!

Version 0.01 of the code is attached to this page, but have a look at it too:


// ==UserScript==
// @name           Twitter - Twilog.org
// @namespace      http://eoinbailey.com/greasemonkey
// @description    Make twitter look better - more like twilog.org
// @include        http://twitter.com/
// ==/UserScript==
/*
TODO: Show the number of tweets per day
*/

var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";


var twitterTimeWords = new Array("about", "less than");
var previousPostDay = -1;

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

addGlobalStyle(
'body {' +
'  font-family: calibri, sans-serif, cursive ! important;' +
'   font-size: 13px !important;' +
'}' +
'.listable {' +
'   display: none !important;' +
'}' +
'.status-body {' +
'   margin-left: 10px !important;' +
'   width: 470px !important;' +	
'}' +
'.entry-meta span {' +
'    display: none !important;' +
'}' +
'.entry-meta span.published {' +
'    display: inline !important;' +
'}'+
'.dayHeader {' +
'    background-color: #F4E5BE !important;' +
'    padding: 4px 4px 4px 14px;' +
'    border-top: solid 1px black;' +
'    border-bottom: solid 1px black;' +
'}' +
'.dayHeader li:hover {' +
'    background-color: #F4E5BE !important;' +
'}');

/*
The first element that you find on the page with the code below is the current status message
It is partially hidden, which is why you don't see it on the page so need to ignore the first
result.

Find all the time elements on the page - in the order they appear on the page.
Have to work out if they are the current day... yesterday... etc...
*/
var allPublishedTimeElements, thisPublishedTimeElement;
allPublishedTimeElements = document.evaluate(
    "//span[@class='published']",
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null);
for (var i = 1; i < allPublishedTimeElements.snapshotLength; i++) {
    thisPublishedTimeElement = allPublishedTimeElements.snapshotItem(i);
	var timeSincePost = thisPublishedTimeElement.innerHTML;

	var x = orderPost(timeSincePost,thisPublishedTimeElement);

	thisPublishedTimeElement.innerHTML = x; //timeSincePost;
}

/*
 Determines where the post should be ordered on the page

less than XX seconds ago
a minute ago
XX minutes ago
XX hours ago
5:26 PM Aug 15th
12:08 AM Aug 1st
*/
function orderPost(postTime, tweetID) {
	// Remove the word ago.. if it's there
	// assumption is that 'ago' is always the last word if it is there
	// That may not be true!
	var agoIndex = postTime.indexOf("ago");
	if (agoIndex != -1) {
		postTime = postTime.substring(0, agoIndex-1);
	}
	
	for (var j = 0; j < twitterTimeWords.length; j++) {
		if (postTime.indexOf(twitterTimeWords[j]) != -1) {
			// this tweet does have one of the twitter time words in it.
			postTime = postTime.substr(twitterTimeWords[j].length+1);
		}
	}
	var d = new Date();
	var currentEpochTime = d.getTime();
	var postEpochTime = currentEpochTime;

	// TODO
	// have to deal with seconds too...
	
	if (postTime.indexOf("minute") != -1) {
		// TODO
		// Have to check for 'a minute' - stupid
		postEpochTime = currentEpochTime - postTime.substring(0, postTime.indexOf("minute")-1)*60*1000;
//		myDate = new Date(postEpochTime);
//		return checkTime(myDate.getHours())+":"+checkTime(myDate.getMinutes());
	}
	else if (postTime.indexOf("hour") != -1) {
		postEpochTime = currentEpochTime - postTime.substring(0, postTime.indexOf("hour")-1)*60*60*1000;	
	}
	
	var myDate = new Date(postEpochTime);

	if (previousPostDay != myDate.getDate()) {
		// We have changed day...
		// TODO: Add a new element that shows which day these tweets were posted on.
		previousPostDay = myDate.getDate();
	
/*		var content = tweetID.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML;
		var dayHeader = '
Posted on '+month[myDate.getMonth()]+' '+previousPostDay+' '+myDate.getFullYear()+'
'; tweetID.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML = dayHeader+content;*/ } return checkTime(myDate.getHours())+":"+checkTime(myDate.getMinutes()); } function checkTime(i) { if (i<10) { i="0" + i; } return i; } // END OF FILE
AttachmentSize
twitter_-_twilogorg.user_.jsV0.01.txt4.36 KB
  • Printer-friendly version
  • Send to friend

Current Poll

What is your current phone OS?:

Freelance Work

A sample of websites I have developed:

  • Studio Richards
  • Medilex
  • Design21C
  • The Spine Clinic
  • Abrivia - Careers and Outplacement
  • Emilie Conway

Twitter

Follow @eoinbailey

Some Links

  • James Bond Opening Scenes
  • Polls
  • Chess Module-Drupal
  • Ski Trip Jan 2009

Training

  • Spinning
  • Hodson Bay Hotel Training
  • Spinning Class - Not too Shabby!
  • Bike Time Trial
  • Spinning Class of Anti-Doom!

Recent Comments

  • Happy New Year 2012!
  • Thank you..
  • Simple way
  • Yep, CSS is an option - there
  • Maybe CSS is an easy solution?
  • Thanks for the direction.
  • Thank you for the insight.
  • Exactly.
  • Thank you for the insight.
  • I'm open to correction on

Powered by

Powered by Drupal, an open source content management system

Recent blog posts

  • Copyright Issues
  • Leap Card
  • A new College term - Dijkstra's Algorithm
  • Dublin GTUG - June 2011 - Over 100 attendees
  • City of a Thousand Welcomes
  • Groupon et al. - "Bet on the Future"
  • Dublin Web Summit - DWS6 - Roundup
  • Anti-Spam - Using a Catch-All to identify bad companies
  • Hide a Note Title - Drupal 7
  • The Election on Hit The Road
more
Copyright © 2012 Eoin Bailey . com.

I'm trying out: Web Analytics