DEV: Avoid using globals (PR #14909)

GitHub

Could we do window.Discourse here, to avoid having an exception?

We probably could, but I’m trying to remove this whole chunk of code in a separate PR anyway :grin: