Only show delete links for your posts. Close #649

This commit is contained in:
Nicolas Stepien 2013-02-23 18:38:52 +01:00
parent 0c220617d9
commit 67b05f6757
4 changed files with 42 additions and 37 deletions

View File

@ -2409,7 +2409,7 @@
DeleteLink = { DeleteLink = {
init: function() { init: function() {
var div, fileEl, fileEntry, postEl, postEntry; var div, fileEl, fileEntry, postEl, postEntry;
if (g.VIEW === 'catalog' || !Conf['Menu'] || !Conf['Delete Link']) { if (g.VIEW === 'catalog' || !Conf['Menu'] || !Conf['Delete Link'] || !Conf['Quick Reply']) {
return; return;
} }
div = $.el('div', { div = $.el('div', {
@ -2437,21 +2437,25 @@
open: function(_arg) { open: function(_arg) {
var file; var file;
file = _arg.file; file = _arg.file;
if (!file || file.isDead) {
return false;
}
fileEl.textContent = 'File'; fileEl.textContent = 'File';
$.on(fileEl, 'click', DeleteLink["delete"]); $.on(fileEl, 'click', DeleteLink["delete"]);
return !!file; return true;
} }
}; };
$.event('AddMenuEntry', { return $.event('AddMenuEntry', {
type: 'post', type: 'post',
el: div, el: div,
order: 40, order: 40,
open: function(post) { open: function(post) {
var node, seconds; var node, seconds, thread, _ref;
if (post.isDead) { if (post.isDead || !((thread = QR.yourPosts.threads[post.thread]) && (_ref = post.ID, __indexOf.call(thread, _ref) >= 0))) {
return false; return false;
} }
DeleteLink.post = post; DeleteLink.post = post;
DeleteLink.cooldown.start(post);
node = div.firstChild; node = div.firstChild;
if (seconds = DeleteLink.cooldown[post.fullID]) { if (seconds = DeleteLink.cooldown[post.fullID]) {
node.textContent = "Delete (" + seconds + ")"; node.textContent = "Delete (" + seconds + ")";
@ -2464,7 +2468,6 @@
}, },
subEntries: [postEntry, fileEntry] subEntries: [postEntry, fileEntry]
}); });
return $.on(d, 'QRPostSuccessful', this.cooldown.start);
}, },
"delete": function() { "delete": function() {
var form, link, m, post, pwd; var form, link, m, post, pwd;
@ -2512,12 +2515,14 @@
return $.on(link, 'click', DeleteLink["delete"]); return $.on(link, 'click', DeleteLink["delete"]);
}, },
cooldown: { cooldown: {
start: function(e) { start: function(post) {
var board, fullID, postID, seconds, _ref; var length, seconds;
_ref = e.detail, board = _ref.board, postID = _ref.postID; if (post.fullID in DeleteLink.cooldown) {
seconds = board.ID === 'q' ? 600 : 30; return;
fullID = "" + board + "." + postID; }
return DeleteLink.cooldown.count(fullID, seconds, seconds); length = post.board.ID === 'q' ? 600 : 30;
seconds = Math.ceil((length * $.SECOND - (Date.now() - post.info.date)) / $.SECOND);
return DeleteLink.cooldown.count(post.fullID, seconds, length);
}, },
count: function(fullID, seconds, length) { count: function(fullID, seconds, length) {
var el; var el;
@ -6537,13 +6542,13 @@
}; };
$.set('QR.persona', persona); $.set('QR.persona', persona);
_ref1 = h1.nextSibling.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref1[0], threadID = _ref1[1], postID = _ref1[2]; _ref1 = h1.nextSibling.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref1[0], threadID = _ref1[1], postID = _ref1[2];
threadID = +threadID;
postID = +postID; postID = +postID;
threadID = +threadID || postID;
((_base = QR.yourPosts.threads)[threadID] || (_base[threadID] = [])).push(postID); ((_base = QR.yourPosts.threads)[threadID] || (_base[threadID] = [])).push(postID);
$.set("yourPosts." + g.BOARD, QR.yourPosts); $.set("yourPosts." + g.BOARD, QR.yourPosts);
$.event('QRPostSuccessful', { $.event('QRPostSuccessful', {
board: g.BOARD, board: g.BOARD,
threadID: threadID || postID, threadID: threadID,
postID: postID postID: postID
}, QR.el); }, QR.el);
QR.cooldown.set({ QR.cooldown.set({
@ -6551,9 +6556,9 @@
isReply: !!threadID isReply: !!threadID
}); });
QR.cooldown.auto = QR.replies.length > 1; QR.cooldown.auto = QR.replies.length > 1;
if (!threadID) { if (threadID === postID) {
$.open("//boards.4chan.org/" + g.BOARD + "/res/" + postID); $.open("//boards.4chan.org/" + g.BOARD + "/res/" + threadID);
} else if (g.VIEW === 'reply' && !QR.cooldown.auto) { } else if (g.VIEW === 'index' && !QR.cooldown.auto) {
$.open("//boards.4chan.org/" + g.BOARD + "/res/" + threadID + "#p" + postID); $.open("//boards.4chan.org/" + g.BOARD + "/res/" + threadID + "#p" + postID);
} }
if (Conf['Persistent QR'] || QR.cooldown.auto) { if (Conf['Persistent QR'] || QR.cooldown.auto) {

View File

@ -10,8 +10,9 @@ beta
Quick Reply shortcut Quick Reply shortcut
Image Expansion Image Expansion
Can be auto-hidden. Can be auto-hidden.
(You): Egocentrism:
"(You)" will be added to quotes linking to your posts. "(You)" will be added to quotes linking to your posts.
Delete links in the post menu will only appear for your posts.
QR changes: QR changes:
Clicking the submit button while uploading will abort the upload and won't start re-uploading automatically anymore. Clicking the submit button while uploading will abort the upload and won't start re-uploading automatically anymore.

View File

@ -1254,7 +1254,7 @@ ReportLink =
DeleteLink = DeleteLink =
init: -> init: ->
return if g.VIEW is 'catalog' or !Conf['Menu'] or !Conf['Delete Link'] return if g.VIEW is 'catalog' or !Conf['Menu'] or !Conf['Delete Link'] or !Conf['Quick Reply']
div = $.el 'div', div = $.el 'div',
className: 'delete-link' className: 'delete-link'
@ -1275,17 +1275,19 @@ DeleteLink =
fileEntry = fileEntry =
el: fileEl el: fileEl
open: ({file}) -> open: ({file}) ->
return false if !file or file.isDead
fileEl.textContent = 'File' fileEl.textContent = 'File'
$.on fileEl, 'click', DeleteLink.delete $.on fileEl, 'click', DeleteLink.delete
!!file true
$.event 'AddMenuEntry', $.event 'AddMenuEntry',
type: 'post' type: 'post'
el: div el: div
order: 40 order: 40
open: (post) -> open: (post) ->
return false if post.isDead return false if post.isDead or !((thread = QR.yourPosts.threads[post.thread]) and post.ID in thread)
DeleteLink.post = post DeleteLink.post = post
DeleteLink.cooldown.start post
node = div.firstChild node = div.firstChild
if seconds = DeleteLink.cooldown[post.fullID] if seconds = DeleteLink.cooldown[post.fullID]
node.textContent = "Delete (#{seconds})" node.textContent = "Delete (#{seconds})"
@ -1296,8 +1298,6 @@ DeleteLink =
true true
subEntries: [postEntry, fileEntry] subEntries: [postEntry, fileEntry]
$.on d, 'QRPostSuccessful', @cooldown.start
delete: -> delete: ->
{post} = DeleteLink {post} = DeleteLink
return if DeleteLink.cooldown[post.fullID] return if DeleteLink.cooldown[post.fullID]
@ -1340,15 +1340,14 @@ DeleteLink =
$.on link, 'click', DeleteLink.delete $.on link, 'click', DeleteLink.delete
cooldown: cooldown:
start: (e) -> start: (post) ->
{board, postID} = e.detail return if post.fullID of DeleteLink.cooldown
seconds = length = if post.board.ID is 'q'
if board.ID is 'q' 600
600 else
else 30
30 seconds = Math.ceil (length * $.SECOND - (Date.now() - post.info.date)) / $.SECOND
fullID = "#{board}.#{postID}" DeleteLink.cooldown.count post.fullID, seconds, length
DeleteLink.cooldown.count fullID, seconds, seconds
count: (fullID, seconds, length) -> count: (fullID, seconds, length) ->
return unless 0 <= seconds <= length return unless 0 <= seconds <= length
setTimeout DeleteLink.cooldown.count, 1000, fullID, seconds-1, length setTimeout DeleteLink.cooldown.count, 1000, fullID, seconds-1, length

View File

@ -812,8 +812,8 @@ QR =
$.set 'QR.persona', persona $.set 'QR.persona', persona
[_, threadID, postID] = h1.nextSibling.textContent.match /thread:(\d+),no:(\d+)/ [_, threadID, postID] = h1.nextSibling.textContent.match /thread:(\d+),no:(\d+)/
threadID = +threadID
postID = +postID postID = +postID
threadID = +threadID or postID
(QR.yourPosts.threads[threadID] or= []).push postID (QR.yourPosts.threads[threadID] or= []).push postID
$.set "yourPosts.#{g.BOARD}", QR.yourPosts $.set "yourPosts.#{g.BOARD}", QR.yourPosts
@ -821,7 +821,7 @@ QR =
# Post/upload confirmed as successful. # Post/upload confirmed as successful.
$.event 'QRPostSuccessful', { $.event 'QRPostSuccessful', {
board: g.BOARD board: g.BOARD
threadID: threadID or postID threadID
postID postID
}, QR.el }, QR.el
@ -832,9 +832,9 @@ QR =
# Enable auto-posting if we have stuff to post, disable it otherwise. # Enable auto-posting if we have stuff to post, disable it otherwise.
QR.cooldown.auto = QR.replies.length > 1 QR.cooldown.auto = QR.replies.length > 1
unless threadID # new thread if threadID is postID # new thread
$.open "//boards.4chan.org/#{g.BOARD}/res/#{postID}" $.open "//boards.4chan.org/#{g.BOARD}/res/#{threadID}"
else if g.VIEW is 'reply' and !QR.cooldown.auto # posting from the index else if g.VIEW is 'index' and !QR.cooldown.auto # posting from the index
$.open "//boards.4chan.org/#{g.BOARD}/res/#{threadID}#p#{postID}" $.open "//boards.4chan.org/#{g.BOARD}/res/#{threadID}#p#{postID}"
if Conf['Persistent QR'] or QR.cooldown.auto if Conf['Persistent QR'] or QR.cooldown.auto