Reputation: 99
I've created an extension and I want it to list all of the downloads in the user's downloads folder on a page rather than just opening the download folder.
This is my code:
window.onload = function(){
var maxNumOfEntries = 100;
for(i = 0; i < maxNumOfEntries; i++){
para = document.createElement('p');
para.setAttribute("id", ("download" + i));
var node = document.createTextNode("");
para.appendChild(node);
var element = document.getElementById("content");
var child = document.getElementById("stuff");
element.insertBefore(para,child);
}
var num = 0;
var currentTime = new Date().getTime();
chrome.downloads.search({text: '', limit: 100}, function(data) {
data.forEach(function(DownloadItem) {
document.getElementById('download' + num).innerHTML = DownloadItem.filename;
num++;
});
});
}
I've tried various other methods but I just can't seem to get the downloads to appear, any advice?
Upvotes: 2
Views: 4066
Reputation: 94319
The text
property should not be there, which is causing the problem.
chrome.downloads.search({limit: 100}, function(data) {
data.forEach(function(item, i) {
document.getElementById('download' + i).innerHTML = item.filename;
});
});
Upvotes: 2