Accessing a specific topic from a user script


(Joe Seyfried) #1

I am trying to access a specific topic from a user script like so:

Discourse.Topic.find(15802, {})

which works if I know its ID. However, I want to access the number of unread posts - and it seems I cannot access this data from the _result object! How can I get this number from a user script?

What I am also looking for is a way to search for a topic with a given title… Can anyone give me a little hint where to dig for those two things?


(Kane York) #2
https://meta.discourse.org/latest.json?topic_ids=24901

Also, you should be using unsafeWindow.Discourse.ajax(). It’ll handle the CSRF and json parsing for you.

Request /t/TITLE_GOES_HERE and read the redirect.


(Joe Seyfried) #3

Great, thx. I guess I got stuck in the depth of the javascript classes and did not realize the JSON way out… :wink: