r1m / GSExtended

Grooveshark userscript
MIT License
11 stars 6 forks source link

grooveshark ready event #18

Closed gdisanto closed 10 years ago

gdisanto commented 10 years ago

Hi, I'm working on a small project during my spare time. I have problem to figure out how I can set a listener executing my main function when gs is fully loaded. By giving a look to your project I guess you understood how the gs script works. Can you say me what event/object I have to listen? If my project works properly we could add it as a new feature for GSextended ;)

jameshartig commented 10 years ago

Your best bet is listening to document.ready. The only problem is that we(Grooveshark) do setup in document.ready so you'll want to put your callback behind a tiny setTimeout delay so that Grooveshark's code can run first.

There's also GS.ready which is a deferred, but I wouldn't recommend that since Grooveshark can change it at any time and isn't guaranteed.

gdisanto commented 10 years ago

Yeah It's what I've done but It doesn't seem a good solution. What about the page is taking time to be loaded?

Thanks for the reply

r1m commented 10 years ago
(function()
{
    var init_check = function ()
    {
        try {
            GS.ready.done(function(){

                //your code goes here
            });
        } catch(e) {
            setTimeout(init_check, 100);
        }
    }
    init_check();
})()

But some function are initialised only after some user action (join a BC, start to play...)

gdisanto commented 10 years ago

Thanks ;)