Created
December 9, 2009 22:06
-
-
Save satyr/252880 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Twiteaks | |
// @namespace http://d.hatena.ne.jp/murky-satyr | |
// @include http://twitter.com/* | |
// @include https://twitter.com/* | |
// ==/UserScript== | |
// LongURLize => http://gist.github.com/103277 | |
var [, user, sid] = | |
/^https?:\/\/twitter\.com\/(\w+)(?:\/status(?:es)?\/(\d+))?$/.exec(location) || 0 | |
// Sidebar Replies | |
user && !sid && xget( | |
'http://search.twitter.com/search.json?q=%40'+ user, | |
function(xhr){ | |
var {results} = JSON.parse(xhr.responseText); | |
var rf = document.getElementById('rssfeed'); | |
if(!rf) return; | |
rf.parentNode.appendChild(document.createElement('div')).innerHTML = | |
[let(uurl = 'http://twitter.com/'+ r.from_user) | |
'<p>'+ r.from_user.link(uurl) +': '+ r.text +'<br/>'+ | |
new Date(r.created_at).toString().link(uurl +'/status/'+ r.id) +'</p>' | |
for each(r in results)].join(''); | |
}); | |
if(sid){ | |
// Status Thread | |
let [em] = document.getElementsByClassName('entry-meta'); | |
if(em && | |
Array.some( | |
em.getElementsByTagName('a'), | |
function(a) /\bin reply to\b/.test(a.textContent))){ | |
let dv = em.parentNode.appendChild(clmn('div')); | |
xget( | |
'http://search.twitter.com/search/thread/'+ sid, | |
function(xhr){ | |
dv.innerHTML = xhr.responseText +'<style>'+ <![CDATA[ | |
.thread div {display:inline} | |
.avatar img {width:24px; height:24px} | |
.inthread:not(.result) {display:none} | |
]]> +'</style>'; | |
}, | |
function({status, statusText}){ | |
dv.innerHTML = <><b>{status}</b> {statusText}</>; | |
}); | |
} | |
// Favstar | |
const FFU = 'http://favstar.fm/users/'; | |
xget(FFU + user +'/status/'+ sid, function({responseText: htm}){ | |
if(!/<div[^>]*ss="avatarList"[^]+?(?=<div class="clear")/.exec(htm)) return | |
document.getElementById('permalink').appendChild(clmn( | |
'div', | |
('<style>.favs{font:bold 333% monospace}</style>'+ | |
RegExp.lastMatch.replace(/[/]users[/]/g, FFU)))); | |
}); | |
// Preceding/Following Tweets | |
xget( | |
'http://twitter.com/'+ user +'?max_id='+ | |
sid.replace(/^(.+)([2-9].*)$/, function(_, a, b) a + ~-b), | |
function(x){ | |
var [, ls] = /<ol id='timeline'[^>]*>([^]+?)<\/ol>/.exec(x.responseText) || 0 | |
if(!ls) return; | |
document.getElementById('container').insertBefore( | |
clmn('ul', ls), | |
document.getElementById('footer')); | |
}); | |
let gft = document.getElementById('container').insertBefore( | |
clmn('button', 'get following tweets'), | |
document.querySelector('#header + *')); | |
gft.addEventListener('click', function(){ | |
gft.innerHTML = '<img src="http://a1.twimg.com/images/spinner.gif"/>'; | |
xget( | |
'http://search.twitter.com/search?from='+ user +'&since_id='+ sid, | |
function(x){ | |
var lis = x.responseText.match(/<li class=\"result[^]+?<\/li>/g); | |
var lmn = lis ? | |
clmn('ul', lis.join('')) : clmn('em', 'No following tweets.'); | |
for each(let a in qsa(lmn, '.avatar')) a.parentNode.removeChild(a); | |
for each(let i in qsa(lmn, '.info')) i.className = 'meta'; | |
for each(let m in qsa(lmn, '.msgtxt')){ | |
let p = m.parentNode; | |
p.parentNode.replaceChild(m, p); | |
m.classList.add('entry-content'); | |
} | |
gft.parentNode.replaceChild(lmn, gft); | |
}); | |
}, false); | |
} | |
function xget(url, ok, ng){ | |
GM_xmlhttpRequest({method: 'GET', url: url, onload: ok, onerror: ng}); | |
} | |
function clmn(name, htm){ | |
var lmn = document.createElement(name); | |
if(htm) lmn.innerHTML = htm; | |
return lmn; | |
} | |
function qsa(lm, sl) Array.slice(lm.querySelectorAll(sl)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment