Skip to content

Instantly share code, notes, and snippets.

@blendmaster
Created May 23, 2012 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blendmaster/2778012 to your computer and use it in GitHub Desktop.
Save blendmaster/2778012 to your computer and use it in GitHub Desktop.
preview /r/gifs on hover, displaying firefox bug
// ==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