You might want to use <code>mw.hook( 'wikipage.content' ).add( function() {</code> here. (see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook)