1. Is it possible to get the unique identifier of the currently logged in forum user without parsing html (since this is more subject to change), e.g. by instead somehow retrieving a JSON file like the hypixel api does?
     
    #1
  2. Can you clarify more what you are trying to do? You want to get the linked Minecraft UUID of the account currently logged into the forums in a browser (e.g., via browser extension)?
     
    #2
  3. Yes something like that, but I'm looking for the identifier of a forum account, for example I'm guessing mine is 92102, since https://hypixel.net/members/92102/ links uniquely to my profile?
     
    #3
  4. Depends on your application but you will probably have to do some HTML/Javascript parsing.

    The only way to avoid HTML parsing would be to somehow scan the network requests and they come and go, looking for the user ID. The only way I know of that exists to do this would be the website's CSRF token. Unfortunately, the only place that I know of that this is stored is in a variable in the Javascript. I checked the cookies, storage, etc. and the only place I could find it was in one cookie, however when I deleted the cookie it didn't log me out (and it didn't add it back when I tried logging out and back in), so you shouldn't assume it's always there.

    The CSRF token is used to verify the request is authentic when a user's browser requests async data via a JSON response (e.g. the forum alerts dropdown). If you only need to get the user's ID AFTER they perform such an action, you can wait for the user to do so, check the request's GET parameters for the _xfToken, and take it from there. Otherwise, you would need to do the request yourself, and in order to do that you need the token anyway... Another way to get the ID would be to find some endpoint (something like https://hypixel.net/members/you, it's obviously not this though) which then redirects you to your account page (https://hypixel.net/members/bugfroggy.52450). Then you could get the ID from the redirect URL, however something like this might not even exist.

    If your main concern for parsing HTML is that the content could change, I wouldn't be too worried. These forums are built on Xenforo which is a popular forums system, and a lot of the identifiers and such that you would need to get this info are very unlikely to ever change. However, you could potentially build your app so it's easy to change in the future without users having to update (i.e. fetch it off of Github/your website, or use a default value if the network request fails).

    I would do something like this, with error handling of course, in case the user is logged out or something goes wrong or something does change:
    Code:
    parseInt(document.querySelector('#AccountMenu .fl a').getAttribute('href').split('.')[1].slice(0, -1))
    // Returns 52450 for me
    
     
    #4
    • Useful Useful x 1

Share This Page