From cb3504c1d79db2af1bc9b9999ecccfe230d47b10 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 23 Jun 2012 23:52:34 +0200 Subject: [PATCH] Move the Report Buttons into the menu as Report Links. More work on the menu. --- 4chan_x.user.js | 77 +++++++++++++++++++++++++++++-------------------- script.coffee | 64 +++++++++++++++++++++++++--------------- 2 files changed, 86 insertions(+), 55 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 424a3a6ae..4eed52eb7 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -86,7 +86,7 @@ 'Keybinds': [true, 'Binds actions to keys'], 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'], 'File Info Formatting': [true, 'Reformats the file information'], - 'Report Button': [true, 'Add report buttons'], + 'Report Link': [true, 'Add report links'], 'Delete Button': [false, 'Add delete buttons'], 'Comment Expansion': [true, 'Expand too long comments'], 'Thread Expansion': [true, 'View all replies'], @@ -1114,20 +1114,29 @@ return Menu.open(Main.preParse($.x('ancestor::div[contains(@class,"postContainer")][1]', this))); }, open: function(post) { - var entry, i, _i, _len, _ref; - for (i in post) { - $.add(Menu.el, $.el('code', { - className: 'entry', - textContent: "" + i + ": " + post[i] - })); - } + var el, entry, _i, _len, _ref; + el = Menu.el; + el.setAttribute('data-id', post.ID); + el.setAttribute('data-rootid', post.root.id); _ref = Menu.entries; for (_i = 0, _len = _ref.length; _i < _len; _i++) { entry = _ref[_i]; - $.add(Menu.el, entry.el); - $.addClass(entry.el, 'entry'); + if ((function() { + var requirement, val, _ref1; + _ref1 = entry.requirements; + for (requirement in _ref1) { + val = _ref1[requirement]; + if (val !== post[requirement]) { + return false; + } + } + return true; + })()) { + $.add(el, entry.el); + $.event(entry.el, new CustomEvent('context')); + } } - $.add(d.body, Menu.el); + $.add(d.body, el); return $.on(d, 'click', Menu.close); }, close: function() { @@ -1135,6 +1144,12 @@ Menu.el.innerHTML = null; delete Menu.lastOpener; return $.off(d, 'click', Menu.close); + }, + newEntry: function(name) { + return $.el(name, { + className: 'entry', + tabIndex: 0 + }); } }; @@ -3379,13 +3394,13 @@ })); $.after((isOP ? piM : pi), file); } - $.replace(root.firstChild, pc); + $.replace(root.firstChild, Get.cleanPost(pc)); if (cb) { return cb(); } }, cleanPost: function(root) { - var child, el, now, post, _i, _j, _len, _len1, _ref, _ref1; + var child, el, els, now, post, _i, _j, _len, _len1, _ref; post = $('.post', root); _ref = Array.prototype.slice.call(root.childNodes); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -3395,9 +3410,10 @@ } } now = Date.now(); - _ref1 = $$('[id]', root); - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - el = _ref1[_j]; + els = $$('[id]', root); + els.push(root); + for (_j = 0, _len1 = els.length; _j < _len1; _j++) { + el = els[_j]; el.id = "" + now + "_" + el.id; } $.rmClass(root, 'forwarded'); @@ -3849,24 +3865,23 @@ ReportButton = { init: function() { - this.a = $.el('a', { - className: 'report_button', - innerHTML: '[ ! ]', - href: 'javascript:;' - }); - return Main.callbacks.push(this.node); - }, - node: function(post) { var a; - if (!(a = $('.report_button', post.el))) { - a = ReportButton.a.cloneNode(true); - $.add($('.postInfo', post.el), a); - } - return $.on(a, 'click', ReportButton.report); + a = Menu.newEntry('a'); + a.href = 'javascript:;'; + a.textContent = 'Report this post'; + $.addClass(a, 'report_button'); + $.on(a, 'click', ReportButton.report); + return Menu.entries.push({ + el: a, + requirements: { + isArchived: false + } + }); }, report: function() { - var id, set, url; - url = "//sys.4chan.org/" + g.BOARD + "/imgboard.php?mode=report&no=" + ($.x('preceding-sibling::input', this).name); + var a, id, set, url; + a = $('.postNum > a[title="Highlight this post"]', $.id(this.parentNode.dataset.rootid)); + url = "//sys.4chan.org/" + (a.pathname.split('/')[1]) + "/imgboard.php?mode=report&no=" + this.parentNode.dataset.id; id = Date.now(); set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200"; return window.open(url, id, set); diff --git a/script.coffee b/script.coffee index ceac5dc77..6aea157b7 100644 --- a/script.coffee +++ b/script.coffee @@ -5,7 +5,7 @@ Config = 'Keybinds': [true, 'Binds actions to keys'] 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'] 'File Info Formatting': [true, 'Reformats the file information'] - 'Report Button': [true, 'Add report buttons'] + 'Report Link': [true, 'Add report links'] 'Delete Button': [false, 'Add delete buttons'] 'Comment Expansion': [true, 'Expand too long comments'] 'Thread Expansion': [true, 'View all replies'] @@ -824,7 +824,6 @@ Menu = @el = $.el 'div', className: 'reply dialog' id: 'menu' - $.on @el, 'click', (e) -> e.stopPropagation() Main.callbacks.push @node @@ -847,21 +846,31 @@ Menu = # Position s = Menu.el.style + # XXX prevent overflows s.top = @offsetTop + @offsetHeight + 2 + 'px' s.left = @offsetLeft + 'px' Menu.lastOpener = @ Menu.open Main.preParse $.x 'ancestor::div[contains(@class,"postContainer")][1]', @ open: (post) -> - for i of post - $.add Menu.el, $.el 'code', - className: 'entry' - textContent: "#{i}: #{post[i]}" + {el} = Menu + # XXX GM/Scriptish require setAttribute + el.setAttribute 'data-id', post.ID + el.setAttribute 'data-rootid', post.root.id + # for i of post + # $.add Menu.el, $.el 'code', + # className: 'entry' + # textContent: "#{i}: #{post[i]}" for entry in Menu.entries - # if the entry matches this post... - $.add Menu.el, entry.el - $.addClass entry.el, 'entry' # XXX ??? - $.add d.body, Menu.el + if (-> + for requirement, val of entry.requirements + return false if val isnt post[requirement] + true + )() + $.add el, entry.el + # XXX 'context' event? + $.event entry.el, new CustomEvent 'context' + $.add d.body, el $.on d, 'click', Menu.close close: -> $.rm Menu.el @@ -869,6 +878,11 @@ Menu = delete Menu.lastOpener $.off d, 'click', Menu.close + newEntry: (name) -> + $.el name, + className: 'entry' + tabIndex: 0 + Keybinds = init: -> for node in $$ '[accesskey]' @@ -2654,7 +2668,7 @@ Get = innerHTML: "#{if data.media_status isnt " $.after (if isOP then piM else pi), file - $.replace root.firstChild, pc + $.replace root.firstChild, Get.cleanPost pc cb() if cb cleanPost: (root) -> post = $ '.post', root @@ -2663,7 +2677,9 @@ Get = # Don't mess with other features now = Date.now() - for el in $$ '[id]', root + els = $$ '[id]', root + els.push root + for el in els el.id = "#{now}_#{el.id}" $.rmClass root, 'forwarded' @@ -3018,20 +3034,20 @@ DeleteButton = ReportButton = init: -> - @a = $.el 'a', - className: 'report_button' - innerHTML: '[ ! ]' - href: 'javascript:;' - Main.callbacks.push @node - node: (post) -> - unless a = $ '.report_button', post.el - a = ReportButton.a.cloneNode true - $.add $('.postInfo', post.el), a + a = Menu.newEntry 'a' + a.href = 'javascript:;' + a.textContent = 'Report this post' + $.addClass a, 'report_button' $.on a, 'click', ReportButton.report + Menu.entries.push + el: a + requirements: + isArchived: false report: -> - url = "//sys.4chan.org/#{g.BOARD}/imgboard.php?mode=report&no=#{$.x('preceding-sibling::input', @).name}" - id = Date.now() - set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200" + a = $ '.postNum > a[title="Highlight this post"]', $.id @parentNode.dataset.rootid + url = "//sys.4chan.org/#{a.pathname.split('/')[1]}/imgboard.php?mode=report&no=#{@parentNode.dataset.id}" + id = Date.now() + set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200" window.open url, id, set ThreadStats =