Merge branch 'autodelete'
This commit is contained in:
commit
08f25faf4f
@ -1,4 +1,6 @@
|
|||||||
DeleteLink =
|
DeleteLink =
|
||||||
|
auto: [{}, {}]
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
return unless g.VIEW in ['index', 'thread'] and Conf['Menu'] and Conf['Delete Link']
|
return unless g.VIEW in ['index', 'thread'] and Conf['Menu'] and Conf['Delete Link']
|
||||||
|
|
||||||
@ -11,19 +13,20 @@ DeleteLink =
|
|||||||
fileEl = $.el 'a',
|
fileEl = $.el 'a',
|
||||||
className: 'delete-file'
|
className: 'delete-file'
|
||||||
href: 'javascript:;'
|
href: 'javascript:;'
|
||||||
|
@links = [postEl, fileEl]
|
||||||
|
|
||||||
postEntry =
|
postEntry =
|
||||||
el: postEl
|
el: postEl
|
||||||
open: ->
|
open: ->
|
||||||
postEl.textContent = 'Post'
|
postEl.textContent = DeleteLink.linkText false
|
||||||
$.on postEl, 'click', DeleteLink.delete
|
$.on postEl, 'click', DeleteLink.toggle
|
||||||
true
|
true
|
||||||
fileEntry =
|
fileEntry =
|
||||||
el: fileEl
|
el: fileEl
|
||||||
open: ({file}) ->
|
open: ({file}) ->
|
||||||
return false if !file or file.isDead
|
return false if !file or file.isDead
|
||||||
fileEl.textContent = 'File'
|
fileEl.textContent = DeleteLink.linkText true
|
||||||
$.on fileEl, 'click', DeleteLink.delete
|
$.on fileEl, 'click', DeleteLink.toggle
|
||||||
true
|
true
|
||||||
|
|
||||||
Menu.menu.addEntry
|
Menu.menu.addEntry
|
||||||
@ -33,18 +36,41 @@ DeleteLink =
|
|||||||
return false if post.isDead
|
return false if post.isDead
|
||||||
DeleteLink.post = post
|
DeleteLink.post = post
|
||||||
node = div.firstChild
|
node = div.firstChild
|
||||||
node.textContent = 'Delete'
|
node.textContent = DeleteLink.menuText()
|
||||||
DeleteLink.cooldown.start post, node
|
DeleteLink.cooldown.start post, node
|
||||||
true
|
true
|
||||||
subEntries: [postEntry, fileEntry]
|
subEntries: [postEntry, fileEntry]
|
||||||
|
|
||||||
delete: ->
|
menuText: ->
|
||||||
{post} = DeleteLink
|
if seconds = DeleteLink.cooldown.seconds[DeleteLink.post.fullID]
|
||||||
return if DeleteLink.cooldown.counting is post
|
"Delete (#{seconds})"
|
||||||
|
else
|
||||||
|
'Delete'
|
||||||
|
|
||||||
$.off @, 'click', DeleteLink.delete
|
linkText: (fileOnly) ->
|
||||||
|
text = if fileOnly then 'File' else 'Post'
|
||||||
|
if DeleteLink.auto[+fileOnly][DeleteLink.post.fullID]
|
||||||
|
text = "Deleting #{text.toLowerCase()}..."
|
||||||
|
text
|
||||||
|
|
||||||
|
toggle: ->
|
||||||
|
{post} = DeleteLink
|
||||||
fileOnly = $.hasClass @, 'delete-file'
|
fileOnly = $.hasClass @, 'delete-file'
|
||||||
@textContent = "Deleting #{if fileOnly then 'file' else 'post'}..."
|
auto = DeleteLink.auto[+fileOnly]
|
||||||
|
|
||||||
|
if auto[post.fullID]
|
||||||
|
delete auto[post.fullID]
|
||||||
|
else
|
||||||
|
auto[post.fullID] = true
|
||||||
|
@textContent = DeleteLink.linkText fileOnly
|
||||||
|
|
||||||
|
unless DeleteLink.cooldown.seconds[post.fullID]
|
||||||
|
DeleteLink.delete post, fileOnly
|
||||||
|
|
||||||
|
delete: (post, fileOnly) ->
|
||||||
|
link = DeleteLink.links[+fileOnly]
|
||||||
|
delete DeleteLink.auto[+fileOnly][post.fullID]
|
||||||
|
$.off link, 'click', DeleteLink.toggle if post.fullID is DeleteLink.post.fullID
|
||||||
|
|
||||||
form =
|
form =
|
||||||
mode: 'usrdel'
|
mode: 'usrdel'
|
||||||
@ -52,47 +78,55 @@ DeleteLink =
|
|||||||
pwd: QR.persona.getPassword()
|
pwd: QR.persona.getPassword()
|
||||||
form[post.ID] = 'delete'
|
form[post.ID] = 'delete'
|
||||||
|
|
||||||
link = @
|
|
||||||
$.ajax $.id('delform').action.replace("/#{g.BOARD}/", "/#{post.board}/"),
|
$.ajax $.id('delform').action.replace("/#{g.BOARD}/", "/#{post.board}/"),
|
||||||
responseType: 'document'
|
responseType: 'document'
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
onload: -> DeleteLink.load link, post, fileOnly, @response
|
onload: -> DeleteLink.load link, post, fileOnly, @response
|
||||||
onerror: -> DeleteLink.error link
|
onerror: -> DeleteLink.error link, post
|
||||||
,
|
,
|
||||||
form: $.formData form
|
form: $.formData form
|
||||||
|
|
||||||
load: (link, post, fileOnly, resDoc) ->
|
load: (link, post, fileOnly, resDoc) ->
|
||||||
|
link.textContent = DeleteLink.linkText fileOnly
|
||||||
if resDoc.title is '4chan - Banned' # Ban/warn check
|
if resDoc.title is '4chan - Banned' # Ban/warn check
|
||||||
s = 'Banned!'
|
el = $.el 'span', <%= html('You can't delete posts because you are <a href="//www.4chan.org/banned" target="_blank">banned</a>.') %>
|
||||||
|
new Notice 'warning', el, 20
|
||||||
else if msg = resDoc.getElementById 'errmsg' # error!
|
else if msg = resDoc.getElementById 'errmsg' # error!
|
||||||
s = msg.textContent
|
new Notice 'warning', msg.textContent, 20
|
||||||
$.on link, 'click', DeleteLink.delete
|
$.on link, 'click', DeleteLink.toggle if post.fullID is DeleteLink.post.fullID
|
||||||
else
|
else
|
||||||
if resDoc.title is 'Updating index...'
|
if resDoc.title is 'Updating index...'
|
||||||
# We're 100% sure.
|
# We're 100% sure.
|
||||||
QR.cooldown.delete post
|
QR.cooldown.delete post
|
||||||
(post.origin or post).kill fileOnly
|
(post.origin or post).kill fileOnly
|
||||||
s = 'Deleted'
|
link.textContent = 'Deleted' if post.fullID is DeleteLink.post.fullID
|
||||||
link.textContent = s
|
|
||||||
error: (link) ->
|
error: (link, post) ->
|
||||||
link.textContent = 'Connection error, please retry.'
|
new Notice 'warning', 'Connection error, please retry.', 20
|
||||||
$.on link, 'click', DeleteLink.delete
|
$.on link, 'click', DeleteLink.toggle if post.fullID is DeleteLink.post.fullID
|
||||||
|
|
||||||
cooldown:
|
cooldown:
|
||||||
|
seconds: {}
|
||||||
|
|
||||||
start: (post, node) ->
|
start: (post, node) ->
|
||||||
unless QR.db?.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID}
|
# Already counting.
|
||||||
# Only start counting on our posts.
|
return if DeleteLink.cooldown.seconds[post.fullID]?
|
||||||
delete DeleteLink.cooldown.counting
|
# Only start counting on our posts.
|
||||||
return
|
return unless QR.db?.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID}
|
||||||
DeleteLink.cooldown.counting = post
|
|
||||||
length = 60
|
length = 60
|
||||||
seconds = Math.ceil (length * $.SECOND - (Date.now() - post.info.date)) / $.SECOND
|
seconds = length - (Date.now() - post.info.date) // $.SECOND
|
||||||
DeleteLink.cooldown.count post, seconds, length, node
|
if 0 < seconds <= length
|
||||||
count: (post, seconds, length, node) ->
|
DeleteLink.cooldown.seconds[post.fullID] = seconds
|
||||||
return if DeleteLink.cooldown.counting isnt post
|
DeleteLink.cooldown.count post, node
|
||||||
unless 0 <= seconds <= length
|
|
||||||
if DeleteLink.cooldown.counting is post
|
count: (post, node) ->
|
||||||
node.textContent = 'Delete'
|
node.textContent = DeleteLink.menuText() if post.fullID is DeleteLink.post.fullID
|
||||||
delete DeleteLink.cooldown.counting
|
if DeleteLink.cooldown.seconds[post.fullID] > 0
|
||||||
return
|
DeleteLink.cooldown.seconds[post.fullID]--
|
||||||
setTimeout DeleteLink.cooldown.count, 1000, post, seconds - 1, length, node
|
setTimeout DeleteLink.cooldown.count, 1000, post, node
|
||||||
node.textContent = "Delete (#{seconds})"
|
else
|
||||||
|
delete DeleteLink.cooldown.seconds[post.fullID]
|
||||||
|
for fileOnly in [false, true] when DeleteLink.auto[+fileOnly][post.fullID]
|
||||||
|
DeleteLink.delete post, fileOnly
|
||||||
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user