Load GIFs before playing

Hides a GIF until it's fully loaded

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name            Load GIFs before playing
// @namespace       https://greasyfork.org/en/users/321-joesimmons
// @description     Hides a GIF until it's fully loaded
// @include         http://*
// @include         https://*
// @exclude         http://*.gif
// @exclude         https://*.gif
// @exclude         http://*.gif?*
// @exclude         https://*.gif?*
// @copyright       JoeSimmons
// @author          JoeSimmons
// @version         1.0.0
// @license         GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @grant           GM_addStyle
// ==/UserScript==

(function () {
    'use strict';

    var gifs = document.querySelectorAll('img[src$=".gif"]'), gif, i;

    function unhide(elem) {
        elem.target.style.visibility = 'visible';
    }

    for (i = 0; i < gifs.length; i += 1) {
        gif = gifs[i];

        // skip ones that are hidden already
        if (gif.style.visiblity === 'hidden' || gif.style.display === 'none') {
            continue;
        }

        // temporarily hide the GIF
        gif.style.visibility = 'hidden';

        // set it to un-hide when it's fully loaded
        gif.addEventListener('load', unhide, false);
    }
}());