Created
December 15, 2010 15:21
-
-
Save superbrothers/742072 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 expand tiqav on new twitter | |
// @namespace http://gist.github.com/742072 | |
// @include http://twitter.com/ | |
// @include http://twitter.com/#!/* | |
// ==/UserScript== | |
(function () { | |
function addJQuery(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"); | |
script.addEventListener('load', function () { | |
var script = document.createElement("script"); | |
script.textContent = "(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
function main() { | |
$('.stream-item').live('click', function () { | |
var | |
$tweetTextLarge, matches, | |
timer = window.setInterval(function () { | |
// 既に画像が展開済の場合、展開を行わない | |
if ($('div.pane-components div.tiqav-image').length > 0) { | |
window.clearInterval(timer); | |
} else { | |
$tweetTextLarge = $('.tweet-text-large'); | |
if ($tweetTextLarge.length > 0) { | |
window.clearInterval(timer); | |
matches = $tweetTextLarge.text().match(/(http:\/\/)?tiqav\.com\/(\w+)(\.\w{3})?/); | |
if (matches !== null && matches[2] !== undefined) { | |
$(['<div class="component">', | |
'<div class="tweet-media" style="display: block;">', | |
'<div data-media-type="tiqav" data-url-id="http://tiqav.com/%{ID}%" class="media-instance-container">', | |
'<div class="tiqav-image">', | |
'<a target="_blank" href="http://tiqav.com/%{ID}%">', | |
'<img src="http://tiqav.com/%{ID}%.th.jpg">', | |
'</a>', | |
'</div>', | |
'<div class="media-attribution"><span>via</span><a href="http://tiqav.com/" class="media-attribution-link" data-media-type="tiqav" target="_blank">', | |
'<img src="http://tiqav.com/images/favicon.ico">', | |
'</a></div>', | |
'</div>', | |
'</div>', | |
'</div>'].join('').replace(/%\{ID\}%/g, matches[2])).insertAfter(".pane-components .component:eq(1)"); | |
} | |
} | |
} | |
}, 500); | |
}); | |
} | |
addJQuery(main); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment