Created
October 19, 2010 20:14
-
-
Save swdyh/635006 to your computer and use it in GitHub Desktop.
This file contains 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 twitter embed image | |
// @namespace http://twitter.com/swdyh/ | |
// @include http://twitter.com/* | |
// ==/UserScript== | |
document.addEventListener("DOMNodeInserted", function(e) { | |
var selector = 'a[href$=".jpg"], a[href$=".png"], a[href$=".gif"]' | |
var elm = e.target | |
if (elm.className == 'stream-item') { | |
if (elm.querySelector(selector)) { | |
var ei = elm.querySelector('.extra-icons') | |
var span1 = document.createElement('span') | |
span1.className = 'inlinemedia-icons' | |
var span2 = document.createElement('span') | |
span2.className = 'media photo' | |
span1.appendChild(span2) | |
ei.appendChild(span1) | |
} | |
} | |
if (elm.className == 'component') { | |
var as = elm.querySelectorAll(selector) | |
for (var i = 0; i < as.length; i++) { | |
var div = document.createElement('div') | |
div.className = 'tweet-media' | |
var img = document.createElement('img') | |
img.src = as[i] | |
var a = document.createElement('a') | |
a.href = as[i] | |
a.target = '_blank' | |
a.appendChild(img) | |
div.appendChild(a) | |
elm.appendChild(div) | |
} | |
} | |
}, false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment