4chan-x icon indicating copy to clipboard operation
4chan-x copied to clipboard

Cooldown

Open unknown-- opened this issue 11 years ago • 7 comments

Lately I've had to wait 90 seconds between posts on /vg/. It's possible that it might be like that on other boards too. Looking at the script source, it is currently 60 seconds which seems a little dated.

unknown-- avatar May 03 '14 12:05 unknown--

I found it, the inline extension defines a cooldowns dictionary with value {thread: 600, reply: 30, image: 60, reply_intra: 90, image_intra: 120} on /vg/ and value {thread: 600, reply: 30, image: 60, reply_intra: 60, image_intra: 60} on /a/.

Just need to figure out how to use those.

loadletter avatar May 03 '14 15:05 loadletter

Fixed in 2.40.27, i'll keep this open if other changes are needed or something that doesn't hardcode the values is implemented.

loadletter avatar May 03 '14 16:05 loadletter

Cheers, mate.

unknown-- avatar May 03 '14 17:05 unknown--

Some thoughts:

Cooldowns are embedded as an object on each board's page, I collected them with a script here:

/a/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/b/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/c/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/d/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/e/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/f/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/g/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/gif/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/h/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/hr/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/k/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/m/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/o/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/p/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/r/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/s/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/t/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/u/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/v/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/vg/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":90,"image_intra":120};
/vr/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/w/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/wg/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/i/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/ic/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/r9k/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/s4s/: cooldowns = {"thread":300,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/cm/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/hm/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/lgbt/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/y/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/3/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/adv/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/an/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/asp/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/biz/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/cgl/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/ck/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/co/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":30};
/diy/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/fa/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/fit/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/gd/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/hc/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/int/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/jp/: cooldowns = {"thread":3600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/lit/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/mlp/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/mu/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/n/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/out/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/po/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/pol/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/sci/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/soc/: cooldowns = {"thread":600,"reply":60,"image":60,"reply_intra":60,"image_intra":30};
/sp/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/tg/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/toy/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/trv/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/tv/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/vp/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/wsg/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};
/x/: cooldowns = {"thread":600,"reply":30,"image":60,"reply_intra":60,"image_intra":60};

It would be possible to use them like this:

        QR.cooldown.types = {
          thread: (function() {
            return parseInt(unsafeWindow.cooldowns.thread);
          })(),
          sage: (function() {
            return parseInt(unsafeWindow.cooldowns.reply_intra);
          })(),
          file: (function() { 
            return parseInt(unsafeWindow.cooldowns.image_intra);
          })(), 
          post: (function() {
            return parseInt(unsafeWindow.cooldowns.reply_intra);
          })()
        };

The usage of unsafeWindow is frowned upon however, that's why I added parseInt() for validation. There's probably a better way. I took a quick look at Mayhem's 4chan-x, but couldn't figure out how he did it.

There's no extra value for "sage", so the extra definition for sage can be dropped and regarded as a normal reply I guess.

There seems to be some kind of issue with image cooldown 30, reply cooldown 60: Make a post with image in a thread then do another text reply. It counts from 60 to 30, then jumps to 0. Then 4chan sends me an error that I have to wait another 30 sec. Maybe I'm interpreting these values wrong.

chk1 avatar Sep 28 '14 08:09 chk1

The usage of unsafeWindow is frowned upon however,

Not to mention you have to worry about security restrictions on what you can and can't do with it, which will vary between browsers and their equivalents of Greasemonkey and change with new versions.

that's why I added parseInt() for validation.

That may not be enough. Consider what happens if thread is a getter. Now that may be blocked by modern security restrictions on using unsafeWindow, but I wouldn't want to depend on that.

I took a quick look at Mayhem's 4chan-x, but couldn't figure out how he did it.

By injecting a <script> into the page which reads cooldowns and fires a custom event. The detail property of the event contains the cooldown information, which is read by an event handler running in the script context.

If you want to scrape it from the page, I would suggest something like this myself: Find the <script> element that sets these variables (it's inline), find the part that sets cooldowns in its textContent, and then run that through JSON.parse. That works even if Javascript on 4chan is disabled. It's more vulnerable to breaking due to 4chan changes than Mayhem's approach, but it's simpler and safer from breaking due to security policy changes.

Perhaps better, you can now also get the cooldown information from: https://a.4cdn.org/boards.json Downside is that it's not available immediately; you have to wait for a network request. So you'd probably want to store the data you receive so you don't have to do the request for every page load.

ccd0 avatar Sep 28 '14 09:09 ccd0

It could be fetched at the same time as the version info

loadletter avatar Sep 29 '14 09:09 loadletter

They've recently added a 300-second cross-board thread creation cooldown as well.

ccd0 avatar Oct 05 '14 16:10 ccd0