-
Notifications
You must be signed in to change notification settings - Fork 0
/
Load GIFs before playing.user.js
41 lines (34 loc) · 1.2 KB
/
Load GIFs before playing.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// ==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);
}
}());