You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
669 B
JavaScript
20 lines
669 B
JavaScript
// background.js
|
|
|
|
// 监听插件图标的点击事件
|
|
chrome.action.onClicked.addListener((tab) => {
|
|
// 定义我们插件页面的URL
|
|
const pluginPageUrl = chrome.runtime.getURL('index.html');
|
|
|
|
// 查询是否已经有打开的插件页面
|
|
chrome.tabs.query({ url: pluginPageUrl }, (tabs) => {
|
|
if (tabs.length > 0) {
|
|
// 如果找到了,就激活第一个找到的标签页和它的窗口
|
|
chrome.tabs.update(tabs[0].id, { active: true });
|
|
chrome.windows.update(tabs[0].windowId, { focused: true });
|
|
} else {
|
|
// 如果没找到,就创建一个新的标签页
|
|
chrome.tabs.create({ url: pluginPageUrl });
|
|
}
|
|
});
|
|
});
|