Script not adding stuff onload, not onDOMContentLoaded

Subscribe to Script not adding stuff onload, not  onDOMContentLoaded 7 posts, 4 voices

 
Raffles Scriptwright

I've made a user script to make Photobucket a bit more useful, to strip out the annoying ads and use the space a bit better. It works very well so far (not completely finished yet) but the script only is applied after absolutely everything has loaded (even images) - clearly not immediately after the DOM has loaded as it is supposed to.

I've put a copy at this pastebin and as you can see, it follows this basic structure:

- Function.prototype.bind defined
- Two global vars defined
- A bunch of functions defined
- init() is called right at the end

Sometimes photobucket gets stuck for ages on "Transferring data from google-analytics.com" or on "Waiting for a.photobucket.com" and so the script isn't applied until this is over. If I click STOP, the script is immediately applied.

Can anyone see what the problem is? Thanks in advance,

Raffles

 
Descriptor Scriptwright

I don't think the DOM is fully loaded until google-analytics.com is done, take a look at this page, it's a script that modifies the DOM by inserting ads.
I think it would help to enable pipelining, I don't know why any site would have trouble with it, it's a HTTP1.1 standard. See this - http://www.mozilla.org/support/firefox/tips#oth...
However, if the site is slow to respond, I don't know that you can do anything except maybe block it.

I didn't look at your script though, just referring to your last paragraph.

 
Arvid Scriptwright

This can be interesting. There is probably no easy solution for your problem. You could try to block the google analytics js with adblock though.

 
Raffles Scriptwright

I've found that blocking Google Analytics' urchin.js with adblock does help a little, but most of the slowness is I think due to the download of over 200KB of javascript in the head. Easily Adblocked, but some pretty trivial functionality in the site relies on them (lazy, bad design) and if anyone else is going to install this script, they might not have Adblock.

Descriptor, Google Analytics doesn't do ads - it logs traffic. The only thing it document.writes into the page is a small GIF image (35 bytes in size).

What makes the experience much better is to put as much of the CSS-related business into userContent.css instead of using GM_addStyle (but doesn't speed up the application of the script of course).

Thanks Arvid, I'd read that before. Wishful thinking here and I doubt it's possible, but does anyone know if a user script can add stuff to userContent.css? Also, userContent.css applies those rules as the page is loading, way before DOMContentLoaded has fired. It would be nice if GM_addStyle could somehow do this. I remember an extension that allowed you to edit userContent.css and it applied changes on page reload (not Firefox reload).

Regarding clicking STOP/ pressing Esc while the page is loading, the user script is applied even if the page's HTML has not been fully loaded. Seems like DOMContentLoaded fires when the user stops the page loading after at least some of the document body has appeared. Perhaps the ideal thing would be to fire DOMContentLoaded artificially, or simulate the user stopping the page loading without it actually happening! Not that I expect this to be possible.

 
Descriptor Scriptwright

Oh, you're right, it's googlesyndication.com that puts in the ads.

I use Stylish, it does the same thing as userContent.css but you can control it per site.
http://userstyles.org/stylish/

Look at the comparison: http://userstyles.org/stylish/differences

I believe pressing stop closes the html like document.close(), which allows Greasemonkey scripts to run, otherwise I'd think that'd be pretty insecure.

 
alien_scum Scriptwright

You could adblock the JavaScript file in the header and then reinsert it from your local computer using a script, or use you hosts file to redirect it to a local copy every time. userscripts can't change userContent.css, but you could prompt to add a userstyle, this code is ripped off userstyles.org so i have no idea if it will work but it should, put the css in a <code id="stylish-code"> tag, then run this bit of JS

function stylishInstall(event) {
 var stylishEvent = document.createEvent("Events");
 stylishEvent.initEvent("stylishInstall", false, false, window, null);
 //event.target.dispatchEvent(stylishEvent);
 document.dispatchEvent(stylishEvent);
}

 
Raffles Scriptwright

Blocking JS files in the head and reinserting from the local computer is just not worth the trouble. It's actually not that bad now, I think Photobucket was probably just having some issues yesterday, it was abnormally slow.

Thanks for the help guys.