Move the Delete Buttons into the menu as Delete Links. Enable by default. Fix cross-board deleting.

This commit is contained in:
Nicolas Stepien 2012-06-24 00:22:47 +02:00
parent f23915b5e7
commit 7b22bb4839
2 changed files with 62 additions and 64 deletions

View File

@ -77,7 +77,7 @@
*/
(function() {
var $, $$, Anonymize, AutoGif, Conf, Config, DeleteButton, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, Get, ImageExpand, ImageHover, Keybinds, Main, Menu, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportLink, RevealSpoilers, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Time, TitlePost, UI, Unread, Updater, Watcher, d, g, _base;
var $, $$, Anonymize, AutoGif, Conf, Config, DeleteLink, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, Get, ImageExpand, ImageHover, Keybinds, Main, Menu, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportLink, RevealSpoilers, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Time, TitlePost, UI, Unread, Updater, Watcher, d, g, _base;
Config = {
main: {
@ -87,7 +87,7 @@
'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'],
'File Info Formatting': [true, 'Reformats the file information'],
'Report Link': [true, 'Add report links'],
'Delete Button': [false, 'Add delete buttons'],
'Delete Link': [true, 'Add delete links'],
'Comment Expansion': [true, 'Expand too long comments'],
'Thread Expansion': [true, 'View all replies'],
'Index Navigation': [true, 'Navigate to previous / next thread'],
@ -3798,46 +3798,42 @@
}
};
DeleteButton = {
DeleteLink = {
init: function() {
this.a = $.el('a', {
className: 'delete_button',
innerHTML: '[ × ]',
href: 'javascript:;'
});
return Main.callbacks.push(this.node);
},
node: function(post) {
var a;
if (!(a = $('.delete_button', post.el))) {
a = DeleteButton.a.cloneNode(true);
$.add($('.postInfo', post.el), a);
}
return $.on(a, 'click', DeleteButton["delete"]);
a = Menu.newEntry('a');
a.href = 'javascript:;';
$.addClass(a, 'delete_link');
$.on(a, 'context', function() {
a.textContent = 'Delete this post';
return $.on(a, 'click', DeleteLink["delete"]);
});
return Menu.entries.push({
el: a,
requirements: {
isArchived: false
}
});
},
"delete": function() {
var board, form, id, m, pwd, self;
$.off(this, 'click', DeleteButton["delete"]);
this.innerHTML = '[ Deleting... ]';
if (m = d.cookie.match(/4chan_pass=([^;]+)/)) {
pwd = decodeURIComponent(m[1]);
} else {
pwd = $.id('delPassword').value;
}
id = $.x('preceding-sibling::input', this).name;
board = $.x('preceding-sibling::span[1]/a', this).pathname.match(/\w+/)[0];
$.off(this, 'click', DeleteLink["delete"]);
this.textContent = 'Deleting...';
pwd = (m = d.cookie.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $.id('delPassword').value;
id = this.parentNode.dataset.id;
board = $('.postNum > a[title="Highlight this post"]', $.id(this.parentNode.dataset.rootid)).pathname.split('/')[1];
self = this;
form = {
mode: 'usrdel',
pwd: pwd
};
form[id] = 'delete';
return $.ajax("https://sys.4chan.org/" + board + "/imgboard.php", {
return $.ajax($.id('delform').action.replace("/" + g.BOARD + "/", "/" + board + "/"), {
onload: function() {
return DeleteButton.load(self, this.response);
return DeleteLink.load(self, this.response);
},
onerror: function() {
return DeleteButton.error(self);
return DeleteLink.error(self);
}
}, {
form: $.formData(form)
@ -3851,15 +3847,15 @@
s = 'Banned!';
} else if (msg = doc.getElementById('errmsg')) {
s = msg.textContent;
$.on(self, 'click', DeleteButton["delete"]);
$.on(self, 'click', DeleteLink["delete"]);
} else {
s = 'Deleted';
}
return self.innerHTML = "[ " + s + " ]";
return self.textContent = s;
},
error: function(self) {
self.innerHTML = '[ Connection error, please retry. ]';
return $.on(self, 'click', DeleteButton["delete"]);
self.textContent = 'Connection error, please retry.';
return $.on(self, 'click', DeleteLink["delete"]);
}
};
@ -4533,8 +4529,8 @@
if (Conf['Report Link']) {
ReportLink.init();
}
if (Conf['Delete Button']) {
DeleteButton.init();
if (Conf['Delete Link']) {
DeleteLink.init();
}
if (Conf['Resurrect Quotes']) {
Quotify.init();

View File

@ -6,7 +6,7 @@ Config =
'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time']
'File Info Formatting': [true, 'Reformats the file information']
'Report Link': [true, 'Add report links']
'Delete Button': [false, 'Add delete buttons']
'Delete Link': [true, 'Add delete links']
'Comment Expansion': [true, 'Expand too long comments']
'Thread Expansion': [true, 'View all replies']
'Index Navigation': [true, 'Navigate to previous / next thread']
@ -2981,28 +2981,31 @@ Quotify =
$.replace node, nodes
return
DeleteButton =
DeleteLink =
init: ->
@a = $.el 'a',
className: 'delete_button'
innerHTML: '[ × ]'
href: 'javascript:;'
Main.callbacks.push @node
node: (post) ->
unless a = $ '.delete_button', post.el
a = DeleteButton.a.cloneNode true
$.add $('.postInfo', post.el), a
$.on a, 'click', DeleteButton.delete
a = Menu.newEntry 'a'
a.href = 'javascript:;'
$.addClass a, 'delete_link'
$.on a, 'context', ->
a.textContent = 'Delete this post'
$.on a, 'click', DeleteLink.delete
Menu.entries.push
el: a
requirements:
isArchived: false
delete: ->
$.off @, 'click', DeleteButton.delete
@innerHTML = '[ Deleting... ]'
$.off @, 'click', DeleteLink.delete
@textContent = 'Deleting...'
if m = d.cookie.match /4chan_pass=([^;]+)/
pwd = decodeURIComponent m[1]
else
pwd = $.id('delPassword').value
id = $.x('preceding-sibling::input', @).name
board = $.x('preceding-sibling::span[1]/a', @).pathname.match(/\w+/)[0]
pwd =
if m = d.cookie.match /4chan_pass=([^;]+)/
decodeURIComponent m[1]
else
$.id('delPassword').value
id = @parentNode.dataset.id
board = $('.postNum > a[title="Highlight this post"]',
$.id @parentNode.dataset.rootid).pathname.split('/')[1]
self = this
form =
@ -3010,13 +3013,12 @@ DeleteButton =
pwd: pwd
form[id] = 'delete'
$.ajax "https://sys.4chan.org/#{board}/imgboard.php", {
onload: -> DeleteButton.load self, @response
onerror: -> DeleteButton.error self
$.ajax $.id('delform').action.replace("/#{g.BOARD}/", "/#{board}/"), {
onload: -> DeleteLink.load self, @response
onerror: -> DeleteLink.error self
}, {
form: $.formData form
}
load: (self, html) ->
doc = d.implementation.createHTMLDocument ''
doc.documentElement.innerHTML = html
@ -3024,13 +3026,13 @@ DeleteButton =
s = 'Banned!'
else if msg = doc.getElementById 'errmsg' # error!
s = msg.textContent
$.on self, 'click', DeleteButton.delete
$.on self, 'click', DeleteLink.delete
else
s = 'Deleted'
self.innerHTML = "[ #{s} ]"
self.textContent = s
error: (self) ->
self.innerHTML = '[ Connection error, please retry. ]'
$.on self, 'click', DeleteButton.delete
self.textContent = 'Connection error, please retry.'
$.on self, 'click', DeleteLink.delete
ReportLink =
init: ->
@ -3529,8 +3531,8 @@ Main =
if Conf['Report Link']
ReportLink.init()
if Conf['Delete Button']
DeleteButton.init()
if Conf['Delete Link']
DeleteLink.init()
if Conf['Resurrect Quotes']
Quotify.init()