Ah.. I got it figured out:
(function() {
        window.addEventListener("load", function(event) {
                        var swfArgs = unsafeWindow.yt.config_.SWF_ARGS;

                        if (swfArgs) {
                                var keys = ["video_id", "sk", "t"];
                                var params = keys.map(function(k) { return k + 
"=" + swfArgs
[k]; }).join("&");

                                //Create the link
                                var link = document.createElement('a');
                                link.href = "http://www.youtube.com/get_video?"; 
+ params;
                                var txt = document.createTextNode("Download 
this Video");
                                link.appendChild(txt);
                                
document.getElementById('watch-player-div').appendChild(link);
                        }
                 }, false);

})();

...  But, I read that using unsafeWindow is "bad"..  I am curious how
I can do this without it, because yt still is undefined without it...

-patrick

On Oct 27, 10:47 pm, patrick <[email protected]> wrote:
> Hi,
>
> I had a script that I got from openjs for downloading youtube videos,
> and it stopped working recently..  It appears that youtube changed
> their code a bit...  I did some poking around and found the data that
> I need, and it all works fine----- in the console, not in
> greasemonkey.
>
> It's hard to tell exactly what youtube is doing, but I am suspecting
> they are doing their own sort of 'window.onload' event that happens
> after the actual window onload event, and creates their 'yt' class
> which holds the parameters that I am looking for.  So, basically if I
> go to youtube, and in firebug I type:
>
> yt.config_.SWF_ARGS
>
> I get the params I need...
>
> But, if I put that same thing in a greasemonkey script, it says yt is
> undefined...
>
> So, I am just wondering, is there a way around this?  I tried putting
> a timeout in the greasemonkey script, but that didn't help... Anyway,
> here is the code.
>
> (function() {
>
>         setTimeout(function() { get_video() }, 5000);
>
>         get_video = function() {
>                 console.log('yes');
>                 var swfArgs = yt.config_.SWF_ARGS;
>                 if (swfArgs) {
>                         var keys = ["video_id", "sk", "t"];
>                         var params = keys.map(function(k) { return k + "=" + 
> swfArgs
> [k]; }).join("&");
>
>                         //Create the link
>                         var link = document.createElement('a');
>                         link.href= "http://www.youtube.com/get_video?"; + 
> params;
>                         var txt = document.createTextNode("Download this 
> Video");
>                         link.appendChild(txt);
>                         
> document.getElementById('watch-player-div').appendChild(link);
>                 }
>         }
>
> })();
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to