Randomize spoiler images.

This commit is contained in:
Nicolas Stepien 2012-09-10 03:42:47 +02:00
parent ef92aac78d
commit d71577896f
2 changed files with 42 additions and 52 deletions

View File

@ -869,12 +869,15 @@
});
},
parse: function(req, a, threadID, replyID) {
var bq, href, post, posts, quote, quotes, _i, _j, _len, _len1;
var bq, href, post, posts, quote, quotes, spoilerRange, _i, _j, _len, _len1;
if (req.status !== 200) {
a.textContent = "" + req.status + " " + req.statusText;
return;
}
posts = JSON.parse(req.response).posts;
if (spoilerRange = posts[0].custom_spoiler) {
Build.spoilerRange[g.BOARD] = spoilerRange;
}
replyID = +replyID;
for (_i = 0, _len = posts.length; _i < _len; _i++) {
post = posts[_i];
@ -979,14 +982,18 @@
}
},
parse: function(req, thread, a) {
var backlink, id, link, nodes, post, replies, reply, threadID, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
var backlink, id, link, nodes, post, posts, replies, reply, spoilerRange, threadID, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
if (req.status !== 200) {
a.textContent = "" + req.status + " " + req.statusText;
$.off(a, 'click', ExpandThread.cb.toggle);
return;
}
a.textContent = a.textContent.replace('× Loading...', '-');
replies = JSON.parse(req.response).posts.slice(1);
posts = JSON.parse(req.response).posts;
if (spoilerRange = posts[0].custom_spoiler) {
Build.spoilerRange[g.BOARD] = spoilerRange;
}
replies = posts.slice(1);
threadID = thread.id.slice(1);
nodes = [];
for (_i = 0, _len = replies.length; _i < _len; _i++) {
@ -2989,7 +2996,10 @@
return delete Updater.request;
},
update: function(posts) {
var count, id, lastPost, nodes, post, scroll, _i, _len, _ref;
var count, id, lastPost, nodes, post, scroll, spoilerRange, _i, _len, _ref;
if (spoilerRange = posts[0].custom_spoiler) {
Build.spoilerRange[g.BOARD] = spoilerRange;
}
lastPost = Updater.thread.lastElementChild;
id = +lastPost.id.slice(2);
nodes = [];
@ -3505,7 +3515,7 @@
}
},
parsePost: function(req, board, threadID, postID, root, cb) {
var post, posts, status, url, _i, _len;
var post, posts, spoilerRange, status, url, _i, _len;
status = req.status;
if (status !== 200) {
if (url = Redirect.post(board, postID)) {
@ -3514,11 +3524,14 @@
});
} else {
$.addClass(root, 'warning');
root.textContent = status === 404 ? "Thread No." + threadID + " has not been found." : "Error " + req.status + ": " + req.statusText + ".";
root.textContent = status === 404 ? "Thread No." + threadID + " 404'd." : "Error " + req.status + ": " + req.statusText + ".";
}
return;
}
posts = JSON.parse(req.response).posts;
if (spoilerRange = posts[0].custom_spoiler) {
Build.spoilerRange[g.BOARD] = spoilerRange;
}
postID = +postID;
for (_i = 0, _len = posts.length; _i < _len; _i++) {
post = posts[_i];
@ -3532,7 +3545,7 @@
});
} else {
$.addClass(root, 'warning');
root.textContent = "Post No." + postID + " has not been found.";
root.textContent = "Post No." + postID + " was not found.";
}
return;
}
@ -3676,6 +3689,7 @@
};
Build = {
spoilerRange: {},
shortFilename: function(filename, isOP) {
var threshold;
threshold = isOP ? 40 : 30;
@ -3729,7 +3743,7 @@
@license: https://github.com/4chan/4chan-JS/blob/master/LICENSE
*/
var a, board, capcode, capcodeClass, capcodeStart, closed, comment, container, date, dateUTC, email, emailEnd, emailStart, ext, file, fileDims, fileHTML, fileInfo, fileSize, fileThumb, filename, flag, flagCode, flagName, href, imgSrc, isClosed, isOP, isSticky, name, postID, quote, shortFilename, staticPath, sticky, subject, threadID, tripcode, uniqueID, userID, _i, _len, _ref;
var a, board, capcode, capcodeClass, capcodeStart, closed, comment, container, date, dateUTC, email, emailEnd, emailStart, ext, file, fileDims, fileHTML, fileInfo, fileSize, fileThumb, filename, flag, flagCode, flagName, href, imgSrc, isClosed, isOP, isSticky, name, postID, quote, shortFilename, spoilerRange, staticPath, sticky, subject, threadID, tripcode, uniqueID, userID, _i, _len, _ref;
postID = o.postID, threadID = o.threadID, board = o.board, name = o.name, capcode = o.capcode, tripcode = o.tripcode, uniqueID = o.uniqueID, email = o.email, subject = o.subject, flagCode = o.flagCode, flagName = o.flagName, date = o.date, dateUTC = o.dateUTC, isSticky = o.isSticky, isClosed = o.isClosed, comment = o.comment, file = o.file;
isOP = postID === threadID;
staticPath = '//static.4chan.org';
@ -3778,33 +3792,9 @@
fileSize = "Spoiler Image, " + fileSize;
if (!isArchived) {
fileThumb = '//static.4chan.org/image/spoiler';
fileThumb += (function() {
switch (board) {
case 'a':
return '-a';
case 'co':
return '-co';
case 'jp':
return '-jp';
case 'lit':
return 'lit';
case 'm':
return '-m2';
case 'mlp':
return '-mlp';
case 'tg':
return '-tg2';
case 'tv':
return '-tv5';
case 'v':
case 'vg':
return '-v';
case 'vp':
return '-vp';
default:
return '';
}
})();
if (spoilerRange = Build.spoilerRange[board]) {
fileThumb += ("-" + board) + Math.floor(1 + spoilerRange * Math.random());
}
fileThumb += '.png';
file.twidth = file.theight = 100;
}

View File

@ -715,6 +715,8 @@ ExpandComment =
return
posts = JSON.parse(req.response).posts
if spoilerRange = posts[0].custom_spoiler
Build.spoilerRange[g.BOARD] = spoilerRange
replyID = +replyID
for post in posts
@ -791,8 +793,11 @@ ExpandThread =
a.textContent = a.textContent.replace '× Loading...', '-'
replies = JSON.parse(req.response).posts[1..]
posts = JSON.parse(req.response).posts
if spoilerRange = posts[0].custom_spoiler
Build.spoilerRange[g.BOARD] = spoilerRange
replies = posts[1..]
threadID = thread.id[1..]
nodes = []
for reply in replies
@ -2384,6 +2389,9 @@ Updater =
Updater.count.className = 'warning'
delete Updater.request
update: (posts) ->
if spoilerRange = posts[0].custom_spoiler
Build.spoilerRange[g.BOARD] = spoilerRange
lastPost = Updater.thread.lastElementChild
id = +lastPost.id[2..]
nodes = []
@ -2748,12 +2756,14 @@ Get =
$.addClass root, 'warning'
root.textContent =
if status is 404
"Thread No.#{threadID} has not been found."
"Thread No.#{threadID} 404'd."
else
"Error #{req.status}: #{req.statusText}."
return
posts = JSON.parse(req.response).posts
if spoilerRange = posts[0].custom_spoiler
Build.spoilerRange[g.BOARD] = spoilerRange
postID = +postID
for post in posts
break if post.no is postID # we found it!
@ -2764,7 +2774,7 @@ Get =
Get.parseArchivedPost @, board, postID, root, cb
else
$.addClass root, 'warning'
root.textContent = "Post No.#{postID} has not been found."
root.textContent = "Post No.#{postID} was not found."
return
$.replace root.firstChild, Get.cleanPost Build.postFromObject post, board
@ -2887,6 +2897,7 @@ Get =
"/#{g.BOARD}/ - #{span.textContent.trim()}"
Build =
spoilerRange: {}
shortFilename: (filename, isOP) ->
# FILENAME SHORTENING SCIENCE:
# OPs have a +10 characters threshold.
@ -3020,20 +3031,9 @@ Build =
fileSize = "Spoiler Image, #{fileSize}"
unless isArchived
fileThumb = '//static.4chan.org/image/spoiler'
fileThumb += switch board
# UGGH, I can't wait to maintain this crap.
# Sup desuwa?
when 'a' then '-a'
when 'co' then '-co'
when 'jp' then '-jp'
when 'lit' then 'lit'
when 'm' then '-m2'
when 'mlp' then '-mlp'
when 'tg' then '-tg2'
when 'tv' then '-tv5'
when 'v', 'vg' then '-v'
when 'vp' then '-vp'
else ''
if spoilerRange = Build.spoilerRange[board]
# Randomize the spoiler image.
fileThumb += "-#{board}" + Math.floor 1 + spoilerRange * Math.random()
fileThumb += '.png'
file.twidth = file.theight = 100