How would I go about adding a script site-wide?

(Wint) #1

See this link:

I want these tooltips to work on any topic on the site. I’m mainly a C++ programmer that dabbles with web development, so I think I should be able to figure this out with minimal help. I just don’t even know where to start. Any help would be appreciated.

(Jeff Atwood) #2

I would start with admin, customize, html.

(Wint) #3

I did try that, but viewing the page source that code is inserted after the posts in the topic, so it’s not working for me. Is it possible to get it right after the body tag somehow?

(Jerry) #4

What we’ve done for a very similar feature:

In the HTML footer:

(function() {
    var timerId;
    function wowheadRefresh() {
        try {
        catch (e) {}
    Discourse.PostView.prototype.on("postViewInserted", function() {
        timerId = setTimeout(wowheadRefresh, 200)
    Discourse.ComposerView.prototype.on("previewRefreshed", wowheadRefresh);

Of course the website’s script is included in the HTML header.

Hope this helps.

PS: we know it’s super messy, but it works and we didn’t want to develop a “whole” plugin just for that. We know the plugin would be relatively small for such a basic thing but still, 10 lines of JS trump it all.

(Wint) #5

I’m not sure my javascript fu is strong enough for something like this. I did get the script in the HTML header, and I tried adding a modified version of what you have here to the footer but I must be missing something. I suspect it’s because the XIV tooltips don’t have the refreshLinks function you’re calling on $WowheadPower.