diff --git a/4chan_x.user.js b/4chan_x.user.js index 3772ed544..1c227ee56 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1107,7 +1107,9 @@ }, node: function(post) { var a; - if (!(a = $('.menu_button', post.el))) { + if (post.isInlined && !post.isCrosspost) { + a = $('.menu_button', post.el); + } else { a = Menu.a.cloneNode(true); $.add($('.postInfo', post.el), a); } @@ -1136,10 +1138,7 @@ _ref = Menu.entries; for (_i = 0, _len = _ref.length; _i < _len; _i++) { entry = _ref[_i]; - if (entry.requirement(post)) { - if (typeof entry.open === "function") { - entry.open(post); - } + if (entry.open(post)) { $.add(el, entry.el); } } @@ -3927,12 +3926,13 @@ }); return Menu.addEntry({ el: a, - open: function() { + open: function(post) { + if (post.isArchived) { + return false; + } a.textContent = 'Delete this post'; - return $.on(a, 'click', DeleteLink["delete"]); - }, - requirement: function(post) { - return post.isArchived === false; + $.on(a, 'click', DeleteLink["delete"]); + return true; } }); }, @@ -3991,7 +3991,7 @@ $.on(a, 'click', this.report); return Menu.addEntry({ el: a, - requirement: function(post) { + open: function(post) { return post.isArchived === false; } }); @@ -4020,12 +4020,13 @@ el: a, open: function(post) { var fileText; + if (!post.img) { + return false; + } a.href = post.img.parentNode.href; fileText = post.fileInfo.firstElementChild; - return a.download = Conf['File Info Formatting'] ? fileText.dataset.filename : $('span', fileText).title; - }, - requirement: function(post) { - return post.img; + a.download = Conf['File Info Formatting'] ? fileText.dataset.filename : $('span', fileText).title; + return true; } }); } @@ -4036,20 +4037,19 @@ var a; a = $.el('a', { className: 'archive_link', - target: '_blank' + target: '_blank', + textContent: 'Archived post' }); return Menu.addEntry({ el: a, open: function(post) { - var path; + var href, path; path = $('.postNum > a[title="Highlight this post"]', post.el).pathname.split('/'); - a.href = Redirect.thread(path[1], path[3], post.ID); - return a.textContent = 'Archived post'; - }, - requirement: function(post) { - var path; - path = $('.postNum > a[title="Highlight this post"]', post.el).pathname.split('/'); - return Redirect.thread(path[1], path[3]) !== ("//boards.4chan.org/" + path[1] + "/"); + if ((href = Redirect.thread(path[1], path[3], post.ID)) === ("//boards.4chan.org/" + path[1] + "/")) { + return false; + } + a.href = href; + return true; } }); } diff --git a/script.coffee b/script.coffee index 31c274714..bbc65d994 100644 --- a/script.coffee +++ b/script.coffee @@ -840,7 +840,9 @@ Menu = Main.callbacks.push @node node: (post) -> - unless a = $ '.menu_button', post.el + if post.isInlined and !post.isCrosspost + a = $ '.menu_button', post.el + else a = Menu.a.cloneNode true $.add $('.postInfo', post.el), a $.on a, 'click', Menu.toggle @@ -873,8 +875,7 @@ Menu = # className: 'entry' # textContent: "#{i}: #{post[i]}" for entry in Menu.entries - if entry.requirement post - entry.open? post + if entry.open post $.add el, entry.el $.addClass $('.entry', Menu.el), 'focused' @@ -3082,11 +3083,12 @@ DeleteLink = href: 'javascript:;' Menu.addEntry el: a - open: -> + open: (post) -> + if post.isArchived + return false a.textContent = 'Delete this post' $.on a, 'click', DeleteLink.delete - requirement: (post) -> - post.isArchived is false + true delete: -> $.off @, 'click', DeleteLink.delete @textContent = 'Deleting...' @@ -3137,7 +3139,7 @@ ReportLink = $.on a, 'click', @report Menu.addEntry el: a - requirement: (post) -> + open: (post) -> post.isArchived is false report: -> a = $ '.postNum > a[title="Highlight this post"]', $.id @parentNode.dataset.rootid @@ -3156,6 +3158,8 @@ DownloadLink = Menu.addEntry el: a open: (post) -> + unless post.img + return false a.href = post.img.parentNode.href fileText = post.fileInfo.firstElementChild a.download = @@ -3163,23 +3167,22 @@ DownloadLink = fileText.dataset.filename else $('span', fileText).title - requirement: (post) -> - post.img + true ArchiveLink = init: -> a = $.el 'a', - className: 'archive_link' - target: '_blank' + className: 'archive_link' + target: '_blank' + textContent: 'Archived post' Menu.addEntry el: a open: (post) -> path = $('.postNum > a[title="Highlight this post"]', post.el).pathname.split '/' - a.href = Redirect.thread path[1], path[3], post.ID - a.textContent = 'Archived post' - requirement: (post) -> - path = $('.postNum > a[title="Highlight this post"]', post.el).pathname.split '/' - Redirect.thread(path[1], path[3]) isnt "//boards.4chan.org/#{path[1]}/" + if (href = Redirect.thread path[1], path[3], post.ID) is "//boards.4chan.org/#{path[1]}/" + return false + a.href = href + true ThreadStats = init: ->