我正在从chrome和firefox建立一个批量下载扩展,以下载大量文件。该扩展的弹出式窗口具有取消pauseresume功能。当下载少量文件时,弹出的窗口可以正常工作。然而,当下载较多的文件时,弹出菜单需要很长时间才能真正弹出(或者有些时候根本就没有弹出),可能是因为扩展程序变得非常忙碌,一次处理了很多文件。有什么办法可以消除这种延迟吗?
manifest.json
"default_popup": "html/popup.html"
},
popup.html
let bgPage = chrome.extension.getBackgroundPage(); //Getting the variables from the background page
let idsOfDownload = [];
idsOfDownload = bgPage.downloadIds;
console.log(idsOfDownload);
let cancel = document.createElement("button");
cancel.id = "cancel";
cancel.className = "btn";
cancel.innerHTML='<i class="fa fa-stop-circle"></i> Cancel All</button>';
document.body.appendChild(cancel);
$('body').width(350);
setInterval(function(){
let downloadString = LZString.decompress(localStorage.getItem('downloadLinks'));
if(downloadString === "") return;
let downloadLinks = JSON.parse(downloadString);
if (downloadLinks !== undefined && downloadLinks !== null && downloadLinks !== "null") {
let status = `Total pending download: ${downloadLinks.length}`;
jQuery("#download-status").html(status);
}
},1000);
$(cancel).click(function () {
chrome.runtime.sendMessage({message: "cancel-download"});
});