From 63245dfd925769c45beb570ba804165cbdc55b8d Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 13 Feb 2016 13:40:03 -0800 Subject: [PATCH] Support turning Cooldown setting on and off without reloading. #763 --- src/Menu/DeleteLink.coffee | 4 ++-- src/Posting/QR.cooldown.coffee | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Menu/DeleteLink.coffee b/src/Menu/DeleteLink.coffee index 49138116b..870fc9ddf 100644 --- a/src/Menu/DeleteLink.coffee +++ b/src/Menu/DeleteLink.coffee @@ -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 diff --git a/src/Posting/QR.cooldown.coffee b/src/Posting/QR.cooldown.coffee index 2868bf840..0dbe95eef 100644 --- a/src/Posting/QR.cooldown.coffee +++ b/src/Posting/QR.cooldown.coffee @@ -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