2023-08-04 16:48:40 +08:00
|
|
|
import { browser } from "./browser";
|
2023-07-20 13:45:41 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送消息给background
|
|
|
|
|
* @param {*} action
|
|
|
|
|
* @param {*} args
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2023-08-31 13:38:06 +08:00
|
|
|
export const sendBgMsg = (action, args) =>
|
|
|
|
|
browser.runtime.sendMessage({ action, args });
|
2023-07-20 13:45:41 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送消息给当前页面
|
|
|
|
|
* @param {*} action
|
|
|
|
|
* @param {*} args
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export const sendTabMsg = async (action, args) => {
|
2023-08-31 13:38:06 +08:00
|
|
|
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
|
|
|
|
|
return browser.tabs.sendMessage(tabs[0].id, { action, args });
|
2023-07-20 13:45:41 +08:00
|
|
|
};
|
2023-09-10 12:35:03 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前tab信息
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export const getTabInfo = async () => {
|
|
|
|
|
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
|
|
|
|
|
return tabs[0];
|
|
|
|
|
};
|