Load GIFs before playing

Hides a GIF until it's fully loaded

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    }
}());