Skip to content

Instantly share code, notes, and snippets.

@amasad
Created October 31, 2013 10:53
Show Gist options
  • Save amasad/7247787 to your computer and use it in GitHub Desktop.
Save amasad/7247787 to your computer and use it in GitHub Desktop.
play gifs on facebook
(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