Created
May 23, 2012 21:42
-
-
Save blendmaster/2778012 to your computer and use it in GitHub Desktop.
preview /r/gifs on hover, displaying firefox bug
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== | |
// @id www.reddit.com-0496007c-95e3-4661-b485-846f1932fbbb@scriptish | |
// @name gif hover preview | |
// @version 0.1 | |
// @namespace | |
// @author blendmaster | |
// @description shows gifs on hover | |
// @match http://www.reddit.com/r/gifs/* | |
// ==/UserScript== | |
document.addEventListener('mouseover', function (e) { | |
if ( e.target.parentNode.classList.contains( 'thumbnail' ) ) { | |
var img = document.createElement( 'img' ), match; | |
img.src = e.target.parentNode.href; | |
// quick fix to get linked imgur gifs | |
if ( match = /imgur.com\/(\w+)/.exec( img.src ) ) { | |
img.src = "http://imgur.com/" + match[1] + '.gif'; | |
} | |
img.style.position = 'fixed'; | |
img.style.left = ( e.clientX + 10 ) + 'px'; | |
img.style.top = ( e.clientY + 10 ) +'px'; | |
img.style.opacity = 0.5; | |
img.addEventListener( 'load', function () { this.style.opacity = 1; } ); | |
document.body.appendChild( img ); | |
e.target.addEventListener( 'mouseout', function remove () { | |
document.body.removeChild( img ); | |
this.removeEventListener( 'mouseout', remove ); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment