1
0
mirror of https://gitee.com/bitdance-team/chrome-extension synced 2025-10-09 17:25:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

manifest.json升级到mv3(mv3的omnibox有Bug,见:https://bugs.chromium.org/p/chromium/issues/detail?id=1186804)

This commit is contained in:
2022-02-05 01:57:27 +08:00
parent add9eca347
commit a822eee438
5 changed files with 105 additions and 242 deletions

View File

@@ -0,0 +1,56 @@
// 注册右键菜单
chrome.contextMenus.create({
id: 'bitdance',
title: '学生助手'
})
chrome.contextMenus.create({
parentId: 'bitdance',
id: 'bitdance-advanced-search',
title: '高级搜索Todo'
})
chrome.contextMenus.create({
parentId: 'bitdance',
id: 'bitdance-advanced-search-notification',
title: 'Notification',
})
chrome.contextMenus.onClicked.addListener(function (info, tab) {
console.log("info", info, "tab", tab)
// alert('当前菜单信息:' + JSON.stringify(info))
switch (info.menuItemId) {
case "bitdance-advanced-search-notification":
// 测试Notification
showNotification()
break;
case "bitdance-advanced-search":
// 高级搜索
console.log("[BitDance extension] 学生助手插件 - 高级搜索 已点击菜单")
break;
}
})
//refer: https://github.com/GoogleChrome/chrome-extensions-samples/blob/main/mv2-archive/api/notifications/background.js
function showNotification() {
// var time = /(..)(:..)/.exec(new Date()); // The prettyprinted time.
// var hour = time[1] % 12 || 12; // The prettyprinted hour.
// var period = time[1] < 12 ? 'a.m.' : 'p.m.'; // The period of the day.
// new Notification(hour + time[2] + ' ' + period, {
// icon: '48.png',
// body: 'Time to make the toast.'
// });
// refer: https://developer.chrome.com/docs/extensions/mv3/richNotifications/#develop
chrome.notifications.create('', {
type: 'basic',
iconUrl: 'assets/image/logo.png',
title: '学生助手',
message: 'Time to make the toast.'
}, function (notificationId) {
console.log('notificationId: ' + notificationId)
})
}