From fec837ecdcdb92e77d406510b12a2f0ebbcd36c1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 11 Feb 2013 15:01:36 +0100 Subject: [PATCH] CoffeeScript tricks. --- 4chan_x.user.js | 47 ++++++++++++++++++++++++++------------------- src/features.coffee | 37 +++++++++++++++++------------------ 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 77fda1b8f..7577a2ede 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1427,10 +1427,10 @@ detail: { type: 'post', el: div, - open: function(post) { - var thread; - thread = post.thread; - if (post.isReply || thread.isHidden) { + open: function(_arg) { + var isReply, thread; + thread = _arg.thread, isReply = _arg.isReply; + if (isReply || thread.isHidden) { return false; } ThreadHiding.menu.thread = thread; @@ -1924,10 +1924,12 @@ }; fileEntry = { el: fileEl, - open: function(post) { + open: function(_arg) { + var file; + file = _arg.file; fileEl.textContent = 'File'; $.on(fileEl, 'click', DeleteLink["delete"]); - return !!post.file; + return !!file; } }; d.dispatchEvent(new CustomEvent('AddMenuEntry', { @@ -2047,12 +2049,14 @@ detail: { type: 'post', el: a, - open: function(post) { - if (!post.file) { + open: function(_arg) { + var file; + file = _arg.file; + if (!file) { return false; } - a.href = post.file.URL; - a.download = post.file.name; + a.href = file.URL; + a.download = file.name; return true; } } @@ -2072,14 +2076,15 @@ entry = { type: 'post', el: div, - open: function(post) { - var redirect; + open: function(_arg) { + var ID, board, redirect, thread; + ID = _arg.ID, thread = _arg.thread, board = _arg.board; redirect = Redirect.to({ - board: post.board, - threadID: post.thread, - postID: post.ID + board: board, + threadID: thread, + postID: ID }); - return redirect !== ("//boards.4chan.org/" + post.board + "/"); + return redirect !== ("//boards.4chan.org/" + board + "/"); }, subEntries: [] }; @@ -2099,11 +2104,13 @@ target: '_blank' }); if (type === 'post') { - open = function(post) { + open = function(_arg) { + var ID, board, thread; + ID = _arg.ID, thread = _arg.thread, board = _arg.board; el.href = Redirect.to({ - board: post.board, - threadID: post.thread, - postID: post.ID + board: board, + threadID: thread, + postID: ID }); return true; }; diff --git a/src/features.coffee b/src/features.coffee index 67b7e1e11..3e4e42752 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -485,13 +485,12 @@ ThreadHiding = detail: type: 'post' el: div - open: (post) -> - {thread} = post - if post.isReply or thread.isHidden + open: ({thread, isReply}) -> + if isReply or thread.isHidden return false ThreadHiding.menu.thread = thread true - subEntries: [{el: apply}, {el: makeStub}] + subEntries: [el: apply; el: makeStub] hide: -> makeStub = $('input', @parentNode).checked {thread} = ThreadHiding.menu @@ -841,10 +840,10 @@ DeleteLink = true fileEntry = el: fileEl - open: (post) -> + open: ({file}) -> fileEl.textContent = 'File' $.on fileEl, 'click', DeleteLink.delete - !!post.file + !!file d.dispatchEvent new CustomEvent 'AddMenuEntry', detail: @@ -940,10 +939,10 @@ DownloadLink = detail: type: 'post' el: a - open: (post) -> - return false unless post.file - a.href = post.file.URL - a.download = post.file.name + open: ({file}) -> + return false unless file + a.href = file.URL + a.download = file.name true ArchiveLink = @@ -956,12 +955,12 @@ ArchiveLink = entry = type: 'post' el: div - open: (post) -> + open: ({ID, thread, board}) -> redirect = Redirect.to - board: post.board - threadID: post.thread - postID: post.ID - redirect isnt "//boards.4chan.org/#{post.board}/" + board: board + threadID: thread + postID: ID + redirect isnt "//boards.4chan.org/#{board}/" subEntries: [] for type in [ @@ -985,11 +984,11 @@ ArchiveLink = target: '_blank' if type is 'post' - open = (post) -> + open = ({ID, thread, board}) -> el.href = Redirect.to - board: post.board - threadID: post.thread - postID: post.ID + board: board + threadID: thread + postID: ID true else open = (post) ->