2024-12-27 14:23:27 +08:00

38 lines
954 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function createPluginMenus() {
const menus = [];
let parent = chrome.contextMenus.create({
id: "parent",
title: "CC-Inspector",
});
chrome.contextMenus.create({
id: "test",
title: "测试右键菜单",
parentId: parent,
// 上下文环境,可选:["all", "page", "frame", "selection", "link", "editable", "image", "video", "audio"]默认page
contexts: ["page"],
});
chrome.contextMenus.create({
id: "notify",
parentId: parent,
title: "通知",
});
chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === "test") {
alert("您点击了右键菜单!");
} else if (info.menuItemId === "notify") {
chrome.notifications.create("null", {
type: "basic",
iconUrl: "icons/48.png",
title: "通知",
message: "测试通知",
});
}
});
}
chrome.contextMenus.removeAll(() => {
createPluginMenus();
});