Discussions » Creation Requests

Script version of the "GoogleGIFs" chrome extension

§
Posted: 2019-02-03

Script version of the "GoogleGIFs" chrome extension

I love using this chrome extension that automatically plays GIFs on the Google Images search results, but I've already got so many extensions, I'd prefer a script instead https://chrome.google.com/webstore/detail/googlegifs/ommpbgoliokoijimalcokhciffhapkdf

wOxxOmMod
§
Posted: 2019-02-03

I guess you can try copypasting the code from that extension and tweaking the include pattern:

// ==UserScript==
// @name    GoogleGIFs
// @include *://www.google.*/*tbm=isch*
// ==/UserScript==

(function() {
    function playGIFs() {
        var els, i, a, img, matches, url;
        els = document.getElementsByClassName('rg_di');
        for (i = 0; i < els.length; i++) {
            if (els[i].animated) continue;
            els[i].animated = true;
            a = els[i].getElementsByTagName('a')[0];
            if (!a) continue;
            img = els[i].getElementsByTagName('img')[0];
            if (!img) continue;
            matches = a.href.match(/imgurl=(\S+?)(&|$)/i);
            if (matches !== null && matches.length > 1) {
                url = unescape(unescape(matches[1]));
                if (/\.gif(\?.*)?$/i.test(url)) {
                    img.src = url;
                }
            }
        }
    }
    // continue to load GIFs added to DOM after initial page load
    window.setInterval(playGIFs, 1000);
})();

Post reply

Sign in to post a reply.