How to keep up with NodeBB topic list changes

  • I'm making a userscript that works with the topic list. Right now it does what I want, but only when refreshing the page, and only with the topics visible at that moment. I'd like to re-trigger the function whenever infini-scroll loads more topics, and when navigating around normally (SPA-style). What's the best way to do that?

  • You want socket.on('something', event_handler_fn).

    I don't know off the top of my head what the event name is. Run this socket monitor I posted elsewhere in the console and make note of the event(s) that it logs when the topic list loads / loads more topics.

  • Actually, I think I was wrong... it'll be a $(window).on('something', event_handler_fn).

    Probably something like event:topics_loaded?

  • @anotherusername I'll take a longer look at it when I'm not doing actual work, but at first glance it seems to be socket.emitting a bunch of stuff at certain times but I don't see any event for when the topics actualy load.

  • Yeah, socket.on is just the messages that the server pushes to the client, and the emits are messages that the client sends to the server.

    What you're looking for was the second thing I thought of. I believe this is what you need:

    $(window).on('action:topics.loaded', event_handler_fn);

    I think it triggers both when loading the topics list and when it loads more while infiniscrolling. The handler function gets passed an object holding the list of items that were loaded.

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.