Twitter Replies Mover
By riddle
—
Last update Dec 12, 2007
—
Installed
814 times.
// ==UserScript==
// @namespace http://riddle.pl/-/greasemonkey/twitter.replies.user.js
// @name Twitter Replies Mover
// @description Takes last replies for you and puts them on your Twitter homepage
// @author Riddle
// @version 1.0.3
// @include http://twitter.com/home
// @include https://twitter.com/home
// ==/UserScript==
GM_xmlhttpRequest({
method: 'GET',
url: 'http://twitter.com/replies',
onload: function(r) { parse(r.responseText) }
});
function parse(text) {
var start = text.indexOf('<table class="doing" id="timeline"');
var end = text.indexOf('</table>') + 8;
var body = text.substring(start, end);
/*
var parser = new DOMParser();
var xml = parser.parseFromString(body, "text/xml");
var xml = xml.documentElement.innerHTML;
*/
var vessel = document.createElement('div');
vessel.innerHTML = body;
vessel.style.display = 'none';
document.body.appendChild(vessel);
styles = '.new-reply { margin: 7px 0; font-size: 10px; overflow: hidden; }' +
'.new-reply img { float: left; }' +
'.new-reply div { margin-left: 29px; }';
newSS = document.createElement('link');
newSS.rel = 'stylesheet';
newSS.href = 'data:text/css,' + escape(styles);
document.getElementsByTagName('head')[0].appendChild(newSS);
text, body = '';
var replies = document.createElement('div');
var items = vessel.getElementsByTagName('tr');
for (var i = 0; i < items.length; i++) {
var reply = document.createElement('div');
reply.className = 'new-reply';
var img = items[i].getElementsByTagName('td')[0].getElementsByTagName('img')[0].cloneNode(true);
var cont = items[i].getElementsByTagName('td')[1];
var nick = cont.getElementsByTagName('strong')[0].cloneNode(true);
var mess = cont.getElementsByTagName('span')[0].cloneNode(true);
var misc = cont.getElementsByTagName('span')[1].cloneNode(true);
var atlink = mess.getElementsByTagName('a')[0];
if (atlink) {
mess.removeChild(mess.firstChild);
mess.removeChild(atlink);
}
var abbr = misc.getElementsByTagName('abbr')[0];
var date = /T[0-9\:\+]+$/;
if (abbr.title.match(date) && !abbr.firstChild.nodeValue.match(/about|hours|minutes|seconds/)) {
abbr.firstChild.nodeValue = abbr.title.replace(date, '');
}
if (abbr.firstChild.nodeValue.match(/about /)) {
abbr.firstChild.nodeValue = abbr.firstChild.nodeValue.replace(/about /, '');
}
var when = misc.getElementsByTagName('a')[0];
var what = misc.getElementsByTagName('a')[1];
var text = document.createElement('div');
text.appendChild(nick);
text.appendChild(mess);
text.appendChild(when);
var replyto = document.createElement('a');
replyto.href = what.href;
img.src = img.src.replace('_normal.', '_mini.');
img.alt = '';
img.height = '24';
img.width = '24';
replyto.appendChild(img);
reply.appendChild(replyto);
reply.appendChild(text);
replies.appendChild(reply);
}
var side = document.getElementById('side');
var h4 = document.createElement('h4');
h4.style.margin = '10px 0';
h4.appendChild(document.createTextNode('Replies to you:'));
side.appendChild(h4);
side.appendChild(replies);
}