Created
October 31, 2013 10:53
-
-
Save amasad/7247787 to your computer and use it in GitHub Desktop.
play gifs on facebook
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
(function () { | |
var debounce = function (fn, d) { | |
var t; | |
return function () { | |
if (t) clearTimeout(t); | |
t = setTimeout(fn, d); | |
}; | |
}; | |
var giffy = function () { | |
[].slice.apply(document.querySelectorAll('a')).filter(function (a) { | |
var msover = a.getAttribute('onmouseover'); | |
if (msover && msover.match(/gif/)) a.dispatchEvent(new Event('mouseover')); | |
var href = a.getAttribute('href'); | |
return(href && !!href.match(/gif$/)); | |
}).forEach(function (a) { | |
var img = a.querySelector('img'); | |
if (img && img.getAttribute('src') != a.getAttribute('href')) { | |
img.setAttribute('src', a.getAttribute('href')); | |
} | |
}); | |
}; | |
window.addEventListener('scroll', debounce(giffy, 300)); | |
giffy(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment