I am staying a day in Hong Kong on Thursday/Friday on my way to Australia. Is it safe? What are necessary precautions? Should I stay in the airport all this time?
It is safe. Demonstrations mostly occur on the weekends, are quite localized, are mostly peaceful and don't target tourists. If you are paranoid, avoid wearing black clothes, since that's one of the way protesters identify themselves (my French contacts advised me to wear a yellow vest to make sure I'm not mistaken for a protester). I have seen a few protests on the axis Tsim Sha Tsui -> Jordan -> Yau Ma Tei -> Mongkok, but again it's quite peaceful and violence, if any, is directed toward objects and police, so unless you're one of them, you're fine. The main impact on tourists is the early closing time of the MTR and Airport Express.
Source: I was in Kowloon two weeks ago.
Hong Kong - Level 2: Exercise Increased Caution
You can see the many countries with that level on https://travel.state.gov/content/travel/en/traveladvisories/traveladvisories.html; for example Belgium and France are level 2 as well.
It's perfectly safe.
I've been there a few weeks ago, and the only inconvenience I encountered were unpredictable MTR station and system closures, but in case that happens there are always alternatives (buses, taxis and ultimately walking). The Citymapper and MTR apps are useful as they provide notifications of closures in real time, and alternative routes as needed.
Protests can happen in unpredictable and unanounced places. If you see groups of either protesters or police, try to find a different route to your destination (basically duck into a side street). Avoid wearing black, as that is the color of the protestors. Protests normally escalate on the weekends, but that is not a firm rule.
HK Map Live site shows the locations of the (some) police and protests almost in real time. It's in Chinese, but you can figure out the areas to avoid based on the icons.
Allow more time than usual for worst-case scenarios if you have to reach a specific place (e.g. catching a flight back).