Vote count:
0
How can I use chrome.downloads.onDeterminingFilename to change downloaded file names if the files have extension of jpg or png?
I am looking at the example here:
chrome.downloads.onDeterminingFilename.addListener(function(item, __suggest) {
function suggest(filename, conflictAction) {
__suggest({filename: filename,
conflictAction: conflictAction,
conflict_action: conflictAction});
}
var rules = localStorage.rules;
try {
rules = JSON.parse(rules);
} catch (e) {
localStorage.rules = JSON.stringify([]);
}
for (var index = 0; index < rules.length; ++index) {
var rule = rules[index];
if (rule.enabled && matches(rule, item)) {
if (rule.action == 'overwrite') {
suggest(item.filename, 'overwrite');
} else if (rule.action == 'prompt') {
suggest(item.filename, 'prompt');
} else if (rule.action == 'js') {
eval(rule.action_js);
}
break;
}
}
});
This is confusing. How does "chrome.downloads.onDeterminingFilename" from above detect the name of the file? And once it detects, how did it change the file? Can anyone break down what these codes mean above?
asked 1 min ago
Aucun commentaire:
Enregistrer un commentaire