Bootstrap 5.3.0 introducted the concept of a theme to set the color mode of a website, ostensibly support light color mode and dark color mode.
The examples on the Bootstrap website show how to manually switch between modes but I wanted a way to automatically set the mode based on the operating system setting when the site loaded, and automatically switch the mode when the operating system switched from one mode to another.
So I put together an anonymous function which does the first and a window watcher which does the second.
This JavaScript should be included in the page itself, putting it in a separate file will cause the page to visibly switch modes when it is loaded which is pretty ugly.