Support turning Cooldown setting on and off without reloading. #763

This commit is contained in:
ccd0 2016-02-13 13:40:03 -08:00
parent 77a32e3371
commit 63245dfd92
2 changed files with 7 additions and 8 deletions

View File

@ -95,7 +95,7 @@ DeleteLink =
else if msg = resDoc.getElementById 'errmsg' # error!
new Notice 'warning', msg.textContent, 20
$.on link, 'click', DeleteLink.toggle if post.fullID is DeleteLink.post.fullID
if Conf['Quick Reply'] and Conf['Cooldown'] and /\bwait\b/i.test(msg.textContent)
if QR.cooldown.data and Conf['Cooldown'] and /\bwait\b/i.test(msg.textContent)
DeleteLink.cooldown.start post, 5
DeleteLink.auto[+fileOnly][post.fullID] = true
DeleteLink.nodes.links[+fileOnly].textContent = DeleteLink.linkText fileOnly
@ -124,7 +124,7 @@ DeleteLink =
count: (post) ->
DeleteLink.nodes.menu.textContent = DeleteLink.menuText() if post.fullID is DeleteLink.post.fullID
if DeleteLink.cooldown.seconds[post.fullID] > 0
if DeleteLink.cooldown.seconds[post.fullID] > 0 and Conf['Cooldown']
DeleteLink.cooldown.seconds[post.fullID]--
setTimeout DeleteLink.cooldown.count, 1000, post
else

View File

@ -11,14 +11,12 @@ QR.cooldown =
# Called from Main
init: ->
return unless Conf['Quick Reply'] and Conf['Cooldown']
return unless Conf['Quick Reply']
@data = Conf['cooldowns']
$.sync 'cooldowns', @sync
# Called from QR
setup: ->
return unless Conf['Cooldown']
# Read cooldown times
if m = Get.scriptData().match /\bcooldowns *= *({[^}]+})/
$.extend QR.cooldown.delays, JSON.parse m[1]
@ -34,6 +32,7 @@ QR.cooldown =
start: ->
{data} = QR.cooldown
return unless (
Conf['Cooldown'] and
QR.cooldown.isSetup and
!QR.cooldown.isCounting and
Object.keys(data[g.BOARD.ID] or {}).length + Object.keys(data.global or {}).length > 0
@ -66,7 +65,7 @@ QR.cooldown =
QR.cooldown.start()
delete: (post) ->
return unless Conf['Cooldown']
return unless QR.cooldown.data
$.forceSync 'cooldowns'
cooldowns = (QR.cooldown.data[post.board.ID] or= {})
for id, cooldown of cooldowns
@ -75,7 +74,7 @@ QR.cooldown =
QR.cooldown.save [post.board.ID]
secondsDeletion: (post) ->
return 0 unless Conf['Quick Reply'] and Conf['Cooldown']
return 0 unless QR.cooldown.data and Conf['Cooldown']
cooldowns = QR.cooldown.data[post.board.ID] or {}
for start, cooldown of cooldowns
if !cooldown.delay? and cooldown.threadID is post.thread.ID and cooldown.postID is post.ID
@ -110,7 +109,7 @@ QR.cooldown =
{type, threadID} = QR.cooldown.categorize QR.posts[0]
seconds = 0
for scope in [g.BOARD.ID, 'global']
if Conf['Cooldown'] then for scope in [g.BOARD.ID, 'global']
cooldowns = (QR.cooldown.data[scope] or= {})
for start, cooldown of cooldowns