Page 1 of 1
save link as anchor name
Posted: Thu Feb 04, 2016 9:34 pm
by Guest
Is there a way to download what a link points to and name the downloaded file with the anchor name in the link? An example where this would be useful is a page which is a table of contents and the names on the links are sensible, but the file names in the uris are not.
Re: save link as anchor name
Posted: Fri Feb 05, 2016 3:42 pm
by therube
I'm thinking that may depend on the particular download manager you use.
Some may pick up "pretty" names, others can only garner the name of the URL.
(My download manager does not do "pretty".)
(I was wondering if there were any way to supply [any] name using browser built-in? As far as I can see, it only allows you to designate a directory for the files to go into.)
Re: save link as anchor name
Posted: Sat Feb 06, 2016 1:46 pm
by Guest
You're right, it's certainly possible for the download manager to decide how to name the resulting files. I'll have to try looking for one that does it how I like.
I don't think that there is any way to use firefox built-in download manager out of the box to skip the prompt and name the files in this way. I've been using a custom bit of code to do it:
Code: Select all
function SaveNamer_onSaveNamedLink()
{
// use selected text as file name if there is any
var fileName = document.commandDispatcher.focusedWindow.getSelection().toString();
// use link to name the file otherwise
if (!fileName) fileName = gContextMenu.linkText();
// remove misbehaving characters
fileName = fileName.replace(/^\s+|\/|\?|\:|\%|\&|\'|\"|\;|\!|\s+$/g, "");
//https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIFile
//https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O
var dest = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("Desk", Components.interfaces.nsIFile);
dest.append(fileName + ".html");
var aChosenData = new AutoChosen(dest,
makeURI(gContextMenu.linkURL, gContextMenu.target.ownerDocument.characterSet));
var aReferrer = makeURI(gContextMenu.target.ownerDocument.URL,
gContextMenu.target.ownerDocument.characterSet);
//toolkit/content/contentAreaUtils.js
internalSave(/*aURL*/ null, /*aDocument*/ null, /*aDefaultFileName*/ null,
/*aContentDisposition*/ null, /*aContentType*/ null,
/*aShouldBypassCache*/ true, /*aFilePickerTitleKey*/ null,
//aChosenData, aReferrer, true); return; dummy( // Iceweasel 17
aChosenData, aReferrer, /*aInitiatingDocument*/ document,
/*aSkipPrompt*/ true, /*aCacheKey*/ null);
}
The problem with this code is that the new firefox extension signing disables it. I'd like to be able to use flashgot instead.
Re: save link as anchor name
Posted: Sat Feb 06, 2016 7:53 pm
by therube
A couple "name" Prefs, but don't know if they'll be of benefit?
> flashgot.media.forceNameHack
> flashgot.media.guessName
Re: save link as anchor name
Posted: Sun Feb 21, 2016 3:31 pm
by Guest
Actually, as far as I can tell, there's no way to pass the link text to the download manager. In the documentation
https://flashgot.net/features#customdm, there's no option for passing the link text at all. So, if I write a script wrapper, I can't name the downloaded file according to this information. And I don't believe any other download manager can either. Also, I experimented by changing flashgot.media.forceNameHack and flashgot.media.guessName. And, I wasn't able to see any effect from doing that.
At this point, I don't think it is possible for the download manager to name files according to the link text.
Re: save link as anchor name
Posted: Tue Feb 23, 2016 8:19 am
by Guest
Taking the path of least resistance, I submitted my naming extension to firefox. There's now a signed version available:
https://addons.mozilla.org/en-US/firefo ... savenamer/
Re: save link as anchor name
Posted: Tue Feb 23, 2016 11:08 pm
by Thrawn
Kudos for proactivity! However, since you used XUL, your extension is already deprecated.
Want to test whether it works on other browsers (eg Seamonkey, Pale Moon) where it might have more future?
Re: save link as anchor name
Posted: Wed Feb 24, 2016 3:16 pm
by therube
I don't understand how this is to work?
What download manager are we using, or does it matter?
What type of links, or does that matter?