-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
33 lines (33 loc) · 1.1 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
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'updateStatus') {
// 处理消息,例如记录状态
console.log('状态更新:', message.status);
}
if (message.action === 'modifyText') {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]) {
chrome.tabs.sendMessage(tabs[0].id, message);
} else {
console.error('无法找到活动的选项卡');
}
});
}
if (message.action === 'startModification') {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'startModification' });
} else {
console.error('无法找到活动的选项卡');
}
});
}
if (message.action === 'applyModification') {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'applyModification' });
} else {
console.error('无法找到活动的选项卡');
}
});
}
});