Passing links to FG from another Addon

Ask for help about FlashGot, no registration needed to post
Post Reply
erosman

Passing links to FG from another Addon

Post by erosman »

Hi

I am writing an addon/extension and I need to pass some links top FlashGot and let FlashGot handle the rest.

I am using the following (which I saw somewhere) and pass links as array of objects with properties 'href' & 'description'

Code: Select all

gFlashGot.download(links);
It doesn't seem to work. I tried passing URLs as a simple array but FG came up with errors

Code: Select all

TypeError: l.href is undefined 
How can I pass links/URLs to FlashGot?

Thanks in advance for your help
:)
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
erosman

Re: Passing links to FG from another Addon

Post by erosman »

Not to worry... I found the answer here:
http://forums.mozillazine.org/viewtopic ... 9&t=544776

Take care
:)
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
erosman
Posts: 16
Joined: Sun May 25, 2014 2:12 pm

Re: Passing links to FG from another Addon

Post by erosman »

Does FG accept multiple links?!

Code: Select all

gFlashGot.download(element.querySelectorAll('a')); // NodeList
gFlashGot.download(element.getElementsByTagName('a')); // HTMLCollection
When I send 1 node, it works fine.

Code: Select all

NodeList {0: HTMLAnchorElement, length: 1}
HTMLCollection {0: HTMLAnchorElement, length: 1}
If I send more than 1 node, nothing happens.

Code: Select all

NodeList {0: HTMLAnchorElement, 1: HTMLAnchorElement, length: 2} browserOverlay.js:171
HTMLCollection {0: HTMLAnchorElement, 1: HTMLAnchorElement, length: 2}
Is it possible to send multiple links? how?

Update: I tried sending an array of object, each object with one href property.. but again FG did not accept it

Code: Select all

[Object, Object]
I also get a flashgot progress bar on my addon bar!! which seems to be stuck


Update: I had to send each link separately inside an array to make it work. I feel that FG hugs when multiple links are set. Out of curiosity, which part of the FG code deals with gFlashGot.download()? I am curios to have a closer look at it.

Code: Select all

 for (let i = 0, len = elem.length; i < len; i++) {
    gFlashGot.download([elem[i]]);
}

After looking at FG code, I even tried gFlashGot.download(array, 1, ''); and 2 and 3 as the 2nd value
The progress bar hangs ...
Sometimes there are errors logged in console

Code: Select all

[FlashGot Redirect Processor] uploaded_to: TypeError: this.links.some is not a function RedirectContext.prototype.change@chrome://flashgot/content/RedirectContext.js:123
uploaded_to@chrome://flashgot/content/RedirectContext.js:1006
RedirectContext.prototype.processLink@chrome://flashgot/content/RedirectContext.js:64
RedirectContext.prototype.process@chrome://flashgot/content/RedirectContext.js:49
Please note that all this happens if the array sent contains more than 1 object.

After looking at FG code... it seems ....

Code: Select all

  download: function(links, opType, dmName) {
    
    switch (links.length) {
      case 0: 
        return false;
      case 1: 
        opType = this.OP_ONE; 
        break;
      default:
        if (!opType) opType = this.OP_SEL; 
    }
....
If links.length === 0 it will end the execution of the function
If links.length === 1 it will set opType = this.OP_ONE
What happens if links.length > 1 ??
default set opType = this.OP_SEL only if parameter2 is not sent

As a test, I tried...

Code: Select all

gFlashGot.download([lnks], gFlashGotService.OP_ALL, null);
gFlashGot.download([lnks], gFlashGotService.OP_QET, null);
gFlashGot.download([lnks], 2, null);
gFlashGot.download([lnks], 3, null);
Therefore..... if links.length > 1 and !opType ... that is where we get the errors from RedirectContext.js

Please note that the same links works find if activated via FlashGot Selection contextMenu/keyboard shortcut
Something is missing from processing gFlashGot.download(lnks);

Looking forward to your comments
Regards
:)
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
User avatar
Giorgio Maone
Site Admin
Posts: 9454
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: Passing links to FG from another Addon

Post by Giorgio Maone »

You cannot send the nodelist directly.

You must copy it into a JavaScript array, each items with its href and description property, and the array itself should have a referer (string url) and/or a document (DOM object) expando property linking it to the original page.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
erosman
Posts: 16
Joined: Sun May 25, 2014 2:12 pm

Re: Passing links to FG from another Addon

Post by erosman »

Thanks Giorgio

I updated my previous post before seeing your reply.

So I gather the answer given in that thread (although old) is not correct anymore
To download all the links of a certain document, for instance, you can use:
gFlashGot.download(window.content.document.getElementsByTagName("a"));
OK...I got it working :)

I wonder why the same process works for a single node?

PS. I noticed that the description is only passed on with single links (as comment in FDM). In case of multiple links, they are omitted.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
erosman
Posts: 16
Joined: Sun May 25, 2014 2:12 pm

Re: Passing links to FG from another Addon

Post by erosman »

Hi Giorgio

I noticed that FlashGot Selection handles plain text URLs.
Can I pass URLs to that function? How?
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
Post Reply