I have submitted the same question to StackOverflow, but I don't know if I should have posted it here.
I have written a Tampermonkey script to add a custom download option to a Flickr photo page. It works when download option in settings is set to native, but the file is always stored in my default downloads folder. Is there any way to set the local path of a download without user interaction?
// ==UserScript==
// @name Flickr download to folder
// @namespace http://malver.dk/
// @version 0.1
// @description Download k-size photo from Flickr where available
// @author Rasmus Malver
// @match https://www.flickr.com/photos/*
// @grant GM_download
// @grant GM_info
// ==/UserScript==
(function() {
'use strict';
var scripts=document.getElementsByTagName("script");
var rx = /modelExport:([^\n\r]+),/;
var match;
for(var i = 0;i < scripts.length; i++){
if(scripts[i].className=="modelExport"){
match = rx.exec(scripts[i].innerHTML);
break;
}
}
var json=JSON.parse(match[1]);
var kUrl='http:'+json['photo-models'][0]['sizes']['k'].url;
var d = new Date();
var localName = "~/Documents/Flickr/"+d.toISOString().substr(0,10)+"-"+kUrl.substr(-28,11)+".jpg";
// E.g. "~/Documents/Flickr/2017-09-05-36203459914.jpg"
var arg = { url: kUrl,
name: localName
};
var result= GM_download(arg);
console.log(result);
})();
(Un)Fortunately you can (only) download files to a location relative to the download folder. 馃槈
Please note, that you have to enable browser API downloads by following these steps:
Config mode to AdvancedDownload Mode and set it to Browser APIExample script:
// ==UserScript==
// @name Flickr download to folder
// @namespace http://malver.dk/
// @version 0.1
// @description Download k-size photo from Flickr where available
// @author Rasmus Malver
// @match https://www.flickr.com/photos/*
// @grant GM_download
// @grant GM_info
// ==/UserScript==
(function() {
'use strict';
var scripts=document.getElementsByTagName("script");
var rx = /modelExport:([^\n\r]+),/;
var match;
for(var i = 0;i < scripts.length; i++){
if(scripts[i].className=="modelExport"){
match = rx.exec(scripts[i].innerHTML);
break;
}
}
var json=JSON.parse(match[1]);
var kUrl='http:'+json['photo-models'][0]['sizes']['k'].url;
var d = new Date();
var localName = d.toISOString().substr(0,10)+"-"+kUrl.substr(-28,11)+".jpg";
var path = 'flickr/'; // use a special folder for all the images
var arg = {
url: kUrl,
name: path + localName
};
debugger;
var result= GM_download(arg);
console.log(result);
})();
Most helpful comment
(Un)Fortunately you can (only) download files to a location relative to the download folder. 馃槈
Please note, that you have to enable browser API downloads by following these steps:
Config modetoAdvancedDownload Modeand set it toBrowser APIExample script: