Some image expanding/hover loading error fixing.
This commit is contained in:
parent
c02991ef4a
commit
fe0cb5cd18
103
4chan_x.user.js
103
4chan_x.user.js
@ -20,7 +20,7 @@
|
|||||||
// @icon data:image/gif;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAIALAAAAAAQABAAAAIxlI+pq+D9DAgUoFkPDlbs7lGiI2bSVnKglnJMOL6omczxVZK3dH/41AG6Lh7i6qUoAAA7
|
// @icon data:image/gif;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAIALAAAAAAQABAAAAIxlI+pq+D9DAgUoFkPDlbs7lGiI2bSVnKglnJMOL6omczxVZK3dH/41AG6Lh7i6qUoAAA7
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
/* 4chan X Beta - Version 3.0.0 - 2013-03-08
|
/* 4chan X Beta - Version 3.0.0 - 2013-03-09
|
||||||
* http://mayhemydg.github.com/4chan-x/
|
* http://mayhemydg.github.com/4chan-x/
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com>
|
* Copyright (c) 2009-2011 James Campos <james.r.campos@gmail.com>
|
||||||
@ -4631,7 +4631,7 @@
|
|||||||
$.rmClass(post.file.thumb, 'expanding');
|
$.rmClass(post.file.thumb, 'expanding');
|
||||||
return post.file.isExpanded = false;
|
return post.file.isExpanded = false;
|
||||||
},
|
},
|
||||||
expand: function(post) {
|
expand: function(post, src) {
|
||||||
var img, thumb;
|
var img, thumb;
|
||||||
thumb = post.file.thumb;
|
thumb = post.file.thumb;
|
||||||
if (post.isHidden || post.file.isExpanded || $.hasClass(thumb, 'expanding')) {
|
if (post.isHidden || post.file.isExpanded || $.hasClass(thumb, 'expanding')) {
|
||||||
@ -4648,7 +4648,7 @@
|
|||||||
}
|
}
|
||||||
post.file.fullImage = img = $.el('img', {
|
post.file.fullImage = img = $.el('img', {
|
||||||
className: 'full-image',
|
className: 'full-image',
|
||||||
src: post.file.URL
|
src: src || post.file.URL
|
||||||
});
|
});
|
||||||
$.on(img, 'error', ImageExpand.error);
|
$.on(img, 'error', ImageExpand.error);
|
||||||
$.asap((function() {
|
$.asap((function() {
|
||||||
@ -4678,32 +4678,42 @@
|
|||||||
post = Get.postFromNode(this);
|
post = Get.postFromNode(this);
|
||||||
$.rm(this);
|
$.rm(this);
|
||||||
delete post.file.fullImage;
|
delete post.file.fullImage;
|
||||||
if (!post.file.isExpanded) {
|
if (!$.hasClass(post.file.thumb, 'expanding')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ImageExpand.contract(post);
|
ImageExpand.contract(post);
|
||||||
src = this.src.split('/');
|
src = this.src.split('/');
|
||||||
if (!(src[2] === 'images.4chan.org' && (URL = Redirect.image(src[3], src[5])))) {
|
if (src[2] === 'images.4chan.org') {
|
||||||
if (g.DEAD) {
|
if (URL = Redirect.image(src[3], src[5])) {
|
||||||
|
setTimeout(ImageExpand.expand, 10000, post, URL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (g.DEAD || post.isDead || post.file.isDead) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
URL = post.file.URL;
|
|
||||||
}
|
|
||||||
if ($.engine !== 'webkit' && URL.split('/')[2] === 'images.4chan.org') {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
timeoutID = setTimeout(ImageExpand.expand, 10000, post);
|
timeoutID = setTimeout(ImageExpand.expand, 10000, post);
|
||||||
if ($.engine !== 'webkit' || URL.split('/')[2] !== 'images.4chan.org') {
|
return $.ajax("//api.4chan.org/" + post.board + "/res/" + post.thread + ".json", {
|
||||||
return;
|
onload: function() {
|
||||||
}
|
var postObj, _i, _len, _ref;
|
||||||
return $.ajax(URL, {
|
if (this.status !== 200) {
|
||||||
onreadystatechange: (function() {
|
return;
|
||||||
if (this.status === 404) {
|
|
||||||
return clearTimeout(timeoutID);
|
|
||||||
}
|
}
|
||||||
})
|
_ref = JSON.parse(this.response).posts;
|
||||||
}, {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
type: 'head'
|
postObj = _ref[_i];
|
||||||
|
if (postObj.no === post.ID) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (postObj.no !== post.ID) {
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
return post.kill();
|
||||||
|
} else if (postObj.filedeleted) {
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
return post.kill(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
menu: {
|
menu: {
|
||||||
@ -4833,11 +4843,13 @@
|
|||||||
return $.on(this.file.thumb, 'mouseover', ImageHover.mouseover);
|
return $.on(this.file.thumb, 'mouseover', ImageHover.mouseover);
|
||||||
},
|
},
|
||||||
mouseover: function(e) {
|
mouseover: function(e) {
|
||||||
var el;
|
var el, post;
|
||||||
|
post = Get.postFromNode(this);
|
||||||
el = $.el('img', {
|
el = $.el('img', {
|
||||||
id: 'ihover',
|
id: 'ihover',
|
||||||
src: this.parentNode.href
|
src: post.file.URL
|
||||||
});
|
});
|
||||||
|
el.setAttribute('data-fullid', post.fullID);
|
||||||
$.add(d.body, el);
|
$.add(d.body, el);
|
||||||
UI.hover({
|
UI.hover({
|
||||||
root: this,
|
root: this,
|
||||||
@ -4851,35 +4863,46 @@
|
|||||||
return $.on(el, 'error', ImageHover.error);
|
return $.on(el, 'error', ImageHover.error);
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
var URL, src, timeoutID,
|
var URL, post, src, timeoutID,
|
||||||
_this = this;
|
_this = this;
|
||||||
if (!doc.contains(this)) {
|
if (!doc.contains(this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
post = g.posts[this.dataset.fullid];
|
||||||
src = this.src.split('/');
|
src = this.src.split('/');
|
||||||
if (!(src[2] === 'images.4chan.org' && (URL = Redirect.image(src[3], src[5])))) {
|
if (src[2] === 'images.4chan.org') {
|
||||||
if (g.DEAD) {
|
if (URL = Redirect.image(src[3], src[5].replace(/\?.+$/, ''))) {
|
||||||
|
this.src = URL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (g.DEAD || post.isDead || post.file.isDead) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
URL = post.file.URL;
|
|
||||||
}
|
|
||||||
if ($.engine !== 'webkit' && URL.split('/')[2] === 'images.4chan.org') {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
timeoutID = setTimeout((function() {
|
timeoutID = setTimeout((function() {
|
||||||
return _this.src = URL;
|
return _this.src = post.file.URL + '?' + Date.now();
|
||||||
}), 3000);
|
}), 3000);
|
||||||
if ($.engine !== 'webkit' || URL.split('/')[2] !== 'images.4chan.org') {
|
return $.ajax("//api.4chan.org/" + post.board + "/res/" + post.thread + ".json", {
|
||||||
return;
|
onload: function() {
|
||||||
}
|
var postObj, _i, _len, _ref;
|
||||||
return $.ajax(URL, {
|
if (this.status !== 200) {
|
||||||
onreadystatechange: (function() {
|
return;
|
||||||
if (this.status === 404) {
|
|
||||||
return clearTimeout(timeoutID);
|
|
||||||
}
|
}
|
||||||
})
|
_ref = JSON.parse(this.response).posts;
|
||||||
}, {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
type: 'head'
|
postObj = _ref[_i];
|
||||||
|
if (postObj.no === post.ID) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (postObj.no !== post.ID) {
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
return post.kill();
|
||||||
|
} else if (postObj.filedeleted) {
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
return post.kill(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3083,19 +3083,19 @@ ImageExpand =
|
|||||||
$.rmClass post.file.thumb, 'expanding'
|
$.rmClass post.file.thumb, 'expanding'
|
||||||
post.file.isExpanded = false
|
post.file.isExpanded = false
|
||||||
|
|
||||||
expand: (post) ->
|
expand: (post, src) ->
|
||||||
# Do not expand images of hidden/filtered replies, or already expanded pictures.
|
# Do not expand images of hidden/filtered replies, or already expanded pictures.
|
||||||
{thumb} = post.file
|
{thumb} = post.file
|
||||||
return if post.isHidden or post.file.isExpanded or $.hasClass thumb, 'expanding'
|
return if post.isHidden or post.file.isExpanded or $.hasClass thumb, 'expanding'
|
||||||
$.addClass thumb, 'expanding'
|
$.addClass thumb, 'expanding'
|
||||||
if post.file.fullImage
|
if post.file.fullImage
|
||||||
# Expand already-loaded picture.
|
# Expand already-loaded/ing picture.
|
||||||
$.asap (-> post.file.fullImage.naturalHeight), ->
|
$.asap (-> post.file.fullImage.naturalHeight), ->
|
||||||
ImageExpand.completeExpand post
|
ImageExpand.completeExpand post
|
||||||
return
|
return
|
||||||
post.file.fullImage = img = $.el 'img',
|
post.file.fullImage = img = $.el 'img',
|
||||||
className: 'full-image'
|
className: 'full-image'
|
||||||
src: post.file.URL
|
src: src or post.file.URL
|
||||||
$.on img, 'error', ImageExpand.error
|
$.on img, 'error', ImageExpand.error
|
||||||
$.asap (-> post.file.fullImage.naturalHeight), ->
|
$.asap (-> post.file.fullImage.naturalHeight), ->
|
||||||
ImageExpand.completeExpand post
|
ImageExpand.completeExpand post
|
||||||
@ -3119,21 +3119,31 @@ ImageExpand =
|
|||||||
post = Get.postFromNode @
|
post = Get.postFromNode @
|
||||||
$.rm @
|
$.rm @
|
||||||
delete post.file.fullImage
|
delete post.file.fullImage
|
||||||
unless post.file.isExpanded
|
unless $.hasClass post.file.thumb, 'expanding'
|
||||||
# Don't try to re-expend if it was already contracted.
|
# Don't try to re-expend if it was already contracted.
|
||||||
return
|
return
|
||||||
ImageExpand.contract post
|
ImageExpand.contract post
|
||||||
|
|
||||||
src = @src.split '/'
|
src = @src.split '/'
|
||||||
unless src[2] is 'images.4chan.org' and URL = Redirect.image src[3], src[5]
|
if src[2] is 'images.4chan.org'
|
||||||
return if g.DEAD
|
if URL = Redirect.image src[3], src[5]
|
||||||
{URL} = post.file
|
setTimeout ImageExpand.expand, 10000, post, URL
|
||||||
return if $.engine isnt 'webkit' and URL.split('/')[2] is 'images.4chan.org'
|
return
|
||||||
|
if g.DEAD or post.isDead or post.file.isDead
|
||||||
|
return
|
||||||
|
|
||||||
timeoutID = setTimeout ImageExpand.expand, 10000, post
|
timeoutID = setTimeout ImageExpand.expand, 10000, post
|
||||||
# Only Chrome let userscripts do cross domain requests.
|
# XXX CORS for images.4chan.org WHEN?
|
||||||
# Don't check for 404'd status in the archivers.
|
$.ajax "//api.4chan.org/#{post.board}/res/#{post.thread}.json", onload: ->
|
||||||
return if $.engine isnt 'webkit' or URL.split('/')[2] isnt 'images.4chan.org'
|
return if @status isnt 200
|
||||||
$.ajax URL, onreadystatechange: (-> clearTimeout timeoutID if @status is 404),
|
for postObj in JSON.parse(@response).posts
|
||||||
type: 'head'
|
break if postObj.no is post.ID
|
||||||
|
if postObj.no isnt post.ID
|
||||||
|
clearTimeout timeoutID
|
||||||
|
post.kill()
|
||||||
|
else if postObj.filedeleted
|
||||||
|
clearTimeout timeoutID
|
||||||
|
post.kill true
|
||||||
|
|
||||||
menu:
|
menu:
|
||||||
init: ->
|
init: ->
|
||||||
@ -3220,9 +3230,11 @@ ImageHover =
|
|||||||
return unless @file?.isImage
|
return unless @file?.isImage
|
||||||
$.on @file.thumb, 'mouseover', ImageHover.mouseover
|
$.on @file.thumb, 'mouseover', ImageHover.mouseover
|
||||||
mouseover: (e) ->
|
mouseover: (e) ->
|
||||||
|
post = Get.postFromNode @
|
||||||
el = $.el 'img',
|
el = $.el 'img',
|
||||||
id: 'ihover'
|
id: 'ihover'
|
||||||
src: @parentNode.href
|
src: post.file.URL
|
||||||
|
el.setAttribute 'data-fullid', post.fullID
|
||||||
$.add d.body, el
|
$.add d.body, el
|
||||||
UI.hover
|
UI.hover
|
||||||
root: @
|
root: @
|
||||||
@ -3233,17 +3245,28 @@ ImageHover =
|
|||||||
$.on el, 'error', ImageHover.error
|
$.on el, 'error', ImageHover.error
|
||||||
error: ->
|
error: ->
|
||||||
return unless doc.contains @
|
return unless doc.contains @
|
||||||
|
post = g.posts[@dataset.fullid]
|
||||||
|
|
||||||
src = @src.split '/'
|
src = @src.split '/'
|
||||||
unless src[2] is 'images.4chan.org' and URL = Redirect.image src[3], src[5]
|
if src[2] is 'images.4chan.org'
|
||||||
return if g.DEAD
|
if URL = Redirect.image src[3], src[5].replace /\?.+$/, ''
|
||||||
{URL} = post.file
|
@src = URL
|
||||||
return if $.engine isnt 'webkit' and URL.split('/')[2] is 'images.4chan.org'
|
return
|
||||||
timeoutID = setTimeout (=> @src = URL), 3000
|
if g.DEAD or post.isDead or post.file.isDead
|
||||||
# Only Chrome let userscripts do cross domain requests.
|
return
|
||||||
# Don't check for 404'd status in the archivers.
|
|
||||||
return if $.engine isnt 'webkit' or URL.split('/')[2] isnt 'images.4chan.org'
|
timeoutID = setTimeout (=> @src = post.file.URL + '?' + Date.now()), 3000
|
||||||
$.ajax URL, onreadystatechange: (-> clearTimeout timeoutID if @status is 404),
|
# XXX CORS for images.4chan.org WHEN?
|
||||||
type: 'head'
|
$.ajax "//api.4chan.org/#{post.board}/res/#{post.thread}.json", onload: ->
|
||||||
|
return if @status isnt 200
|
||||||
|
for postObj in JSON.parse(@response).posts
|
||||||
|
break if postObj.no is post.ID
|
||||||
|
if postObj.no isnt post.ID
|
||||||
|
clearTimeout timeoutID
|
||||||
|
post.kill()
|
||||||
|
else if postObj.filedeleted
|
||||||
|
clearTimeout timeoutID
|
||||||
|
post.kill true
|
||||||
|
|
||||||
ExpandComment =
|
ExpandComment =
|
||||||
init: ->
|
init: ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user