Skip to content

Commit 7afa8c5

Browse files
committed
1. 重新设置获取请求方式
2. 优化下载界面
1 parent 1d3818d commit 7afa8c5

23 files changed

+218
-197
lines changed

background/request-service.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const temp_requests = [];
1+
let temp_requests = [];
22
let timer = null;
33

44
/**
@@ -15,41 +15,44 @@ function requestCallback(info) {
1515
if (!temp_requests.length) return;
1616
//拷贝数据
1717
const temp_requests_clone = JSON.parse(JSON.stringify(temp_requests));
18+
temp_requests = [];
1819

1920
//处理数据
2021
chrome.storage.local.get(["tabs_request"]).then((storage) => {
2122
let storageTabs = storage["tabs_request"] || {};
2223

2324
Promise.all(
24-
temp_requests_clone.map((el) =>
25-
chrome.tabs.get(el.tabId).then((tab) => {
25+
temp_requests_clone.map((el) => {
26+
console.log("-----el", el);
27+
return chrome.tabs.get(el.tabId).then((tab) => {
2628
return {
2729
name: tab.title,
2830
icon: tab.favIconUrl,
2931
id: tab.id,
3032
requests: [],
3133
};
32-
})
33-
)
34+
});
35+
})
3436
)
35-
.then((tabs, index) => {
36-
const details = temp_requests_clone[index];
37+
.then((tabs) => {
38+
tabs.forEach((tab, index) => {
39+
const details = temp_requests_clone[index];
3740

38-
let tabInfo =
39-
storageTabs[details.tabId] || tabs.find((el) => el.id == details.tabId);
41+
let tabInfo = storageTabs[details.tabId] || tab;
4042

41-
if (!tabInfo.requests.find((el) => el.url == details.url)) {
42-
let fileName = "",
43-
pathArray = new URL(details.url).pathname.split("/");
44-
while (!fileName) {
45-
fileName = pathArray.pop();
46-
}
47-
details.name = fileName;
43+
if (!tabInfo.requests.find((el) => el.url == details.url)) {
44+
let fileName = "",
45+
pathArray = new URL(details.url).pathname.split("/");
46+
while (!fileName) {
47+
fileName = pathArray.pop();
48+
}
49+
details.name = fileName;
4850

49-
tabInfo.requests.push(details);
50-
}
51+
tabInfo.requests.push(details);
52+
}
5153

52-
storageTabs[details.tabId] = tabInfo;
54+
storageTabs[details.tabId] = tabInfo;
55+
});
5356
})
5457
.finally(() => {
5558
storage["tabs_request"] = storageTabs;
@@ -72,7 +75,7 @@ function onWatchRequest(types) {
7275

7376
chrome.webRequest.onBeforeRequest.addListener(
7477
requestCallback,
75-
{ urls: ["<all_urls>"], types },
78+
{ urls: ["http://*/*", "https://*/*"], types },
7679
[]
7780
);
7881
}

images/delete-dark.png

3.71 KB
Loading

images/delete.png

-994 Bytes
Loading

images/download-dark.png

3.95 KB
Loading

images/download.png

1.04 KB
Loading

images/fetch-dark.png

7.57 KB
Loading

images/fetch.png

350 Bytes
Loading

images/refresh-dark.png

6.5 KB
Loading

images/refresh.png

165 Bytes
Loading

images/reload-dark.png

5 KB
Loading

0 commit comments

Comments
 (0)