This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
73 lines (65 loc) · 2.03 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*global browser chrome*/
console.log("background.js");
let main = chrome || browser;
/**
* Context menus
*
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Context_menu_items
*/
main.contextMenus.create(
{
contexts: ["all"],
id: "web-extension-template",
title: "Web Extension Template"
},
() => console.log("[contextMenus: onCreated] Context menu created")
);
main.contextMenus.onClicked.addListener(info => {
console.log(`[contextMenus: onClicked] User clicked on: "${info.menuItemId}"`);
});
/**
* Omnibox
*
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Omnibox
*/
main.omnibox.setDefaultSuggestion({
description: "Phone Home"
});
main.omnibox.onInputChanged.addListener((text, addSuggestions) => {
console.log(`[omnibox: onInputChanged] User typed "${text}" so far`);
addSuggestions([
{
content: "Content",
description: "Description"
}
]);
});
main.omnibox.onInputEntered.addListener((text, disposition) => {
console.log(`[omnibox: onInputEntered] User selected "${text}" (disposition: ${disposition})`);
});
/**
* Window/tab changed
*
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onActivated
*/
main.tabs.onActivated.addListener(() => {
console.log("[tabs: onActivated] User changed browser window/tab");
});
/**
* Toolbar button
*
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Browser_action
*/
main.browserAction.onClicked.addListener(() => {
console.log("[browserAction: onClicked] User clicked on toolbar");
});
/**
* Address bar button
*
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Page_actions
*/
if (Object.prototype.hasOwnProperty.call(main, "pageAction")) {
main.pageAction.onClicked.addListener(() => {
console.log("[pageAction: onClicked] User clicked on address bar");
});
}