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) { 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) { if (req.status !== 200) {
a.textContent = "" + req.status + " " + req.statusText; a.textContent = "" + req.status + " " + req.statusText;
return; return;
} }
posts = JSON.parse(req.response).posts; posts = JSON.parse(req.response).posts;
if (spoilerRange = posts[0].custom_spoiler) {
Build.spoilerRange[g.BOARD] = spoilerRange;
}
replyID = +replyID; replyID = +replyID;
for (_i = 0, _len = posts.length; _i < _len; _i++) { for (_i = 0, _len = posts.length; _i < _len; _i++) {
post = posts[_i]; post = posts[_i];
@ -979,14 +982,18 @@
} }
}, },
parse: function(req, thread, a) { 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) { if (req.status !== 200) {
a.textContent = "" + req.status + " " + req.statusText; a.textContent = "" + req.status + " " + req.statusText;
$.off(a, 'click', ExpandThread.cb.toggle); $.off(a, 'click', ExpandThread.cb.toggle);
return; return;
} }
a.textContent = a.textContent.replace('× Loading...', '-'); 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); threadID = thread.id.slice(1);
nodes = []; nodes = [];
for (_i = 0, _len = replies.length; _i < _len; _i++) { for (_i = 0, _len = replies.length; _i < _len; _i++) {
@ -2989,7 +2996,10 @@
return delete Updater.request; return delete Updater.request;
}, },
update: function(posts) { 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; lastPost = Updater.thread.lastElementChild;
id = +lastPost.id.slice(2); id = +lastPost.id.slice(2);
nodes = []; nodes = [];
@ -3505,7 +3515,7 @@
} }
}, },
parsePost: function(req, board, threadID, postID, root, cb) { 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; status = req.status;
if (status !== 200) { if (status !== 200) {
if (url = Redirect.post(board, postID)) { if (url = Redirect.post(board, postID)) {
@ -3514,11 +3524,14 @@
}); });
} else { } else {
$.addClass(root, 'warning'); $.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; return;
} }
posts = JSON.parse(req.response).posts; posts = JSON.parse(req.response).posts;
if (spoilerRange = posts[0].custom_spoiler) {
Build.spoilerRange[g.BOARD] = spoilerRange;
}
postID = +postID; postID = +postID;
for (_i = 0, _len = posts.length; _i < _len; _i++) { for (_i = 0, _len = posts.length; _i < _len; _i++) {
post = posts[_i]; post = posts[_i];
@ -3532,7 +3545,7 @@
}); });
} else { } else {
$.addClass(root, 'warning'); $.addClass(root, 'warning');
root.textContent = "Post No." + postID + " has not been found."; root.textContent = "Post No." + postID + " was not found.";
} }
return; return;
} }
@ -3676,6 +3689,7 @@
}; };
Build = { Build = {
spoilerRange: {},
shortFilename: function(filename, isOP) { shortFilename: function(filename, isOP) {
var threshold; var threshold;
threshold = isOP ? 40 : 30; threshold = isOP ? 40 : 30;
@ -3729,7 +3743,7 @@
@license: https://github.com/4chan/4chan-JS/blob/master/LICENSE @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; 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; isOP = postID === threadID;
staticPath = '//static.4chan.org'; staticPath = '//static.4chan.org';
@ -3778,33 +3792,9 @@
fileSize = "Spoiler Image, " + fileSize; fileSize = "Spoiler Image, " + fileSize;
if (!isArchived) { if (!isArchived) {
fileThumb = '//static.4chan.org/image/spoiler'; fileThumb = '//static.4chan.org/image/spoiler';
fileThumb += (function() { if (spoilerRange = Build.spoilerRange[board]) {
switch (board) { fileThumb += ("-" + board) + Math.floor(1 + spoilerRange * Math.random());
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 '';
}
})();
fileThumb += '.png'; fileThumb += '.png';
file.twidth = file.theight = 100; file.twidth = file.theight = 100;
} }

View File

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