From 8046bfa93937f735cea7c08fe9f88f67c2404cb5 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 14 Jun 2012 18:59:30 +0200 Subject: [PATCH] Some archived posts parsing fixes. Add an 'archivedPost' class to the root. --- 4chan_x.user.js | 44 +++++++++++++++------------------------- script.coffee | 53 ++++++++++++++++++++----------------------------- 2 files changed, 38 insertions(+), 59 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 990534c32..7d8dbaa3b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3109,7 +3109,7 @@ } }, parseArchivedPost: function(req, board, postID, root, cb) { - var bq, data, date, email, file, filesize, isOP, nameBlock, p, pc, pi, piM, span, time; + var bq, capcode, data, date, email, file, filesize, isOP, nameBlock, p, pc, pi, piM, span, time; data = JSON.parse(req.response); if (data.error) { root.textContent = data.error; @@ -3117,7 +3117,7 @@ } isOP = postID === data.thread_num; pc = $.el('div', { - id: "pc", + id: "pc" + postID, className: isOP ? 'postContainer opContainer' : 'postContainer replyContainer' }); p = $.el('div', { @@ -3162,40 +3162,24 @@ }) ]); } - if (data.capcode === 'A') { + capcode = data.capcode; + if (capcode !== 'N') { $.add(nameBlock, [ $.tn(' '), $.el('strong', { - className: 'capcode capcodeAdmin', - textContent: '## Admin' + className: capcode === 'A' ? 'capcode capcodeAdmin' : 'capcode', + textContent: capcode === 'A' ? '## Admin' : '## Mod' }) ]); nameBlock = $('.nameBlock', pi); - $.addClass(nameBlock, 'capcodeAdmin'); + $.addClass(nameBlock, capcode === 'A' ? 'capcodeAdmin' : 'capcodeMod'); $.add(nameBlock, [ - $.tn(' '), $.el('img'), { - src: '//static.4chan.org/image/adminicon.gif', - alt: 'This user is the 4chan Administrator.', - title: 'This user is the 4chan Administrator.', + $.tn(' '), $.el('img', { + src: capcode === 'A' ? '//static.4chan.org/image/adminicon.gif' : '//static.4chan.org/image/modicon.gif', + alt: capcode === 'A' ? 'This user is the 4chan Administrator.' : 'This user is a 4chan Moderator.', + title: capcode === 'A' ? 'This user is the 4chan Administrator.' : 'This user is a 4chan Moderator.', className: 'identityIcon' - } - ]); - } else if (data.capcode === 'M') { - $.add(nameBlock, [ - $.tn(' '), $.el('strong', { - className: 'capcode', - textContent: '## Mod' }) ]); - nameBlock = $('.nameBlock', pi); - $.addClass(nameBlock, 'capcodeMod'); - $.add(nameBlock, [ - $.tn(' '), $.el('img'), { - src: '//static.4chan.org/image/adminicon.gif', - alt: 'This user is a 4chan Moderator.', - title: 'This user is a 4chan Moderator.', - className: 'identityIcon' - } - ]); } bq = $.el('blockquote', { id: "m" + postID, @@ -3238,7 +3222,7 @@ filesize = $.bytesToString(data.media_size); $.add(file, $.el('div', { className: 'fileInfo', - innerHTML: "File: " + data.media_orig + "-(" + filesize + ", " + data.media_w + "x" + data.media_h + ", )" + innerHTML: "File: " + data.media_orig + "-(" + (data.spoiler === '1' ? 'Spoiler Image, ' : '') + filesize + ", " + data.media_w + "x" + data.media_h + ", )" })); span = $('span[title]', file); span.title = data.media_filename; @@ -3251,6 +3235,7 @@ })); $.after((isOP ? piM : pi), file); } + $.addClass(root, 'archivedPost'); $.replace(root.firstChild, pc); if (cb) { return cb(); @@ -3510,6 +3495,9 @@ post.img = img; } } + if (Conf['Reveal Spoilers']) { + RevealSpoilers.node(post); + } if (Conf['Image Auto-Gif']) { AutoGif.node(post); } diff --git a/script.coffee b/script.coffee index 119675e9e..cedfbe3b3 100644 --- a/script.coffee +++ b/script.coffee @@ -2414,15 +2414,6 @@ Get = $.replace root.firstChild, pc cb() if cb parseArchivedPost: (req, board, postID, root, cb) -> - # unarchived - # >>>/a/1 - # op - # >>>/a/66734868 - # reply - # >>>/a/66718194 - # reply with image and spoiler text - # >>>/v/142341606 - data = JSON.parse req.response if data.error @@ -2433,7 +2424,7 @@ Get = # post containers pc = $.el 'div', - id: "pc#{}" + id: "pc#{postID}" className: if isOP then 'postContainer opContainer' else 'postContainer replyContainer' p = $.el 'div', id: "p#{postID}" @@ -2476,27 +2467,25 @@ Get = textContent: data.name if data.trip $.add nameBlock, [$.tn(' '), $.el('span', className: 'postertrip', textContent: data.trip)] - if data.capcode is 'A' # admin + {capcode} = data + if capcode isnt 'N' # 'A'dmin or 'M'od $.add nameBlock, [ $.tn(' '), - $.el('strong', className: 'capcode capcodeAdmin', textContent: '## Admin') + $.el('strong', + className: if capcode is 'A' then 'capcode capcodeAdmin' else 'capcode', + textContent: if capcode is 'A' then '## Admin' else '## Mod' + ) ] nameBlock = $ '.nameBlock', pi - $.addClass nameBlock, 'capcodeAdmin' + $.addClass nameBlock, if capcode is 'A' then 'capcodeAdmin' else 'capcodeMod' $.add nameBlock, [ $.tn(' '), - $.el('img'), src: '//static.4chan.org/image/adminicon.gif', alt: 'This user is the 4chan Administrator.', title: 'This user is the 4chan Administrator.', className: 'identityIcon' - ] - else if data.capcode is 'M' # mod - $.add nameBlock, [ - $.tn(' '), - $.el('strong', className: 'capcode', textContent: '## Mod') - ] - nameBlock = $ '.nameBlock', pi - $.addClass nameBlock, 'capcodeMod' - $.add nameBlock, [ - $.tn(' '), - $.el('img'), src: '//static.4chan.org/image/adminicon.gif', alt: 'This user is a 4chan Moderator.', title: 'This user is a 4chan Moderator.', className: 'identityIcon' + $.el('img', + src: if capcode is 'A' then '//static.4chan.org/image/adminicon.gif' else '//static.4chan.org/image/modicon.gif', + alt: if capcode is 'A' then 'This user is the 4chan Administrator.' else 'This user is a 4chan Moderator.', + title: if capcode is 'A' then 'This user is the 4chan Administrator.' else 'This user is a 4chan Moderator.', + className: 'identityIcon' + ) ] @@ -2552,7 +2541,7 @@ Get = filesize = $.bytesToString data.media_size $.add file, $.el 'div', className: 'fileInfo' - innerHTML: "File: #{data.media_orig}-(#{filesize}, #{data.media_w}x#{data.media_h}, )" + innerHTML: "File: #{data.media_orig}-(#{if data.spoiler is '1' then 'Spoiler Image, ' else ''}#{filesize}, #{data.media_w}x#{data.media_h}, )" span = $ 'span[title]', file span.title = data.media_filename span.textContent = @@ -2567,7 +2556,7 @@ Get = innerHTML: "#{if data.spoiler is " $.after (if isOP then piM else pi), file - + $.addClass root, 'archivedPost' $.replace root.firstChild, pc cb() if cb cleanPost: (root) -> @@ -2753,14 +2742,16 @@ QuotePreview = if img.alt isnt 'File deleted.' post.fileInfo = fileInfo post.img = img + if Conf['Reveal Spoilers'] + RevealSpoilers.node post if Conf['Image Auto-Gif'] - AutoGif.node post + AutoGif.node post if Conf['Time Formatting'] - Time.node post + Time.node post if Conf['File Info Formatting'] - FileInfo.node post + FileInfo.node post if Conf['Resurrect Quotes'] - Quotify.node post + Quotify.node post if board is g.BOARD and el = $.id "p#{postID}" if Conf['Quote Highlighting']