From 9372c1dc32dc924d1fb502f7d533ec369942371d Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 15 Jun 2012 19:32:27 +0200 Subject: [PATCH] A bit of clean up. --- 4chan_x.user.js | 43 +++++++++++++++++++++---------------------- script.coffee | 49 +++++++++++++++++++++---------------------------- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 69ee1ea26..8abbc11ca 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3099,35 +3099,30 @@ } }, parseArchivedPost: function(req, board, postID, root, cb) { - var bq, br, capcode, data, email, file, filesize, isOP, nameBlock, p, pc, pi, piM, span; + var bq, br, capcode, data, email, file, filesize, isOP, name, nameBlock, pc, pi, piM, span, subject, threadID, trip; data = JSON.parse(req.response); + $.addClass(root, 'archivedPost'); if (data.error) { root.textContent = data.error; return; } - isOP = postID === data.thread_num; - pc = $.el('div', { - id: "pc" + postID, - className: isOP ? 'postContainer opContainer' : 'postContainer replyContainer' - }); - p = $.el('div', { - id: "p" + postID, - className: isOP ? 'post op' : 'post reply' - }); - $.add(pc, p); + threadID = data.thread_num; + isOP = postID === threadID; + name = data.name, trip = data.trip; + subject = data.title; piM = $.el('div', { id: "pim" + postID, className: 'postInfoM mobile', - innerHTML: "
" + data.fourchan_date + "
No." + postID + "
" + innerHTML: "
" + data.fourchan_date + "
No." + postID + "
" }); - $('.name', piM).textContent = data.name; - $('.subject', piM).textContent = data.title; + $('.name', piM).textContent = name; + $('.subject', piM).textContent = subject; br = $('br', piM); - if (data.trip) { + if (trip) { $.before(br, [ $.tn(' '), $.el('span', { className: 'postertrip', - textContent: data.trip + textContent: trip }) ]); } @@ -3149,9 +3144,9 @@ pi = $.el('div', { id: "pi" + postID, className: 'postInfo desktop', - innerHTML: " data.fourchan_date No." + postID + "" + (isOP ? '   ' : '') + " " + innerHTML: " data.fourchan_date No." + postID + "" + (isOP ? '   ' : '') + " " }); - $('.subject', pi).textContent = data.title; + $('.subject', pi).textContent = subject; nameBlock = $('.nameBlock', pi); if (data.email) { email = $.el('a', { @@ -3165,11 +3160,11 @@ className: 'name', textContent: data.name })); - if (data.trip) { + if (trip) { $.add(nameBlock, [ $.tn(' '), $.el('span', { className: 'postertrip', - textContent: data.trip + textContent: trip }) ]); } @@ -3223,7 +3218,12 @@ } }); bq.innerHTML = bq.innerHTML.replace(/(^|>)(>[^<$]+)(<|$)/g, '$1$2$3'); - $.add(p, [piM, pi, bq]); + pc = $.el('div', { + id: "pc" + postID, + className: "postContainer " + (isOP ? 'op' : 'reply') + "Container", + innerHTML: "
" + }); + $.add(pc.firstChild, [piM, pi, bq]); if (data.media_filename) { file = $.el('div', { id: "f" + postID, @@ -3245,7 +3245,6 @@ })); $.after((isOP ? piM : pi), file); } - $.addClass(root, 'archivedPost'); $.replace(root.firstChild, pc); if (cb) { return cb(); diff --git a/script.coffee b/script.coffee index 0434c96fe..4c408581c 100644 --- a/script.coffee +++ b/script.coffee @@ -2378,35 +2378,28 @@ Get = cb() if cb parseArchivedPost: (req, board, postID, root, cb) -> data = JSON.parse req.response - + $.addClass root, 'archivedPost' if data.error root.textContent = data.error return - isOP = postID is data.thread_num - - # post containers - pc = $.el 'div', - id: "pc#{postID}" - className: if isOP then 'postContainer opContainer' else 'postContainer replyContainer' - p = $.el 'div', - id: "p#{postID}" - className: if isOP then 'post op' else 'post reply' - $.add pc, p - + threadID = data.thread_num + isOP = postID is threadID + {name, trip} = data + subject = data.title # post info (mobile) piM = $.el 'div', id: "pim#{postID}" className: 'postInfoM mobile' - innerHTML: "
#{data.fourchan_date}
No.#{postID}
" - $('.name', piM).textContent = data.name - $('.subject', piM).textContent = data.title + innerHTML: "
#{data.fourchan_date}
No.#{postID}
" + $('.name', piM).textContent = name + $('.subject', piM).textContent = subject br = $ 'br', piM - if data.trip + if trip $.before br, [$.tn(' '), $.el 'span', className: 'postertrip' - textContent: data.trip + textContent: trip ] {capcode} = data if capcode isnt 'N' # 'A'dmin or 'M'od @@ -2427,15 +2420,13 @@ Get = ) ] - # post info pi = $.el 'div', id: "pi#{postID}" className: 'postInfo desktop' - innerHTML: " data.fourchan_date No.#{postID}#{if isOP then '   ' else ''} " + innerHTML: " data.fourchan_date No.#{postID}#{if isOP then '   ' else ''} " # subject - $('.subject', pi).textContent = data.title - + $('.subject', pi).textContent = subject nameBlock = $ '.nameBlock', pi if data.email email = $.el 'a', @@ -2446,8 +2437,8 @@ Get = $.add nameBlock, $.el 'span', className: 'name' textContent: data.name - if data.trip - $.add nameBlock, [$.tn(' '), $.el('span', className: 'postertrip', textContent: data.trip)] + if trip + $.add nameBlock, [$.tn(' '), $.el('span', className: 'postertrip', textContent: trip)] if capcode isnt 'N' # 'A'dmin or 'M'od $.add nameBlock, [ $.tn(' '), @@ -2468,7 +2459,6 @@ Get = ) ] - # comment bq = $.el 'blockquote', id: "m#{postID}" @@ -2507,11 +2497,15 @@ Get = '' when '[/banned]' '' + # greentext bq.innerHTML = bq.innerHTML.replace /(^|>)(>[^<$]+)(<|$)/g, '$1$2$3' - - $.add p, [piM, pi, bq] - + # post container + pc = $.el 'div', + id: "pc#{postID}" + className: "postContainer #{if isOP then 'op' else 'reply'}Container" + innerHTML: "
" + $.add pc.firstChild, [piM, pi, bq] # file if data.media_filename @@ -2536,7 +2530,6 @@ 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) ->