Dark mode won't work

Hi,

I’m just experimenting with this little code snippet. https://darkmodejs.learn.uno/

If I insert the script at the end of the page before , it only works if the page is empty otherwise it does not work.

Does anyone have any idea what’s the problem?