From ee53c212cf0ca88ecf453e6de89ae42dcd7bc5b3 Mon Sep 17 00:00:00 2001 From: AchtBit <8bitfur@gmail.com> Date: Sun, 15 Feb 2015 16:57:02 -0600 Subject: [PATCH 1/5] Implement additional cooldown. --- src/General/Config.coffee | 2 ++ src/General/Settings.coffee | 4 ++-- src/General/css/style.css | 3 +++ src/General/html/Features/QuickReply.html | 1 + src/General/html/Settings/Advanced.html | 7 +++++++ src/Posting/QR.coffee | 18 ++++++++++++++++++ src/Posting/QR.cooldown.coffee | 8 ++++++++ 7 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 67f941ae4..525d65438 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -935,3 +935,5 @@ Config = 'Increase the intervals between updates on threads without new posts.' ] 'Interval': 30 + + additionalCooldown: 0 diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index 1518da3df..af928ff94 100755 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -315,7 +315,7 @@ Settings = items = {} inputs = {} - for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss'] + for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss', 'additionalCooldown'] input = $ "[name='#{name}']", section items[name] = Conf[name] inputs[name] = input @@ -339,7 +339,7 @@ Settings = for key, val of items input = inputs[key] input.value = val - continue if key is 'usercss' + continue if key in ['usercss', 'additionalCooldown'] Settings[key].call input return diff --git a/src/General/css/style.css b/src/General/css/style.css index fed33c815..014e807e1 100755 --- a/src/General/css/style.css +++ b/src/General/css/style.css @@ -1277,6 +1277,9 @@ input#qr-filename:not(.edit) { #file-n-submit { height: 23px; } +#file-n-submit.add-cooldown { + height: 43px; +} #qr input[type="file"] { visibility: hidden; position: absolute; diff --git a/src/General/html/Features/QuickReply.html b/src/General/html/Features/QuickReply.html index c1401fc53..c9ed33c32 100755 --- a/src/General/html/Features/QuickReply.html +++ b/src/General/html/Features/QuickReply.html @@ -36,6 +36,7 @@ + #{if parseInt(Conf['additionalCooldown']) > 0 then 'Enable Custom Cooldown' else ''} diff --git a/src/General/html/Settings/Advanced.html b/src/General/html/Settings/Advanced.html index 6a2b6c095..dbd7a1326 100755 --- a/src/General/html/Settings/Advanced.html +++ b/src/General/html/Settings/Advanced.html @@ -109,6 +109,13 @@ +
+ Additional Cooldown Time +
+ Seconds: +
+
+
diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 2ceb7a7c8..b7b5ca043 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -166,6 +166,16 @@ QR = else QR.unhide() + toggleAddCooldown: -> + if @checked + QR.cooldown.addCooldown = true + if QR.cooldown.seconds + QR.cooldown.seconds += parseInt(Conf['additionalCooldown']) + else + QR.cooldown.addCooldown = false + if QR.cooldown.seconds + QR.cooldown.seconds -= parseInt(Conf['additionalCooldown']) + error: (err) -> QR.open() if typeof err is 'string' @@ -485,6 +495,7 @@ QR = setNode 'spoilerPar', '#qr-spoiler-label' setNode 'status', '[type=submit]' setNode 'fileInput', '[type=file]' + setNode 'addCooldown', '[data-name=addCooldown]' rules = $('ul.rules').textContent.trim() match_min = rules.match(/.+smaller than (\d+)x(\d+).+/) @@ -522,6 +533,11 @@ QR = else nodes.spoiler.parentElement.hidden = true + if parseInt(Conf['additionalCooldown']) > 0 + $.addClass QR.nodes.fileSubmit, 'add-cooldown' + else + $.rmClass QR.nodes.fileSubmit, 'add-cooldown' + if g.BOARD.ID is 'f' and g.VIEW isnt 'thread' nodes.flashTag = $.el 'select', name: 'filetag' @@ -552,6 +568,8 @@ QR = $.on nodes.fileExtras, 'click', (e) -> e.stopPropagation() $.on nodes.spoiler, 'change', -> QR.selected.nodes.spoiler.click() $.on nodes.fileInput, 'change', QR.handleFiles + if parseInt(Conf['additionalCooldown']) > 0 + $.on nodes.addCooldown,'change', QR.toggleAddCooldown # save selected post's data items = ['thread', 'name', 'email', 'sub', 'com', 'filename'] diff --git a/src/Posting/QR.cooldown.coffee b/src/Posting/QR.cooldown.coffee index ba5e4de65..c4ea679cb 100644 --- a/src/Posting/QR.cooldown.coffee +++ b/src/Posting/QR.cooldown.coffee @@ -105,6 +105,10 @@ QR.cooldown = seconds = Math.max seconds, cooldown.delay - elapsed continue + # Increase the max delay if additional cooldown is enabled + if QR.cooldown.addCooldown + QR.cooldown.maxDelay = QR.cooldown.maxDelay + parseInt(Conf['additionalCooldown']) + # Clean up expired cooldowns maxDelay = if cooldown.threadID isnt cooldown.postID QR.cooldown.maxDelay @@ -127,6 +131,10 @@ QR.cooldown = '' seconds = Math.max seconds, QR.cooldown.delays[type + suffix] - elapsed + # If additional cooldown is enabled, add the configured seconds to the count. + if QR.cooldown.addCooldown + seconds = Math.max seconds, QR.cooldown.delays[type] + parseInt(Conf['additionalCooldown']) - elapsed + QR.cooldown.save scope if save if Object.keys(QR.cooldown.local).length + Object.keys(QR.cooldown.global).length From d03ed4b8628db455eb0d34b7696b1012ca052f62 Mon Sep 17 00:00:00 2001 From: AchtBit <8bitfur@gmail.com> Date: Tue, 17 Feb 2015 19:08:19 -0600 Subject: [PATCH 2/5] Don't set value in HTML. --- src/General/html/Settings/Advanced.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/General/html/Settings/Advanced.html b/src/General/html/Settings/Advanced.html index dbd7a1326..1170a85d0 100755 --- a/src/General/html/Settings/Advanced.html +++ b/src/General/html/Settings/Advanced.html @@ -112,7 +112,7 @@
Additional Cooldown Time
- Seconds: + Seconds:
From 5c9014cfd28ee6b024ba6f82e4991e8edfd1763d Mon Sep 17 00:00:00 2001 From: AchtBit <8bitfur@gmail.com> Date: Tue, 17 Feb 2015 19:18:11 -0600 Subject: [PATCH 3/5] span->label. Hide label in CSS. --- src/General/css/style.css | 3 +++ src/General/html/Features/QuickReply.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/General/css/style.css b/src/General/css/style.css index 014e807e1..65e727123 100755 --- a/src/General/css/style.css +++ b/src/General/css/style.css @@ -1280,6 +1280,9 @@ input#qr-filename:not(.edit) { #file-n-submit.add-cooldown { height: 43px; } +#file-n-submit:not(.add-cooldown) #add-cooldown-label { + display: none; +} #qr input[type="file"] { visibility: hidden; position: absolute; diff --git a/src/General/html/Features/QuickReply.html b/src/General/html/Features/QuickReply.html index c9ed33c32..fa1187734 100755 --- a/src/General/html/Features/QuickReply.html +++ b/src/General/html/Features/QuickReply.html @@ -36,7 +36,7 @@ - #{if parseInt(Conf['additionalCooldown']) > 0 then 'Enable Custom Cooldown' else ''} + From 7568f0c64e911eb3e50c37eacee6234d29e1023e Mon Sep 17 00:00:00 2001 From: AchtBit <8bitfur@gmail.com> Date: Tue, 17 Feb 2015 19:27:51 -0600 Subject: [PATCH 4/5] Increase maxDelay instead of QR.cooldown.maxDelay. --- src/Posting/QR.cooldown.coffee | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Posting/QR.cooldown.coffee b/src/Posting/QR.cooldown.coffee index c4ea679cb..50bf5aee4 100644 --- a/src/Posting/QR.cooldown.coffee +++ b/src/Posting/QR.cooldown.coffee @@ -105,15 +105,13 @@ QR.cooldown = seconds = Math.max seconds, cooldown.delay - elapsed continue - # Increase the max delay if additional cooldown is enabled - if QR.cooldown.addCooldown - QR.cooldown.maxDelay = QR.cooldown.maxDelay + parseInt(Conf['additionalCooldown']) - # Clean up expired cooldowns maxDelay = if cooldown.threadID isnt cooldown.postID QR.cooldown.maxDelay else QR.cooldown.delays[if scope is 'global' then 'thread_global' else 'thread'] + if QR.cooldown.addCooldown + maxDelay += parseInt(Conf['additionalCooldown']) if maxDelay <= elapsed delete QR.cooldown[scope][start] save = true From 8358197d7f1e7528c1c5f2b7cd7f661ac0e9bf78 Mon Sep 17 00:00:00 2001 From: AchtBit <8bitfur@gmail.com> Date: Tue, 17 Feb 2015 19:40:55 -0600 Subject: [PATCH 5/5] Don't update in toggleAddCooldown. --- src/Posting/QR.coffee | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index b7b5ca043..5dad77f94 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -169,12 +169,8 @@ QR = toggleAddCooldown: -> if @checked QR.cooldown.addCooldown = true - if QR.cooldown.seconds - QR.cooldown.seconds += parseInt(Conf['additionalCooldown']) else QR.cooldown.addCooldown = false - if QR.cooldown.seconds - QR.cooldown.seconds -= parseInt(Conf['additionalCooldown']) error: (err) -> QR.open()