Reputation: 109
I am trying to make a Chrome extension and I have two questions:
Upvotes: 3
Views: 2609
Reputation: 348962
You can rename downloads using chrome.downloads.onDeterminingFilename
.
Use downloadItem.referrer
to figure out where the download was initiated. This could be an empty string, e.g. when the user typed the download URL in the omnibox.
Here is an example that adds a prefix "downloadprefix-" before every file name if the download originates from http://www.example.com
or https://www.example.com/
.
chrome.downloads.onDeterminingFilename.addListener(function(downloadItem, suggest) {
if (/^https?:\/\/www\.example\.com\//.test(downloadItem.referrer)) {
suggest({
filename: 'downloadprefix-' + downloadItem.filename
});
}
});
Upvotes: 2