This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
44 lines (41 loc) · 1.55 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
chrome.runtime.onMessage.addListener(
function (request, sender) {
function onFill(tabId, src) {
let data = localStorage.getItem(tabId);
if (data !== null) {
let aims = JSON.parse(data);
chrome.tabs.sendMessage(aims.originTab, {
src: src,
href: aims.href
});
}
}
switch (request.type) {
case 'newTab':
chrome.tabs.create({
url: request.href,
selected: false,
// pinned: true
}, function (tab) {
localStorage.setItem(tab.id, JSON.stringify({
originTab: sender.tab.id,
href: request.href
}));
if (request.payload.redirect) {
let flag = setInterval(function () {
chrome.tabs.get(tab.id, function (newTab) {
if (newTab.status === 'complete') {
clearInterval(flag);
onFill(tab.id, newTab.url);
chrome.tabs.remove(tab.id);
}
})
}, 1500)
}
});
break;
case 'closeTab':
onFill(sender.tab.id, request.src);
chrome.tabs.remove(sender.tab.id);
}
});