What are you trying to achieve?
This might work but it’s not very efficient since you’re making an extra AJAX for every topic page view for every user - including anons. So this will create a lot of unnecessary load on your server.
Not really. The URL for a topic looks like this
your.site.com/t/topic_title/topic_id/linked_post_number(optional)
There’s no category order in the URL in a default Discourse installation.
We can help you if you describe the problem you’re trying to solve instead of describing your solutions for it.