From 9c59c0d6f9a32726010cd8fd6fa77f1f8e14dd0a Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 11 Jul 2012 23:15:06 +0200 Subject: [PATCH] Add file deletion in the menu. Close #587 --- 4chan_x.user.js | 54 ++++++++++++++++++++++++++++++++++++------------- changelog | 2 ++ script.coffee | 47 +++++++++++++++++++++++++++++++----------- 3 files changed, 77 insertions(+), 26 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 69fe49251..42e09c9a8 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -111,7 +111,7 @@ Menu: { 'Menu': [true, 'Add a drop-down menu in posts.'], 'Report Link': [true, 'Add a report link to the menu.'], - 'Delete Link': [true, 'Add a delete link to the menu.'], + 'Delete Link': [true, 'Add post and image deletion links to the menu.'], 'Download Link': [true, 'Add a download with original filename link to the menu. Chrome-only currently.'], 'Archive Link': [true, 'Add an archive link to the menu.'] }, @@ -4067,33 +4067,59 @@ DeleteLink = { init: function() { - var a; - a = $.el('a', { + var aImage, aPost, children, div; + div = $.el('div', { className: 'delete_link', + textContent: 'Delete' + }); + aPost = $.el('a', { + className: 'delete_post', href: 'javascript:;' }); - return Menu.addEntry({ - el: a, - open: function(post) { - if (post.isArchived) { - return false; - } - a.textContent = 'Delete this post'; - $.on(a, 'click', DeleteLink["delete"]); + aImage = $.el('a', { + className: 'delete_image', + href: 'javascript:;' + }); + children = []; + children.push({ + el: aPost, + open: function() { + aPost.textContent = 'Post'; + $.on(aPost, 'click', DeleteLink["delete"]); return true; } }); + children.push({ + el: aImage, + open: function(post) { + if (!post.img) { + return false; + } + aImage.textContent = 'Image'; + $.on(aImage, 'click', DeleteLink["delete"]); + return true; + } + }); + return Menu.addEntry({ + el: div, + open: function(post) { + return !post.isArchived; + }, + children: children + }); }, "delete": function() { - var board, form, id, m, pwd, self; + var board, form, id, m, menu, pwd, self; $.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]; + menu = $.id('menu'); + id = menu.dataset.id; + board = $('.postNum > a[title="Highlight this post"]', $.id(menu.dataset.rootid)).pathname.split('/')[1]; self = this; form = { mode: 'usrdel', + onlyimgdel: /\bdelete_image\b/.test(this.className), pwd: pwd }; form[id] = 'delete'; diff --git a/changelog b/changelog index 39c95b4db..9ee3b9f96 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master +- Mayhem + Divide the Delete Link in the Menu into a Post and Image deletion links. 2.34.1 - Mayhem diff --git a/script.coffee b/script.coffee index 5854bcf2e..ba815e1e0 100644 --- a/script.coffee +++ b/script.coffee @@ -27,7 +27,7 @@ Config = Menu: 'Menu': [true, 'Add a drop-down menu in posts.'] 'Report Link': [true, 'Add a report link to the menu.'] - 'Delete Link': [true, 'Add a delete link to the menu.'] + 'Delete Link': [true, 'Add post and image deletion links to the menu.'] 'Download Link': [true, 'Add a download with original filename link to the menu. Chrome-only currently.'] 'Archive Link': [true, 'Add an archive link to the menu.'] Monitoring: @@ -3231,17 +3231,38 @@ Quotify = DeleteLink = init: -> - a = $.el 'a', + div = $.el 'div', className: 'delete_link' + textContent: 'Delete' + aPost = $.el 'a', + className: 'delete_post' href: 'javascript:;' - Menu.addEntry - el: a - open: (post) -> - if post.isArchived - return false - a.textContent = 'Delete this post' - $.on a, 'click', DeleteLink.delete + aImage = $.el 'a', + className: 'delete_image' + href: 'javascript:;' + + children = [] + + children.push + el: aPost + open: -> + aPost.textContent = 'Post' + $.on aPost, 'click', DeleteLink.delete true + + children.push + el: aImage + open: (post) -> + return false unless post.img + aImage.textContent = 'Image' + $.on aImage, 'click', DeleteLink.delete + true + + Menu.addEntry + el: div + open: (post) -> !post.isArchived + children: children + delete: -> $.off @, 'click', DeleteLink.delete @textContent = 'Deleting...' @@ -3252,13 +3273,15 @@ DeleteLink = else $.id('delPassword').value - id = @parentNode.dataset.id + menu = $.id 'menu' + id = menu.dataset.id board = $('.postNum > a[title="Highlight this post"]', - $.id @parentNode.dataset.rootid).pathname.split('/')[1] - self = this + $.id menu.dataset.rootid).pathname.split('/')[1] + self = @ form = mode: 'usrdel' + onlyimgdel: /\bdelete_image\b/.test @className pwd: pwd form[id] = 'delete'