Javascript in theme component only runs once?

Thanks. That got me on the right track. However, in looking at How do you force a script to refire on every page load in Discourse?, and the code of the linkify component, I believe I need to use the api.decorateCooked rather than api.onPageChange. Does that sound right?

Problem is, I can’t figure out how to use either one. I was able to get it “working” without the API, but like the above mentioned issue, it fires 3 times on page load. Here’s the code that works:

<script>
	var refTagger = {
		settings: {
			bibleVersion: "NASB",			
			socialSharing: []
		}
	};
	(function(d, t) {
		var g = d.createElement(t), s = d.getElementsByTagName(t)[0];
		g.src = "//api.reftagger.com/v2/RefTagger.js";
		s.parentNode.insertBefore(g, s);
	}(document, "script"));

$(document).ajaxComplete(function() {
    refTagger.tag();
});

</script>

If I replace the ajaxComplete section with the following, there’s an error in the console: “ReferenceError: Can’t find variable: api”.

  api.decorateCooked($elem => {
    refTagger.tag();
  });

If I change the opening script tag as follows, the error changes to "“refTagger.tag is not a function. (In ‘refTagger.tag()’, ‘refTagger.tag’ is undefined)”

<script type="text/discourse-plugin" version="0.2">

I don’t know javascript, so I’m just lost now. I’d like to do this the “proper” way if anybody can help me fix it. Thanks much.

By the way, it’s also possible apparently to run refTagger on specific content (rather than the whole page, I guess). This is some example code I found:

var o_c = document.getElementById('comment');

o_c.innerHTML = "See [Romans 1:10](http://biblia.com/bible/esv/Rom%201.10) for details";

refTagger.tag(o_c);

Not sure if it would be possible to just do something like the following, which is similar to what linkify does. If so, it seems like this would be most efficient:

  api.decorateCooked($elem => {
    refTagger($elem[0]);
  });

Anyway, as I said, if anybody can help, I’d be grateful.