diff --git a/CHANGELOG.md b/CHANGELOG.md index 91126661b..a19e4bd10 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### v1.9.2.8 +*2014-09-11* + +**ccd0** +- Simplify and improve thumbnail replacement / preloading. Remove the download queue (didn't work well). Drop support for non-autoplaying replaced WebM thumbnails. + ### v1.9.2.7 *2014-09-10* diff --git a/LICENSE b/LICENSE index a87ff1da1..22ea2c285 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.9.2.7 +* 4chan X - Version 1.9.2.8 * * Licensed under the MIT license. * https://github.com/ccd0/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X-beta.crx b/builds/4chan-X-beta.crx index 0b984bc68..0c66f6b73 100644 Binary files a/builds/4chan-X-beta.crx and b/builds/4chan-X-beta.crx differ diff --git a/builds/4chan-X-beta.meta.js b/builds/4chan-X-beta.meta.js index ccad62541..0d99e5f25 100644 --- a/builds/4chan-X-beta.meta.js +++ b/builds/4chan-X-beta.meta.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X -// @version 1.9.2.7 +// @version 1.9.2.8 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X diff --git a/builds/4chan-X-beta.user.js b/builds/4chan-X-beta.user.js index 16e753fbf..049bc97d5 100644 --- a/builds/4chan-X-beta.user.js +++ b/builds/4chan-X-beta.user.js @@ -1,7 +1,7 @@ // Generated by CoffeeScript // ==UserScript== // @name 4chan X -// @version 1.9.2.7 +// @version 1.9.2.8 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -24,7 +24,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.9.2.7 +* 4chan X - Version 1.9.2.8 * * Licensed under the MIT license. * https://github.com/ccd0/4chan-x/blob/master/LICENSE @@ -376,7 +376,7 @@ doc = d.documentElement; g = { - VERSION: '1.9.2.7', + VERSION: '1.9.2.8', NAMESPACE: '4chan X.', NAME: '4chan X', FAQ: 'https://github.com/ccd0/4chan-x/wiki/Frequently-Asked-Questions', @@ -692,15 +692,6 @@ } }; - $.one = function(el, events, handler) { - var handler2; - handler2 = function(e) { - $.off(el, events, handler2); - return handler.call(this, e); - }; - return $.on(el, events, handler2); - }; - $.event = function(event, detail, root) { if (root == null) { root = d; @@ -8658,25 +8649,30 @@ if (g.VIEW === 'catalog') { return; } - if (!(Conf["Image Prefetching"] || Conf["Replace JPG"] || Conf["Replace PNG"] || Conf["Replace GIF"] || Conf["Replace WEBM"])) { + if (!(Conf['Image Prefetching'] || Conf['Replace JPG'] || Conf['Replace PNG'] || Conf['Replace GIF'] || Conf['Replace WEBM'])) { return; } Post.callbacks.push({ name: 'Image Replace', cb: this.node }); - if (Conf['Replace WEBM'] && Conf['Autoplay']) { - $.on(d, 'scroll visibilitychange', function() { + $.on(d, 'PostsInserted', function() { + return g.posts.forEach(ImageLoader.prefetch); + }); + if (Conf['Replace WEBM']) { + $.on(d, 'scroll visibilitychange 4chanXInitFinished PostsInserted', function() { + var qpClone, _ref; + qpClone = (_ref = $.id('qp')) != null ? _ref.firstElementChild : void 0; return g.posts.forEach(function(post) { - var thumb, _i, _len, _ref, _ref1; - _ref = [post].concat(__slice.call(post.clones)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - post = _ref[_i]; - if (!((_ref1 = post.file) != null ? _ref1.videoThumb : void 0)) { + var thumb, _i, _len, _ref1, _ref2; + _ref1 = [post].concat(__slice.call(post.clones)); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + post = _ref1[_i]; + if (!((_ref2 = post.file) != null ? _ref2.videoThumb : void 0)) { continue; } thumb = post.file.thumb; - if (Header.isNodeVisible(thumb)) { + if (Header.isNodeVisible(thumb) || post.nodes.root === qpClone) { thumb.play(); } else { thumb.pause(); @@ -8685,16 +8681,6 @@ }); }); } - $.on(d, 'PostsInserted', function() { - var thumb, thumbsToPlay, _i, _len; - thumbsToPlay = ImageLoader.thumbsToPlay; - ImageLoader.thumbsToPlay = []; - for (_i = 0, _len = thumbsToPlay.length; _i < _len; _i++) { - thumb = thumbsToPlay[_i]; - ImageLoader.play(thumb); - } - return g.posts.forEach(ImageLoader.prefetch); - }); if (!Conf['Image Prefetching']) { return; } @@ -8713,23 +8699,47 @@ }); }, node: function() { - var _ref; - if (this.isClone) { - if ((_ref = this.file) != null ? _ref.videoThumb : void 0) { - return ImageLoader.play(this.file.thumb); - } - } else { - return ImageLoader.prefetch(this); + if (this.isClone || !this.file) { + return; } + if (Conf['Replace WEBM'] && this.file.isVideo) { + ImageLoader.replaceVideo(this); + } + return ImageLoader.prefetch(this); + }, + replaceVideo: function(post) { + var attr, file, thumb, video, _i, _len, _ref; + file = post.file; + thumb = file.thumb; + video = $.el('video', { + preload: 'none', + loop: true, + poster: thumb.src, + textContent: thumb.alt, + className: thumb.className + }); + video.dataset.md5 = thumb.dataset.md5; + _ref = ['height', 'width', 'maxHeight', 'maxWidth']; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + attr = _ref[_i]; + video.style[attr] = thumb.style[attr]; + } + video.src = file.URL; + if (Conf['Image Hover']) { + $.on(video, 'mouseover', ImageHover.mouseover); + } + $.replace(thumb, video); + file.thumb = video; + return file.videoThumb = true; }, prefetch: function(post) { - var URL, el, file, isImage, isVideo, match, replace, thumb, type; + var URL, clone, el, file, isImage, isVideo, match, replace, thumb, type, _i, _len, _ref; file = post.file; if (!file) { return; } isImage = file.isImage, isVideo = file.isVideo, thumb = file.thumb, URL = file.URL; - if (!(isImage || isVideo) || post.isHidden || post.thread.isHidden || file.isPrefetched) { + if (file.isPrefetched || !(isImage || isVideo) || post.isHidden || post.thread.isHidden) { return; } type = (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) === 'JPEG' ? 'JPG' : match; @@ -8743,108 +8753,33 @@ return; } file.isPrefetched = true; - el = $.el(isImage ? 'img' : 'video'); - if (replace) { - if (isImage) { - $.on(el, 'load', (function(_this) { - return function() { - return ImageLoader.replaceImage(post); - }; - })(this)); - } else { - $.one(el, 'loadeddata', (function(_this) { - return function() { - return ImageLoader.replaceVideo(post, el); - }; - })(this)); - } - } - return ImageLoader.queueDownload(el, URL); - }, - queueDownload: (function() { - var busy, items, load; - busy = false; - items = []; - load = function(el, url) { - $.one(el, 'load loadedmetadata error', function() { - var el2, item, url2; - busy = false; - if (item = items.shift()) { - el2 = item[0], url2 = item[1]; - return load(el2, url2); - } - }); - el.src = url; - return busy = true; - }; - return function(el, url) { - if (busy) { - return items.push([el, url]); - } else { - return load(el, url); - } - }; - })(), - replaceImage: function(post) { - var _i, _len, _ref; - _ref = [post].concat(__slice.call(post.clones)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - post = _ref[_i]; - post.file.thumb.src = post.file.URL; - } - }, - replaceVideo: function(post, video) { - var clone, file, style, thumb, video2, _i, _len, _ref; - file = post.file; - thumb = file.thumb; - style = thumb.style; - if (!post.isClone) { + if (file.videoThumb) { _ref = post.clones; for (_i = 0, _len = _ref.length; _i < _len; _i++) { clone = _ref[_i]; - video2 = $.el('video'); - $.one(video2, 'loadeddata', (function(_this) { - return function() { - return ImageLoader.replaceVideo(clone, video2); - }; - })(this)); - video2.src = video.src; + clone.file.thumb.preload = 'auto'; + } + thumb.preload = 'auto'; + if (typeof chrome === "undefined" || chrome === null) { + $.on(thumb, 'loadeddata', function() { + return this.removeAttribute('poster'); + }); } - } - if (typeof chrome !== "undefined" && chrome !== null) { - video.poster = thumb.src; - } - video.loop = true; - video.textContent = thumb.alt; - video.dataset.md5 = thumb.dataset.md5; - video.style.height = style.height; - video.style.width = style.width; - video.style.maxHeight = style.maxHeight; - video.style.maxWidth = style.maxWidth; - video.className = thumb.className; - if (Conf['Image Hover']) { - $.on(video, 'mouseover', ImageHover.mouseover); - } - $.replace(thumb, video); - file.thumb = video; - file.videoThumb = true; - if (doc.contains(video) || post.isClone) { - return ImageLoader.play(video); - } - }, - thumbsToPlay: [], - play: function(thumb) { - var _ref; - if (!Conf['Autoplay']) { return; } - if (doc.contains(thumb)) { - if (Header.isNodeVisible(thumb) || ((_ref = $.id('qp')) != null ? _ref.contains(thumb) : void 0)) { - return thumb.play(); - } - } else { - return ImageLoader.thumbsToPlay.push(thumb); + el = $.el(isImage ? 'img' : 'video'); + if (replace && isImage) { + $.on(el, 'load', function() { + var _j, _len1, _ref1; + _ref1 = post.clones; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + clone = _ref1[_j]; + clone.file.thumb.src = URL; + } + return thumb.src = URL; + }); } + return el.src = URL; } }; @@ -12961,7 +12896,7 @@ className: 'dialog' }); $.extend(dialog, { - innerHTML: "
" + innerHTML: "
" }); $.on($('.export', Settings.dialog), 'click', Settings["export"]); $.on($('.import', Settings.dialog), 'click', Settings["import"]); diff --git a/builds/4chan-X-noupdate.crx b/builds/4chan-X-noupdate.crx index 8140f855f..7a7e6e73b 100644 Binary files a/builds/4chan-X-noupdate.crx and b/builds/4chan-X-noupdate.crx differ diff --git a/builds/4chan-X-noupdate.user.js b/builds/4chan-X-noupdate.user.js index a172ea36e..abf653682 100644 --- a/builds/4chan-X-noupdate.user.js +++ b/builds/4chan-X-noupdate.user.js @@ -1,7 +1,7 @@ // Generated by CoffeeScript // ==UserScript== // @name 4chan X -// @version 1.9.2.7 +// @version 1.9.2.8 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -23,7 +23,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.9.2.7 +* 4chan X - Version 1.9.2.8 * * Licensed under the MIT license. * https://github.com/ccd0/4chan-x/blob/master/LICENSE @@ -375,7 +375,7 @@ doc = d.documentElement; g = { - VERSION: '1.9.2.7', + VERSION: '1.9.2.8', NAMESPACE: '4chan X.', NAME: '4chan X', FAQ: 'https://github.com/ccd0/4chan-x/wiki/Frequently-Asked-Questions', @@ -691,15 +691,6 @@ } }; - $.one = function(el, events, handler) { - var handler2; - handler2 = function(e) { - $.off(el, events, handler2); - return handler.call(this, e); - }; - return $.on(el, events, handler2); - }; - $.event = function(event, detail, root) { if (root == null) { root = d; @@ -8657,25 +8648,30 @@ if (g.VIEW === 'catalog') { return; } - if (!(Conf["Image Prefetching"] || Conf["Replace JPG"] || Conf["Replace PNG"] || Conf["Replace GIF"] || Conf["Replace WEBM"])) { + if (!(Conf['Image Prefetching'] || Conf['Replace JPG'] || Conf['Replace PNG'] || Conf['Replace GIF'] || Conf['Replace WEBM'])) { return; } Post.callbacks.push({ name: 'Image Replace', cb: this.node }); - if (Conf['Replace WEBM'] && Conf['Autoplay']) { - $.on(d, 'scroll visibilitychange', function() { + $.on(d, 'PostsInserted', function() { + return g.posts.forEach(ImageLoader.prefetch); + }); + if (Conf['Replace WEBM']) { + $.on(d, 'scroll visibilitychange 4chanXInitFinished PostsInserted', function() { + var qpClone, _ref; + qpClone = (_ref = $.id('qp')) != null ? _ref.firstElementChild : void 0; return g.posts.forEach(function(post) { - var thumb, _i, _len, _ref, _ref1; - _ref = [post].concat(__slice.call(post.clones)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - post = _ref[_i]; - if (!((_ref1 = post.file) != null ? _ref1.videoThumb : void 0)) { + var thumb, _i, _len, _ref1, _ref2; + _ref1 = [post].concat(__slice.call(post.clones)); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + post = _ref1[_i]; + if (!((_ref2 = post.file) != null ? _ref2.videoThumb : void 0)) { continue; } thumb = post.file.thumb; - if (Header.isNodeVisible(thumb)) { + if (Header.isNodeVisible(thumb) || post.nodes.root === qpClone) { thumb.play(); } else { thumb.pause(); @@ -8684,16 +8680,6 @@ }); }); } - $.on(d, 'PostsInserted', function() { - var thumb, thumbsToPlay, _i, _len; - thumbsToPlay = ImageLoader.thumbsToPlay; - ImageLoader.thumbsToPlay = []; - for (_i = 0, _len = thumbsToPlay.length; _i < _len; _i++) { - thumb = thumbsToPlay[_i]; - ImageLoader.play(thumb); - } - return g.posts.forEach(ImageLoader.prefetch); - }); if (!Conf['Image Prefetching']) { return; } @@ -8712,23 +8698,47 @@ }); }, node: function() { - var _ref; - if (this.isClone) { - if ((_ref = this.file) != null ? _ref.videoThumb : void 0) { - return ImageLoader.play(this.file.thumb); - } - } else { - return ImageLoader.prefetch(this); + if (this.isClone || !this.file) { + return; } + if (Conf['Replace WEBM'] && this.file.isVideo) { + ImageLoader.replaceVideo(this); + } + return ImageLoader.prefetch(this); + }, + replaceVideo: function(post) { + var attr, file, thumb, video, _i, _len, _ref; + file = post.file; + thumb = file.thumb; + video = $.el('video', { + preload: 'none', + loop: true, + poster: thumb.src, + textContent: thumb.alt, + className: thumb.className + }); + video.dataset.md5 = thumb.dataset.md5; + _ref = ['height', 'width', 'maxHeight', 'maxWidth']; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + attr = _ref[_i]; + video.style[attr] = thumb.style[attr]; + } + video.src = file.URL; + if (Conf['Image Hover']) { + $.on(video, 'mouseover', ImageHover.mouseover); + } + $.replace(thumb, video); + file.thumb = video; + return file.videoThumb = true; }, prefetch: function(post) { - var URL, el, file, isImage, isVideo, match, replace, thumb, type; + var URL, clone, el, file, isImage, isVideo, match, replace, thumb, type, _i, _len, _ref; file = post.file; if (!file) { return; } isImage = file.isImage, isVideo = file.isVideo, thumb = file.thumb, URL = file.URL; - if (!(isImage || isVideo) || post.isHidden || post.thread.isHidden || file.isPrefetched) { + if (file.isPrefetched || !(isImage || isVideo) || post.isHidden || post.thread.isHidden) { return; } type = (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) === 'JPEG' ? 'JPG' : match; @@ -8742,108 +8752,33 @@ return; } file.isPrefetched = true; - el = $.el(isImage ? 'img' : 'video'); - if (replace) { - if (isImage) { - $.on(el, 'load', (function(_this) { - return function() { - return ImageLoader.replaceImage(post); - }; - })(this)); - } else { - $.one(el, 'loadeddata', (function(_this) { - return function() { - return ImageLoader.replaceVideo(post, el); - }; - })(this)); - } - } - return ImageLoader.queueDownload(el, URL); - }, - queueDownload: (function() { - var busy, items, load; - busy = false; - items = []; - load = function(el, url) { - $.one(el, 'load loadedmetadata error', function() { - var el2, item, url2; - busy = false; - if (item = items.shift()) { - el2 = item[0], url2 = item[1]; - return load(el2, url2); - } - }); - el.src = url; - return busy = true; - }; - return function(el, url) { - if (busy) { - return items.push([el, url]); - } else { - return load(el, url); - } - }; - })(), - replaceImage: function(post) { - var _i, _len, _ref; - _ref = [post].concat(__slice.call(post.clones)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - post = _ref[_i]; - post.file.thumb.src = post.file.URL; - } - }, - replaceVideo: function(post, video) { - var clone, file, style, thumb, video2, _i, _len, _ref; - file = post.file; - thumb = file.thumb; - style = thumb.style; - if (!post.isClone) { + if (file.videoThumb) { _ref = post.clones; for (_i = 0, _len = _ref.length; _i < _len; _i++) { clone = _ref[_i]; - video2 = $.el('video'); - $.one(video2, 'loadeddata', (function(_this) { - return function() { - return ImageLoader.replaceVideo(clone, video2); - }; - })(this)); - video2.src = video.src; + clone.file.thumb.preload = 'auto'; + } + thumb.preload = 'auto'; + if (typeof chrome === "undefined" || chrome === null) { + $.on(thumb, 'loadeddata', function() { + return this.removeAttribute('poster'); + }); } - } - if (typeof chrome !== "undefined" && chrome !== null) { - video.poster = thumb.src; - } - video.loop = true; - video.textContent = thumb.alt; - video.dataset.md5 = thumb.dataset.md5; - video.style.height = style.height; - video.style.width = style.width; - video.style.maxHeight = style.maxHeight; - video.style.maxWidth = style.maxWidth; - video.className = thumb.className; - if (Conf['Image Hover']) { - $.on(video, 'mouseover', ImageHover.mouseover); - } - $.replace(thumb, video); - file.thumb = video; - file.videoThumb = true; - if (doc.contains(video) || post.isClone) { - return ImageLoader.play(video); - } - }, - thumbsToPlay: [], - play: function(thumb) { - var _ref; - if (!Conf['Autoplay']) { return; } - if (doc.contains(thumb)) { - if (Header.isNodeVisible(thumb) || ((_ref = $.id('qp')) != null ? _ref.contains(thumb) : void 0)) { - return thumb.play(); - } - } else { - return ImageLoader.thumbsToPlay.push(thumb); + el = $.el(isImage ? 'img' : 'video'); + if (replace && isImage) { + $.on(el, 'load', function() { + var _j, _len1, _ref1; + _ref1 = post.clones; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + clone = _ref1[_j]; + clone.file.thumb.src = URL; + } + return thumb.src = URL; + }); } + return el.src = URL; } }; @@ -12960,7 +12895,7 @@ className: 'dialog' }); $.extend(dialog, { - innerHTML: "
" + innerHTML: "
" }); $.on($('.export', Settings.dialog), 'click', Settings["export"]); $.on($('.import', Settings.dialog), 'click', Settings["import"]); diff --git a/builds/4chan-X.crx b/builds/4chan-X.crx index 6396f2582..1e9be5159 100644 Binary files a/builds/4chan-X.crx and b/builds/4chan-X.crx differ diff --git a/builds/4chan-X.meta.js b/builds/4chan-X.meta.js index 5fb9aecdf..1986dd3bb 100644 --- a/builds/4chan-X.meta.js +++ b/builds/4chan-X.meta.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X -// @version 1.9.2.7 +// @version 1.9.2.8 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index df6648f66..4c8335c74 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -1,7 +1,7 @@ // Generated by CoffeeScript // ==UserScript== // @name 4chan X -// @version 1.9.2.7 +// @version 1.9.2.8 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -24,7 +24,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.9.2.7 +* 4chan X - Version 1.9.2.8 * * Licensed under the MIT license. * https://github.com/ccd0/4chan-x/blob/master/LICENSE @@ -376,7 +376,7 @@ doc = d.documentElement; g = { - VERSION: '1.9.2.7', + VERSION: '1.9.2.8', NAMESPACE: '4chan X.', NAME: '4chan X', FAQ: 'https://github.com/ccd0/4chan-x/wiki/Frequently-Asked-Questions', @@ -692,15 +692,6 @@ } }; - $.one = function(el, events, handler) { - var handler2; - handler2 = function(e) { - $.off(el, events, handler2); - return handler.call(this, e); - }; - return $.on(el, events, handler2); - }; - $.event = function(event, detail, root) { if (root == null) { root = d; @@ -8658,25 +8649,30 @@ if (g.VIEW === 'catalog') { return; } - if (!(Conf["Image Prefetching"] || Conf["Replace JPG"] || Conf["Replace PNG"] || Conf["Replace GIF"] || Conf["Replace WEBM"])) { + if (!(Conf['Image Prefetching'] || Conf['Replace JPG'] || Conf['Replace PNG'] || Conf['Replace GIF'] || Conf['Replace WEBM'])) { return; } Post.callbacks.push({ name: 'Image Replace', cb: this.node }); - if (Conf['Replace WEBM'] && Conf['Autoplay']) { - $.on(d, 'scroll visibilitychange', function() { + $.on(d, 'PostsInserted', function() { + return g.posts.forEach(ImageLoader.prefetch); + }); + if (Conf['Replace WEBM']) { + $.on(d, 'scroll visibilitychange 4chanXInitFinished PostsInserted', function() { + var qpClone, _ref; + qpClone = (_ref = $.id('qp')) != null ? _ref.firstElementChild : void 0; return g.posts.forEach(function(post) { - var thumb, _i, _len, _ref, _ref1; - _ref = [post].concat(__slice.call(post.clones)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - post = _ref[_i]; - if (!((_ref1 = post.file) != null ? _ref1.videoThumb : void 0)) { + var thumb, _i, _len, _ref1, _ref2; + _ref1 = [post].concat(__slice.call(post.clones)); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + post = _ref1[_i]; + if (!((_ref2 = post.file) != null ? _ref2.videoThumb : void 0)) { continue; } thumb = post.file.thumb; - if (Header.isNodeVisible(thumb)) { + if (Header.isNodeVisible(thumb) || post.nodes.root === qpClone) { thumb.play(); } else { thumb.pause(); @@ -8685,16 +8681,6 @@ }); }); } - $.on(d, 'PostsInserted', function() { - var thumb, thumbsToPlay, _i, _len; - thumbsToPlay = ImageLoader.thumbsToPlay; - ImageLoader.thumbsToPlay = []; - for (_i = 0, _len = thumbsToPlay.length; _i < _len; _i++) { - thumb = thumbsToPlay[_i]; - ImageLoader.play(thumb); - } - return g.posts.forEach(ImageLoader.prefetch); - }); if (!Conf['Image Prefetching']) { return; } @@ -8713,23 +8699,47 @@ }); }, node: function() { - var _ref; - if (this.isClone) { - if ((_ref = this.file) != null ? _ref.videoThumb : void 0) { - return ImageLoader.play(this.file.thumb); - } - } else { - return ImageLoader.prefetch(this); + if (this.isClone || !this.file) { + return; } + if (Conf['Replace WEBM'] && this.file.isVideo) { + ImageLoader.replaceVideo(this); + } + return ImageLoader.prefetch(this); + }, + replaceVideo: function(post) { + var attr, file, thumb, video, _i, _len, _ref; + file = post.file; + thumb = file.thumb; + video = $.el('video', { + preload: 'none', + loop: true, + poster: thumb.src, + textContent: thumb.alt, + className: thumb.className + }); + video.dataset.md5 = thumb.dataset.md5; + _ref = ['height', 'width', 'maxHeight', 'maxWidth']; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + attr = _ref[_i]; + video.style[attr] = thumb.style[attr]; + } + video.src = file.URL; + if (Conf['Image Hover']) { + $.on(video, 'mouseover', ImageHover.mouseover); + } + $.replace(thumb, video); + file.thumb = video; + return file.videoThumb = true; }, prefetch: function(post) { - var URL, el, file, isImage, isVideo, match, replace, thumb, type; + var URL, clone, el, file, isImage, isVideo, match, replace, thumb, type, _i, _len, _ref; file = post.file; if (!file) { return; } isImage = file.isImage, isVideo = file.isVideo, thumb = file.thumb, URL = file.URL; - if (!(isImage || isVideo) || post.isHidden || post.thread.isHidden || file.isPrefetched) { + if (file.isPrefetched || !(isImage || isVideo) || post.isHidden || post.thread.isHidden) { return; } type = (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) === 'JPEG' ? 'JPG' : match; @@ -8743,108 +8753,33 @@ return; } file.isPrefetched = true; - el = $.el(isImage ? 'img' : 'video'); - if (replace) { - if (isImage) { - $.on(el, 'load', (function(_this) { - return function() { - return ImageLoader.replaceImage(post); - }; - })(this)); - } else { - $.one(el, 'loadeddata', (function(_this) { - return function() { - return ImageLoader.replaceVideo(post, el); - }; - })(this)); - } - } - return ImageLoader.queueDownload(el, URL); - }, - queueDownload: (function() { - var busy, items, load; - busy = false; - items = []; - load = function(el, url) { - $.one(el, 'load loadedmetadata error', function() { - var el2, item, url2; - busy = false; - if (item = items.shift()) { - el2 = item[0], url2 = item[1]; - return load(el2, url2); - } - }); - el.src = url; - return busy = true; - }; - return function(el, url) { - if (busy) { - return items.push([el, url]); - } else { - return load(el, url); - } - }; - })(), - replaceImage: function(post) { - var _i, _len, _ref; - _ref = [post].concat(__slice.call(post.clones)); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - post = _ref[_i]; - post.file.thumb.src = post.file.URL; - } - }, - replaceVideo: function(post, video) { - var clone, file, style, thumb, video2, _i, _len, _ref; - file = post.file; - thumb = file.thumb; - style = thumb.style; - if (!post.isClone) { + if (file.videoThumb) { _ref = post.clones; for (_i = 0, _len = _ref.length; _i < _len; _i++) { clone = _ref[_i]; - video2 = $.el('video'); - $.one(video2, 'loadeddata', (function(_this) { - return function() { - return ImageLoader.replaceVideo(clone, video2); - }; - })(this)); - video2.src = video.src; + clone.file.thumb.preload = 'auto'; + } + thumb.preload = 'auto'; + if (typeof chrome === "undefined" || chrome === null) { + $.on(thumb, 'loadeddata', function() { + return this.removeAttribute('poster'); + }); } - } - if (typeof chrome !== "undefined" && chrome !== null) { - video.poster = thumb.src; - } - video.loop = true; - video.textContent = thumb.alt; - video.dataset.md5 = thumb.dataset.md5; - video.style.height = style.height; - video.style.width = style.width; - video.style.maxHeight = style.maxHeight; - video.style.maxWidth = style.maxWidth; - video.className = thumb.className; - if (Conf['Image Hover']) { - $.on(video, 'mouseover', ImageHover.mouseover); - } - $.replace(thumb, video); - file.thumb = video; - file.videoThumb = true; - if (doc.contains(video) || post.isClone) { - return ImageLoader.play(video); - } - }, - thumbsToPlay: [], - play: function(thumb) { - var _ref; - if (!Conf['Autoplay']) { return; } - if (doc.contains(thumb)) { - if (Header.isNodeVisible(thumb) || ((_ref = $.id('qp')) != null ? _ref.contains(thumb) : void 0)) { - return thumb.play(); - } - } else { - return ImageLoader.thumbsToPlay.push(thumb); + el = $.el(isImage ? 'img' : 'video'); + if (replace && isImage) { + $.on(el, 'load', function() { + var _j, _len1, _ref1; + _ref1 = post.clones; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + clone = _ref1[_j]; + clone.file.thumb.src = URL; + } + return thumb.src = URL; + }); } + return el.src = URL; } }; @@ -12961,7 +12896,7 @@ className: 'dialog' }); $.extend(dialog, { - innerHTML: "
" + innerHTML: "
" }); $.on($('.export', Settings.dialog), 'click', Settings["export"]); $.on($('.import', Settings.dialog), 'click', Settings["import"]); diff --git a/builds/4chan-X.zip b/builds/4chan-X.zip index aa47b2070..77a498dfe 100644 Binary files a/builds/4chan-X.zip and b/builds/4chan-X.zip differ diff --git a/builds/updates-beta.xml b/builds/updates-beta.xml index d5246aa51..9a8ce7cb5 100644 --- a/builds/updates-beta.xml +++ b/builds/updates-beta.xml @@ -1,7 +1,7 @@ - + diff --git a/builds/updates.xml b/builds/updates.xml index 626aef6d4..a466d1377 100644 --- a/builds/updates.xml +++ b/builds/updates.xml @@ -1,7 +1,7 @@ - + diff --git a/package.json b/package.json index 76f3fe848..6dbc26a3c 100755 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "Cross-browser userscript for maximum lurking on 4chan.", "meta": { "name": "4chan X", - "version": "1.9.2.7", + "version": "1.9.2.8", "repo": "https://github.com/ccd0/4chan-x/", "page": "https://github.com/ccd0/4chan-x", "downloads": "https://ccd0.github.io/4chan-x/builds/",