Move the Report Buttons into the menu as Report Links.

More work on the menu.
This commit is contained in:
Nicolas Stepien 2012-06-23 23:52:34 +02:00
parent 1bdad6b3e5
commit cb3504c1d7
2 changed files with 86 additions and 55 deletions

View File

@ -86,7 +86,7 @@
'Keybinds': [true, 'Binds actions to keys'], 'Keybinds': [true, 'Binds actions to keys'],
'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'], 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'],
'File Info Formatting': [true, 'Reformats the file information'], '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'], 'Delete Button': [false, 'Add delete buttons'],
'Comment Expansion': [true, 'Expand too long comments'], 'Comment Expansion': [true, 'Expand too long comments'],
'Thread Expansion': [true, 'View all replies'], 'Thread Expansion': [true, 'View all replies'],
@ -1114,20 +1114,29 @@
return Menu.open(Main.preParse($.x('ancestor::div[contains(@class,"postContainer")][1]', this))); return Menu.open(Main.preParse($.x('ancestor::div[contains(@class,"postContainer")][1]', this)));
}, },
open: function(post) { open: function(post) {
var entry, i, _i, _len, _ref; var el, entry, _i, _len, _ref;
for (i in post) { el = Menu.el;
$.add(Menu.el, $.el('code', { el.setAttribute('data-id', post.ID);
className: 'entry', el.setAttribute('data-rootid', post.root.id);
textContent: "" + i + ": " + post[i]
}));
}
_ref = Menu.entries; _ref = Menu.entries;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
entry = _ref[_i]; entry = _ref[_i];
$.add(Menu.el, entry.el); if ((function() {
$.addClass(entry.el, 'entry'); 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); return $.on(d, 'click', Menu.close);
}, },
close: function() { close: function() {
@ -1135,6 +1144,12 @@
Menu.el.innerHTML = null; Menu.el.innerHTML = null;
delete Menu.lastOpener; delete Menu.lastOpener;
return $.off(d, 'click', Menu.close); 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); $.after((isOP ? piM : pi), file);
} }
$.replace(root.firstChild, pc); $.replace(root.firstChild, Get.cleanPost(pc));
if (cb) { if (cb) {
return cb(); return cb();
} }
}, },
cleanPost: function(root) { 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); post = $('.post', root);
_ref = Array.prototype.slice.call(root.childNodes); _ref = Array.prototype.slice.call(root.childNodes);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -3395,9 +3410,10 @@
} }
} }
now = Date.now(); now = Date.now();
_ref1 = $$('[id]', root); els = $$('[id]', root);
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { els.push(root);
el = _ref1[_j]; for (_j = 0, _len1 = els.length; _j < _len1; _j++) {
el = els[_j];
el.id = "" + now + "_" + el.id; el.id = "" + now + "_" + el.id;
} }
$.rmClass(root, 'forwarded'); $.rmClass(root, 'forwarded');
@ -3849,24 +3865,23 @@
ReportButton = { ReportButton = {
init: function() { init: function() {
this.a = $.el('a', {
className: 'report_button',
innerHTML: '[&nbsp;!&nbsp;]',
href: 'javascript:;'
});
return Main.callbacks.push(this.node);
},
node: function(post) {
var a; var a;
if (!(a = $('.report_button', post.el))) { a = Menu.newEntry('a');
a = ReportButton.a.cloneNode(true); a.href = 'javascript:;';
$.add($('.postInfo', post.el), a); a.textContent = 'Report this post';
} $.addClass(a, 'report_button');
return $.on(a, 'click', ReportButton.report); $.on(a, 'click', ReportButton.report);
return Menu.entries.push({
el: a,
requirements: {
isArchived: false
}
});
}, },
report: function() { report: function() {
var id, set, url; var a, id, set, url;
url = "//sys.4chan.org/" + g.BOARD + "/imgboard.php?mode=report&no=" + ($.x('preceding-sibling::input', this).name); 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(); id = Date.now();
set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200"; set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200";
return window.open(url, id, set); return window.open(url, id, set);

View File

@ -5,7 +5,7 @@ Config =
'Keybinds': [true, 'Binds actions to keys'] 'Keybinds': [true, 'Binds actions to keys']
'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'] 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time']
'File Info Formatting': [true, 'Reformats the file information'] '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'] 'Delete Button': [false, 'Add delete buttons']
'Comment Expansion': [true, 'Expand too long comments'] 'Comment Expansion': [true, 'Expand too long comments']
'Thread Expansion': [true, 'View all replies'] 'Thread Expansion': [true, 'View all replies']
@ -824,7 +824,6 @@ Menu =
@el = $.el 'div', @el = $.el 'div',
className: 'reply dialog' className: 'reply dialog'
id: 'menu' id: 'menu'
$.on @el, 'click', (e) -> e.stopPropagation() $.on @el, 'click', (e) -> e.stopPropagation()
Main.callbacks.push @node Main.callbacks.push @node
@ -847,21 +846,31 @@ Menu =
# Position # Position
s = Menu.el.style s = Menu.el.style
# XXX prevent overflows
s.top = @offsetTop + @offsetHeight + 2 + 'px' s.top = @offsetTop + @offsetHeight + 2 + 'px'
s.left = @offsetLeft + 'px' s.left = @offsetLeft + 'px'
Menu.lastOpener = @ Menu.lastOpener = @
Menu.open Main.preParse $.x 'ancestor::div[contains(@class,"postContainer")][1]', @ Menu.open Main.preParse $.x 'ancestor::div[contains(@class,"postContainer")][1]', @
open: (post) -> open: (post) ->
for i of post {el} = Menu
$.add Menu.el, $.el 'code', # XXX GM/Scriptish require setAttribute
className: 'entry' el.setAttribute 'data-id', post.ID
textContent: "#{i}: #{post[i]}" 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 for entry in Menu.entries
# if the entry matches this post... if (->
$.add Menu.el, entry.el for requirement, val of entry.requirements
$.addClass entry.el, 'entry' # XXX ??? return false if val isnt post[requirement]
$.add d.body, Menu.el true
)()
$.add el, entry.el
# XXX 'context' event?
$.event entry.el, new CustomEvent 'context'
$.add d.body, el
$.on d, 'click', Menu.close $.on d, 'click', Menu.close
close: -> close: ->
$.rm Menu.el $.rm Menu.el
@ -869,6 +878,11 @@ Menu =
delete Menu.lastOpener delete Menu.lastOpener
$.off d, 'click', Menu.close $.off d, 'click', Menu.close
newEntry: (name) ->
$.el name,
className: 'entry'
tabIndex: 0
Keybinds = Keybinds =
init: -> init: ->
for node in $$ '[accesskey]' for node in $$ '[accesskey]'
@ -2654,7 +2668,7 @@ Get =
innerHTML: "<img #{thumb_src} alt='#{if data.media_status isnt 'available' then "Error: #{data.media_status}, " else ''}#{if spoiler then 'Spoiler Image, ' else ''}#{filesize}' data-md5=#{data.media_hash} style='height: #{data.preview_h}px; width: #{data.preview_w}px;'>" innerHTML: "<img #{thumb_src} alt='#{if data.media_status isnt 'available' then "Error: #{data.media_status}, " else ''}#{if spoiler then 'Spoiler Image, ' else ''}#{filesize}' data-md5=#{data.media_hash} style='height: #{data.preview_h}px; width: #{data.preview_w}px;'>"
$.after (if isOP then piM else pi), file $.after (if isOP then piM else pi), file
$.replace root.firstChild, pc $.replace root.firstChild, Get.cleanPost pc
cb() if cb cb() if cb
cleanPost: (root) -> cleanPost: (root) ->
post = $ '.post', root post = $ '.post', root
@ -2663,7 +2677,9 @@ Get =
# Don't mess with other features # Don't mess with other features
now = Date.now() now = Date.now()
for el in $$ '[id]', root els = $$ '[id]', root
els.push root
for el in els
el.id = "#{now}_#{el.id}" el.id = "#{now}_#{el.id}"
$.rmClass root, 'forwarded' $.rmClass root, 'forwarded'
@ -3018,20 +3034,20 @@ DeleteButton =
ReportButton = ReportButton =
init: -> init: ->
@a = $.el 'a', a = Menu.newEntry 'a'
className: 'report_button' a.href = 'javascript:;'
innerHTML: '[&nbsp;!&nbsp;]' a.textContent = 'Report this post'
href: 'javascript:;' $.addClass a, 'report_button'
Main.callbacks.push @node
node: (post) ->
unless a = $ '.report_button', post.el
a = ReportButton.a.cloneNode true
$.add $('.postInfo', post.el), a
$.on a, 'click', ReportButton.report $.on a, 'click', ReportButton.report
Menu.entries.push
el: a
requirements:
isArchived: false
report: -> report: ->
url = "//sys.4chan.org/#{g.BOARD}/imgboard.php?mode=report&no=#{$.x('preceding-sibling::input', @).name}" a = $ '.postNum > a[title="Highlight this post"]', $.id @parentNode.dataset.rootid
id = Date.now() url = "//sys.4chan.org/#{a.pathname.split('/')[1]}/imgboard.php?mode=report&no=#{@parentNode.dataset.id}"
set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200" 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 window.open url, id, set
ThreadStats = ThreadStats =