diff --git a/CHANGELOG.md b/CHANGELOG.md index 78ba140c6..e629c4723 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### v1.9.2.3 +*2014-09-07* + +**ccd0** +- Thumbnail replacement / preloading / WebM bugfixes. +- Embedded videos from mediacru.sh are no longer autoplayed and have controls. + ### v1.9.2.2 *2014-09-07* diff --git a/LICENSE b/LICENSE index 66717bd06..3e0e1b6ee 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.9.2.2 +* 4chan X - Version 1.9.2.3 * * 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 dd71316ae..ed8e9e1e8 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 b8da61ed6..67e3f7517 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.2 +// @version 1.9.2.3 // @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 c2e41c801..2336e9409 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.2 +// @version 1.9.2.3 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -24,7 +24,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.9.2.2 +* 4chan X - Version 1.9.2.3 * * 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.2', + VERSION: '1.9.2.3', NAMESPACE: '4chan X.', NAME: '4chan X', FAQ: 'https://github.com/ccd0/4chan-x/wiki/Frequently-Asked-Questions', @@ -691,6 +691,15 @@ } }; + $.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; @@ -2257,6 +2266,9 @@ }, isNodeVisible: function(node) { var height; + if (d.hidden || !doc.contains(node)) { + return false; + } height = node.getBoundingClientRect().height; return Header.getTopOf(node) + height >= 0 && Header.getBottomOf(node) + height >= 0; }, @@ -8162,7 +8174,7 @@ ImageExpand.setupVideoCB(this); return ImageExpand.setupVideo(this, !((_ref = this.origin.file.fullImage) != null ? _ref.paused : void 0) || this.origin.file.wasPlaying, this.file.fullImage.controls); } - } else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { + } else if (ImageExpand.on && !this.isHidden && !this.isFetchedQuote && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { return ImageExpand.expand(this); } }, @@ -8216,18 +8228,22 @@ }, playVideos: function(e) { return g.posts.forEach(function(post) { - var video, visible; - if (!(post.file && post.file.isVideo && post.file.isExpanded)) { - return; - } - video = post.file.fullImage; - visible = !d.hidden && Header.isNodeVisible(video); - if (visible && post.file.wasPlaying) { - delete post.file.wasPlaying; - video.play(); - } else if (!visible && !video.paused) { - post.file.wasPlaying = true; - video.pause(); + var video, visible, _i, _len, _ref; + _ref = [post].concat(__slice.call(post.clones)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + post = _ref[_i]; + if (!(post.file && post.file.isVideo && post.file.isExpanded)) { + continue; + } + video = post.file.fullImage; + visible = Header.isNodeVisible(video); + if (visible && post.file.wasPlaying) { + delete post.file.wasPlaying; + video.play(); + } else if (!visible && !video.paused) { + post.file.wasPlaying = true; + video.pause(); + } } }); }, @@ -8634,14 +8650,18 @@ if (Conf['Replace WEBM'] && Conf['Autoplay']) { $.on(d, 'scroll visibilitychange', function() { return g.posts.forEach(function(post) { - var thumb, visible, _ref; - if ((_ref = post.file) != null ? _ref.videoThumb : void 0) { + 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)) { + continue; + } thumb = post.file.thumb; - visible = !d.hidden && Header.isNodeVisible(thumb); - if (visible) { - return thumb.play(); + if (Header.isNodeVisible(thumb)) { + thumb.play(); } else { - return thumb.pause(); + thumb.pause(); } } }); @@ -8661,7 +8681,7 @@ }); }, node: function(force) { - var URL, cb, el, isImage, isVideo, match, prefetch, replace, style, thumb, type, _ref; + var URL, el, isImage, isVideo, match, prefetch, replace, thumb, type, _ref; if (!this.file) { return; } @@ -8672,7 +8692,6 @@ if (this.isClone || this.isHidden || this.thread.isHidden || !(isImage || isVideo)) { return; } - style = thumb.style; type = (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) === 'JPEG' ? 'JPG' : match; replace = Conf["Replace " + type] && !/spoiler/.test(thumb.src); prefetch = (Conf['prefetch'] && g.VIEW === 'thread') || force; @@ -8682,78 +8701,93 @@ el = $.el(isImage ? 'img' : 'video'); if (replace) { if (this.file.isSpoiler) { - style.maxHeight = style.maxWidth = this.isReply ? '125px' : '250px'; + thumb.style.maxHeight = thumb.style.maxWidth = this.isReply ? '125px' : '250px'; } - if (isVideo) { - el.textContent = thumb.alt; - el.dataset.md5 = thumb.dataset.md5; - el.style.height = style.height; - el.style.width = style.width; - el.style.maxHeight = style.maxHeight; - el.style.maxWidth = style.maxWidth; - el.loop = true; - el.className = thumb.className; + if (isImage) { + $.on(el, 'load', (function(_this) { + return function() { + return ImageLoader.replaceImage(_this); + }; + })(this)); + } else { + $.one(el, 'loadeddata', (function(_this) { + return function() { + return ImageLoader.replaceVideo(_this, el); + }; + })(this)); } - cb = (function(_this) { - return function() { - $.off(el, 'load loadeddata', cb); - return ImageLoader.replace(_this, el); - }; - })(this); - $.on(el, 'load loadeddata', cb); - } - ImageLoader.queue.push([el, URL]); - if (!ImageLoader.busy) { - return ImageLoader.next(); } + return ImageLoader.queueDownload(el, URL); }, - busy: false, - queue: [], - loadend: function() { - $.off(this, 'load loadeddata error', ImageLoader.loadend); - ImageLoader.busy = false; - return ImageLoader.next(); - }, - next: function() { - var el, item, url; - if (ImageLoader.busy) { - return; - } - if (item = ImageLoader.queue.shift()) { - el = item[0], url = item[1]; - $.on(el, 'load loadeddata error', ImageLoader.loadend); - setTimeout((function() { - return ImageLoader.loadend.call(el); - }), $.SECOND); + 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 ImageLoader.busy = true; + 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; } }, - replace: function(post, el) { - var clone, file, isVideo, thumb, _i, _len, _ref; + replaceVideo: function(post, video) { + var clone, file, style, thumb, video2, _i, _len, _ref; file = post.file; - isVideo = file.isVideo, thumb = file.thumb; + thumb = file.thumb; + style = thumb.style; if (!post.isClone) { _ref = post.clones; for (_i = 0, _len = _ref.length; _i < _len; _i++) { clone = _ref[_i]; - if (!isVideo || !$.hasClass(clone.nodes.root.parentNode, 'dialog')) { - ImageLoader.replace(clone, el.cloneNode(true)); - } + video2 = $.el('video'); + $.one(video2, 'loadeddata', (function(_this) { + return function() { + return ImageLoader.replaceVideo(clone, video2); + }; + })(this)); + video2.src = video.src; } } - if (isVideo) { - if (Conf['Image Hover']) { - $.on(el, 'mouseover', ImageHover.mouseover); - } - $.replace(thumb, el); - file.videoThumb = true; - file.thumb = el; - if (!post.isFetchedQuote) { - return ImageLoader.play(el); - } - } else { - return thumb.src = file.URL; + 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 (!post.isFetchedQuote) { + return ImageLoader.play(video); } }, play: function(video) { @@ -8761,7 +8795,7 @@ return $.asap((function() { return doc.contains(video); }), function() { - if (!d.hidden && Header.isNodeVisible(video)) { + if (Header.isNodeVisible(video)) { return video.play(); } }); @@ -9301,7 +9335,7 @@ case 'video/webm': case 'video/ogv': $.extend(el, { - innerHTML: "" + innerHTML: "" }); _ref1 = ['mp4', 'webm']; _results = []; @@ -12888,7 +12922,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 7b565f02d..17e92735c 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 365227047..6be2bf7e0 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.2 +// @version 1.9.2.3 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -23,7 +23,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.9.2.2 +* 4chan X - Version 1.9.2.3 * * 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.2', + VERSION: '1.9.2.3', NAMESPACE: '4chan X.', NAME: '4chan X', FAQ: 'https://github.com/ccd0/4chan-x/wiki/Frequently-Asked-Questions', @@ -690,6 +690,15 @@ } }; + $.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; @@ -2256,6 +2265,9 @@ }, isNodeVisible: function(node) { var height; + if (d.hidden || !doc.contains(node)) { + return false; + } height = node.getBoundingClientRect().height; return Header.getTopOf(node) + height >= 0 && Header.getBottomOf(node) + height >= 0; }, @@ -8161,7 +8173,7 @@ ImageExpand.setupVideoCB(this); return ImageExpand.setupVideo(this, !((_ref = this.origin.file.fullImage) != null ? _ref.paused : void 0) || this.origin.file.wasPlaying, this.file.fullImage.controls); } - } else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { + } else if (ImageExpand.on && !this.isHidden && !this.isFetchedQuote && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { return ImageExpand.expand(this); } }, @@ -8215,18 +8227,22 @@ }, playVideos: function(e) { return g.posts.forEach(function(post) { - var video, visible; - if (!(post.file && post.file.isVideo && post.file.isExpanded)) { - return; - } - video = post.file.fullImage; - visible = !d.hidden && Header.isNodeVisible(video); - if (visible && post.file.wasPlaying) { - delete post.file.wasPlaying; - video.play(); - } else if (!visible && !video.paused) { - post.file.wasPlaying = true; - video.pause(); + var video, visible, _i, _len, _ref; + _ref = [post].concat(__slice.call(post.clones)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + post = _ref[_i]; + if (!(post.file && post.file.isVideo && post.file.isExpanded)) { + continue; + } + video = post.file.fullImage; + visible = Header.isNodeVisible(video); + if (visible && post.file.wasPlaying) { + delete post.file.wasPlaying; + video.play(); + } else if (!visible && !video.paused) { + post.file.wasPlaying = true; + video.pause(); + } } }); }, @@ -8633,14 +8649,18 @@ if (Conf['Replace WEBM'] && Conf['Autoplay']) { $.on(d, 'scroll visibilitychange', function() { return g.posts.forEach(function(post) { - var thumb, visible, _ref; - if ((_ref = post.file) != null ? _ref.videoThumb : void 0) { + 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)) { + continue; + } thumb = post.file.thumb; - visible = !d.hidden && Header.isNodeVisible(thumb); - if (visible) { - return thumb.play(); + if (Header.isNodeVisible(thumb)) { + thumb.play(); } else { - return thumb.pause(); + thumb.pause(); } } }); @@ -8660,7 +8680,7 @@ }); }, node: function(force) { - var URL, cb, el, isImage, isVideo, match, prefetch, replace, style, thumb, type, _ref; + var URL, el, isImage, isVideo, match, prefetch, replace, thumb, type, _ref; if (!this.file) { return; } @@ -8671,7 +8691,6 @@ if (this.isClone || this.isHidden || this.thread.isHidden || !(isImage || isVideo)) { return; } - style = thumb.style; type = (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) === 'JPEG' ? 'JPG' : match; replace = Conf["Replace " + type] && !/spoiler/.test(thumb.src); prefetch = (Conf['prefetch'] && g.VIEW === 'thread') || force; @@ -8681,78 +8700,93 @@ el = $.el(isImage ? 'img' : 'video'); if (replace) { if (this.file.isSpoiler) { - style.maxHeight = style.maxWidth = this.isReply ? '125px' : '250px'; + thumb.style.maxHeight = thumb.style.maxWidth = this.isReply ? '125px' : '250px'; } - if (isVideo) { - el.textContent = thumb.alt; - el.dataset.md5 = thumb.dataset.md5; - el.style.height = style.height; - el.style.width = style.width; - el.style.maxHeight = style.maxHeight; - el.style.maxWidth = style.maxWidth; - el.loop = true; - el.className = thumb.className; + if (isImage) { + $.on(el, 'load', (function(_this) { + return function() { + return ImageLoader.replaceImage(_this); + }; + })(this)); + } else { + $.one(el, 'loadeddata', (function(_this) { + return function() { + return ImageLoader.replaceVideo(_this, el); + }; + })(this)); } - cb = (function(_this) { - return function() { - $.off(el, 'load loadeddata', cb); - return ImageLoader.replace(_this, el); - }; - })(this); - $.on(el, 'load loadeddata', cb); - } - ImageLoader.queue.push([el, URL]); - if (!ImageLoader.busy) { - return ImageLoader.next(); } + return ImageLoader.queueDownload(el, URL); }, - busy: false, - queue: [], - loadend: function() { - $.off(this, 'load loadeddata error', ImageLoader.loadend); - ImageLoader.busy = false; - return ImageLoader.next(); - }, - next: function() { - var el, item, url; - if (ImageLoader.busy) { - return; - } - if (item = ImageLoader.queue.shift()) { - el = item[0], url = item[1]; - $.on(el, 'load loadeddata error', ImageLoader.loadend); - setTimeout((function() { - return ImageLoader.loadend.call(el); - }), $.SECOND); + 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 ImageLoader.busy = true; + 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; } }, - replace: function(post, el) { - var clone, file, isVideo, thumb, _i, _len, _ref; + replaceVideo: function(post, video) { + var clone, file, style, thumb, video2, _i, _len, _ref; file = post.file; - isVideo = file.isVideo, thumb = file.thumb; + thumb = file.thumb; + style = thumb.style; if (!post.isClone) { _ref = post.clones; for (_i = 0, _len = _ref.length; _i < _len; _i++) { clone = _ref[_i]; - if (!isVideo || !$.hasClass(clone.nodes.root.parentNode, 'dialog')) { - ImageLoader.replace(clone, el.cloneNode(true)); - } + video2 = $.el('video'); + $.one(video2, 'loadeddata', (function(_this) { + return function() { + return ImageLoader.replaceVideo(clone, video2); + }; + })(this)); + video2.src = video.src; } } - if (isVideo) { - if (Conf['Image Hover']) { - $.on(el, 'mouseover', ImageHover.mouseover); - } - $.replace(thumb, el); - file.videoThumb = true; - file.thumb = el; - if (!post.isFetchedQuote) { - return ImageLoader.play(el); - } - } else { - return thumb.src = file.URL; + 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 (!post.isFetchedQuote) { + return ImageLoader.play(video); } }, play: function(video) { @@ -8760,7 +8794,7 @@ return $.asap((function() { return doc.contains(video); }), function() { - if (!d.hidden && Header.isNodeVisible(video)) { + if (Header.isNodeVisible(video)) { return video.play(); } }); @@ -9300,7 +9334,7 @@ case 'video/webm': case 'video/ogv': $.extend(el, { - innerHTML: "" + innerHTML: "" }); _ref1 = ['mp4', 'webm']; _results = []; @@ -12887,7 +12921,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 4f5e91c1a..515803262 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 ed0fbbd3c..641ee69b3 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.2 +// @version 1.9.2.3 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 3ac2f2c0c..52f88fe2c 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.2 +// @version 1.9.2.3 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -24,7 +24,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.9.2.2 +* 4chan X - Version 1.9.2.3 * * 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.2', + VERSION: '1.9.2.3', NAMESPACE: '4chan X.', NAME: '4chan X', FAQ: 'https://github.com/ccd0/4chan-x/wiki/Frequently-Asked-Questions', @@ -691,6 +691,15 @@ } }; + $.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; @@ -2257,6 +2266,9 @@ }, isNodeVisible: function(node) { var height; + if (d.hidden || !doc.contains(node)) { + return false; + } height = node.getBoundingClientRect().height; return Header.getTopOf(node) + height >= 0 && Header.getBottomOf(node) + height >= 0; }, @@ -8162,7 +8174,7 @@ ImageExpand.setupVideoCB(this); return ImageExpand.setupVideo(this, !((_ref = this.origin.file.fullImage) != null ? _ref.paused : void 0) || this.origin.file.wasPlaying, this.file.fullImage.controls); } - } else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { + } else if (ImageExpand.on && !this.isHidden && !this.isFetchedQuote && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { return ImageExpand.expand(this); } }, @@ -8216,18 +8228,22 @@ }, playVideos: function(e) { return g.posts.forEach(function(post) { - var video, visible; - if (!(post.file && post.file.isVideo && post.file.isExpanded)) { - return; - } - video = post.file.fullImage; - visible = !d.hidden && Header.isNodeVisible(video); - if (visible && post.file.wasPlaying) { - delete post.file.wasPlaying; - video.play(); - } else if (!visible && !video.paused) { - post.file.wasPlaying = true; - video.pause(); + var video, visible, _i, _len, _ref; + _ref = [post].concat(__slice.call(post.clones)); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + post = _ref[_i]; + if (!(post.file && post.file.isVideo && post.file.isExpanded)) { + continue; + } + video = post.file.fullImage; + visible = Header.isNodeVisible(video); + if (visible && post.file.wasPlaying) { + delete post.file.wasPlaying; + video.play(); + } else if (!visible && !video.paused) { + post.file.wasPlaying = true; + video.pause(); + } } }); }, @@ -8634,14 +8650,18 @@ if (Conf['Replace WEBM'] && Conf['Autoplay']) { $.on(d, 'scroll visibilitychange', function() { return g.posts.forEach(function(post) { - var thumb, visible, _ref; - if ((_ref = post.file) != null ? _ref.videoThumb : void 0) { + 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)) { + continue; + } thumb = post.file.thumb; - visible = !d.hidden && Header.isNodeVisible(thumb); - if (visible) { - return thumb.play(); + if (Header.isNodeVisible(thumb)) { + thumb.play(); } else { - return thumb.pause(); + thumb.pause(); } } }); @@ -8661,7 +8681,7 @@ }); }, node: function(force) { - var URL, cb, el, isImage, isVideo, match, prefetch, replace, style, thumb, type, _ref; + var URL, el, isImage, isVideo, match, prefetch, replace, thumb, type, _ref; if (!this.file) { return; } @@ -8672,7 +8692,6 @@ if (this.isClone || this.isHidden || this.thread.isHidden || !(isImage || isVideo)) { return; } - style = thumb.style; type = (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) === 'JPEG' ? 'JPG' : match; replace = Conf["Replace " + type] && !/spoiler/.test(thumb.src); prefetch = (Conf['prefetch'] && g.VIEW === 'thread') || force; @@ -8682,78 +8701,93 @@ el = $.el(isImage ? 'img' : 'video'); if (replace) { if (this.file.isSpoiler) { - style.maxHeight = style.maxWidth = this.isReply ? '125px' : '250px'; + thumb.style.maxHeight = thumb.style.maxWidth = this.isReply ? '125px' : '250px'; } - if (isVideo) { - el.textContent = thumb.alt; - el.dataset.md5 = thumb.dataset.md5; - el.style.height = style.height; - el.style.width = style.width; - el.style.maxHeight = style.maxHeight; - el.style.maxWidth = style.maxWidth; - el.loop = true; - el.className = thumb.className; + if (isImage) { + $.on(el, 'load', (function(_this) { + return function() { + return ImageLoader.replaceImage(_this); + }; + })(this)); + } else { + $.one(el, 'loadeddata', (function(_this) { + return function() { + return ImageLoader.replaceVideo(_this, el); + }; + })(this)); } - cb = (function(_this) { - return function() { - $.off(el, 'load loadeddata', cb); - return ImageLoader.replace(_this, el); - }; - })(this); - $.on(el, 'load loadeddata', cb); - } - ImageLoader.queue.push([el, URL]); - if (!ImageLoader.busy) { - return ImageLoader.next(); } + return ImageLoader.queueDownload(el, URL); }, - busy: false, - queue: [], - loadend: function() { - $.off(this, 'load loadeddata error', ImageLoader.loadend); - ImageLoader.busy = false; - return ImageLoader.next(); - }, - next: function() { - var el, item, url; - if (ImageLoader.busy) { - return; - } - if (item = ImageLoader.queue.shift()) { - el = item[0], url = item[1]; - $.on(el, 'load loadeddata error', ImageLoader.loadend); - setTimeout((function() { - return ImageLoader.loadend.call(el); - }), $.SECOND); + 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 ImageLoader.busy = true; + 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; } }, - replace: function(post, el) { - var clone, file, isVideo, thumb, _i, _len, _ref; + replaceVideo: function(post, video) { + var clone, file, style, thumb, video2, _i, _len, _ref; file = post.file; - isVideo = file.isVideo, thumb = file.thumb; + thumb = file.thumb; + style = thumb.style; if (!post.isClone) { _ref = post.clones; for (_i = 0, _len = _ref.length; _i < _len; _i++) { clone = _ref[_i]; - if (!isVideo || !$.hasClass(clone.nodes.root.parentNode, 'dialog')) { - ImageLoader.replace(clone, el.cloneNode(true)); - } + video2 = $.el('video'); + $.one(video2, 'loadeddata', (function(_this) { + return function() { + return ImageLoader.replaceVideo(clone, video2); + }; + })(this)); + video2.src = video.src; } } - if (isVideo) { - if (Conf['Image Hover']) { - $.on(el, 'mouseover', ImageHover.mouseover); - } - $.replace(thumb, el); - file.videoThumb = true; - file.thumb = el; - if (!post.isFetchedQuote) { - return ImageLoader.play(el); - } - } else { - return thumb.src = file.URL; + 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 (!post.isFetchedQuote) { + return ImageLoader.play(video); } }, play: function(video) { @@ -8761,7 +8795,7 @@ return $.asap((function() { return doc.contains(video); }), function() { - if (!d.hidden && Header.isNodeVisible(video)) { + if (Header.isNodeVisible(video)) { return video.play(); } }); @@ -9301,7 +9335,7 @@ case 'video/webm': case 'video/ogv': $.extend(el, { - innerHTML: "" + innerHTML: "" }); _ref1 = ['mp4', 'webm']; _results = []; @@ -12888,7 +12922,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 51a05ba53..aba6aff1d 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 af07822db..0a47d7c95 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 5ff33d832..d5d055a2f 100644 --- a/builds/updates.xml +++ b/builds/updates.xml @@ -1,7 +1,7 @@ - + diff --git a/package.json b/package.json index 8137222c0..61bde0ab1 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.2", + "version": "1.9.2.3", "repo": "https://github.com/ccd0/4chan-x/", "page": "https://github.com/ccd0/4chan-x", "downloads": "https://ccd0.github.io/4chan-x/builds/",