After some research, I settled on the following approach:
- Use the HN Droid API to retrieve recently submitted HN posts for a given user via JSON.
- If any of the recently submitted posts match the provided url, store that thread id in Firebase and execute the user defined callback function.
It works as expected but has a few limitations:
- It relies on Firebase and doesn’t use authentication so someone can modify the database to point to another comment thread.
- It relies on a 3rd party Hacker News API so if that ever goes down it won’t be able to pull recently posted links to Hacker News.
- The HN API call only pulls the most recent submissions so the plugin will not be able to get the comment thread for older posts.
- Since Firebase prevents certain characters from being used in a key, I do some string replacement to clean the string which would allow someone to cause a string collision.
- The HN API isn’t real time and uses a cached version so it may take a bit of time for the link to get retrieved.
- The code hasn’t been thoroughly tested so may have some weird errors. It’s also my first “real” jQuery plugin so it may not follow best practices.