tankerkiller125 [deleted]
Not quite. When you go to a flarum site, the backend returns a server-generated HTML page that shows the pure minimum of useful content (we actually have a GH issue for improving this no-js view). Then, we load in the JS bundle and initialize the Flarum SPA within that HTML skeleton. Those initializations shouldn't override most of the document head (with some exceptions, like the page title).
Now, the problem with this script as far as I can tell is '<script>$("img").attr("data-fancybox", "gallery");</script>'
. This will be executed exactly once, when the page loads for the first time. So it'll apply to any images initially there, and then not to any more.
The current fancybox extension works by effectively applying this code whenever a post is rendered or updated by Mithril: https://github.com/squeevee/flarum-ext-fancybox/blob/master/js/src/forum/index.js#L62. I don't think there's an easy way to do this without using the Flarum API, unless you want to run the fancybox script on an interval, which could cause performance issues / bugs.
EDIT: Or do what Clark said