diff --git a/4chan_x.user.js b/4chan_x.user.js index 37bf5a0e4..9e8ecabd2 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -72,7 +72,7 @@ */ (function() { - var $, $$, Anonymize, AutoGif, Conf, Config, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, ImageExpand, ImageHover, Keybinds, Main, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportButton, RevealSpoilers, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Time, TitlePost, UI, Unread, Updater, Watcher, d, g, _base; + var $, $$, Anonymize, AutoGif, Conf, Config, DeleteButton, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, ImageExpand, ImageHover, Keybinds, Main, Nav, Options, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Redirect, ReplyHiding, ReportButton, RevealSpoilers, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Time, TitlePost, UI, Unread, Updater, Watcher, d, g, _base; Config = { main: { @@ -82,6 +82,7 @@ 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'], 'File Info Formatting': [true, 'Reformats the file information'], 'Report Button': [true, 'Add report buttons'], + 'Delete Button': [false, 'Add delete buttons'], 'Comment Expansion': [true, 'Expand too long comments'], 'Thread Expansion': [true, 'View all replies'], 'Index Navigation': [true, 'Navigate to previous / next thread'], @@ -3418,6 +3419,73 @@ } }; + DeleteButton = { + 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"]); + }, + "delete": function() { + var board, form, id, m, o, pwd, self; + $.off(this, 'click', DeleteButton["delete"]); + this.textContent = '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]; + self = this; + o = { + mode: 'usrdel', + pwd: pwd + }; + o[id] = 'delete'; + form = $.formData(o); + return $.ajax("https://sys.4chan.org/" + board + "/imgboard.php", { + onload: function() { + return DeleteButton.load(self, this.response); + }, + onerror: function() { + return DeleteButton.error(self); + } + }, { + type: 'post', + form: form + }); + }, + load: function(self, html) { + var doc, msg, tc; + doc = d.implementation.createHTMLDocument(''); + doc.documentElement.innerHTML = html; + if (doc.title === '4chan - Banned') { + tc = 'Banned!'; + } else if (msg = doc.getElementById('errmsg')) { + tc = msg.textContent; + $.on(self, 'click', DeleteButton["delete"]); + } else { + tc = 'Deleted'; + } + return self.textContent = tc; + }, + error: function(self) { + self.textContent = 'Connection error, please retry.'; + return $.on(self, 'click', DeleteButton["delete"]); + } + }; + ReportButton = { init: function() { this.a = $.el('a', { @@ -4055,6 +4123,9 @@ if (Conf['Report Button']) { ReportButton.init(); } + if (Conf['Delete Button']) { + DeleteButton.init(); + } if (Conf['Resurrect Quotes']) { Quotify.init(); } @@ -4677,6 +4748,13 @@ div.opContainer {\ text-decoration: none;\ border-bottom: 1px dashed;\ }\ +/* \\00A0 is nbsp */\ +.delete_button::before {\ + content: "[\\00a0"\ +}\ +.delete_button::after {\ + content: "\\00a0]"\ +}\ ' }; diff --git a/changelog b/changelog index 79ba5bcfb..f8965c85f 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master +- aeosynth + delete button 2.31.6 - Mayhem diff --git a/script.coffee b/script.coffee index 20083919c..111337bde 100644 --- a/script.coffee +++ b/script.coffee @@ -6,6 +6,7 @@ Config = 'Time Formatting': [true, 'Arbitrarily formatted timestamps, using your local time'] 'File Info Formatting': [true, 'Reformats the file information'] 'Report Button': [true, 'Add report buttons'] + 'Delete Button': [false, 'Add delete buttons'] 'Comment Expansion': [true, 'Expand too long comments'] 'Thread Expansion': [true, 'View all replies'] 'Index Navigation': [true, 'Navigate to previous / next thread'] @@ -2609,6 +2610,59 @@ Quotify = $.replace node, nodes return +DeleteButton = + 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 + delete: -> + $.off @, 'click', DeleteButton.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] + self = this + + o = + mode: 'usrdel' + pwd: pwd + o[id] = 'delete' + form = $.formData o + + $.ajax "https://sys.4chan.org/#{board}/imgboard.php", { + onload: -> DeleteButton.load self, @response + onerror: -> DeleteButton.error self + }, { + type: 'post' + form: form + } + + load: (self, html) -> + doc = d.implementation.createHTMLDocument '' + doc.documentElement.innerHTML = html + if doc.title is '4chan - Banned' # Ban/warn check + tc = 'Banned!' + else if msg = doc.getElementById 'errmsg' # error! + tc = msg.textContent + $.on self, 'click', DeleteButton.delete + else + tc = 'Deleted' + self.textContent = tc + error: (self) -> + self.textContent = 'Connection error, please retry.' + $.on self, 'click', DeleteButton.delete + ReportButton = init: -> @a = $.el 'a', @@ -3086,6 +3140,9 @@ Main = if Conf['Report Button'] ReportButton.init() + if Conf['Delete Button'] + DeleteButton.init() + if Conf['Resurrect Quotes'] Quotify.init() @@ -3648,6 +3705,13 @@ div.opContainer { text-decoration: none; border-bottom: 1px dashed; } +/* \\00A0 is nbsp */ +.delete_button::before { + content: "[\\00a0" +} +.delete_button::after { + content: "\\00a0]" +} ' Main.init()