I'm viewing this website that has a client side javascript error caused by 
the scripts being loaded in the wrong order.  Problem is I don't own this 
source, but I really need to use the site ASAP.  

Is there a way to do this with greasemonkey?  The problem is that since 
this is loaded in the `head` element, if I modify the html the JS error has 
already occurred.  But, if I refresh the changes (at least in chrome) my 
local modifications disappear.

Specifically, the html head element contains this:

    <script 
        language="javascript" 
        src="/scripts/util.js" 
        type="text/javascript"></script>
    <script 
        language="javascript" 
        src="/scripts/scriptaculous/prototype.js" 
        type="text/javascript"></script>
    <script 
        language="javascript" 
        src="/scripts/scriptaculous/scriptaculous.js" 
        type="text/javascript"></script>

And to fix the bug, it would need to be like this:

    <script 
        language="javascript" 
        src="/scripts/scriptaculous/prototype.js" 
        type="text/javascript"></script>
    <script 
        language="javascript" 
        src="/scripts/scriptaculous/scriptaculous.js" 
        type="text/javascript"></script>
    <script 
        language="javascript" 
        src="/scripts/util.js" 
        type="text/javascript"></script>

Notice how the `util.js` moved to the bottom.  

I'm pretty close to doing this with a grease monkey script with this source:

    // ==UserScript==
    // @name        name
    // @namespace   namespace
    // @include     htmlfilewithbug
    // @version     1
    // @grant       none
    // @run-at document-start
    // ==/UserScript==
    
    var loaded = false;
    
    var loadScript = function(scriptName) {
    
        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = scriptName;
        head.appendChild(script);
    
    };
    
    window.onload = function() {
        loaded = true;
        
loadScript('https://hostwithbug/scripts/scriptaculous/prototype.js');
        
loadScript('https://hostwithbug/scripts/scriptaculous/scriptaculous.js');
        loadScript('https://hostwithbug/scripts/util.js');
    };
    
    
    document.onbeforescriptexecute = function() {   //control whether 
scripts get executed at all. FireFox feature
        return loaded;  
    }

But I get this error that says this:

    A call to document.write() from an asynchronously-loaded external 
script was ignored. @ 
https://hostwithbug/scripts/scriptaculous/scriptaculous.js:30

I don't know how to get around this.  Perhaps there's some way for me to 
replace a `head` tag with one of my choosing? As far as I can tell, it 
would have to happen right before the `head` were to be rendered in order 
to avoid this error.  I have not found any way to do this.

Regardless, I'm looking for a solution to the problem in my title: How can 
I change the order that the html's scripts are loaded?

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to