Answers for "chrome extension change download file name form"

0

chrome extension change download file name form

chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
    if (item.referrer.search("gutenberg.org") == -1) {
    // If the file does not come from gutenberg.org, suggest nothing new.
        suggest({filename: item.filename});
    } else {
    // Otherwise, fetch the book's title in storage...
        chrome.storage.local.get([item.referrer], function(result) {
            if (result[item.referrer] == null) {
                // ...and if we find don't find it, suggest nothing new.
                suggest({filename: item.filename});
                console.log('Nothing done.');
            }
            else {
                // ...if we find it, suggest it.
                fileExt = item.filename.split('.').pop();
                var newFilename = "gutenberg/" + result[item.referrer] + "." + fileExt;
                suggest({filename: newFilename});
                console.log('New filename: ' + newFilename);
            }
          });
        // Storage API is asynchronous so we need to return true
        return true;
    }
  });
Posted by: Guest on September-02-2021

Code answers related to "chrome extension change download file name form"

Code answers related to "Javascript"

Browse Popular Code Answers by Language