-
Notifications
You must be signed in to change notification settings - Fork 2
/
background.js
52 lines (36 loc) · 1.54 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
// This event is fired when the user installs/updates the extension
browser.runtime.onInstalled.addListener(details => {
function onInstall() {
const DEFAULT_CONFIG = {
[STORAGE_RULES]: [
{ id: 0, searchValue: ":ff", replaceValue: "firefox" },
{ id: 1, searchValue: ":js", replaceValue: "javascript" },
{ id: 2, searchValue: ":ciu", replaceValue: "caniuse" },
{ id: 3, searchValue: ":so", replaceValue: "stackoverflow" },
{ id: 4, searchValue: ":bea", replaceValue: "browser extension api" },
{ id: 5, searchValue: ":lx", replaceValue: "linux" },
{ id: 6, searchValue: "@db", replaceValue: "danielbiegler.de" },
],
[STORAGE_DEFAULT_SEARCH_URL]: "https://www.google.com/search?q=%s"
};
browser.storage.sync.set(DEFAULT_CONFIG)
.then(generateDefaultSuggestions);
}
function onUpdate(currentVersion, previousVersion) {
// Currently there's nothing to do here.
// Future versions might need to use this to update the internals
}
const currentVersion = browser.runtime.getManifest().version;
const previousVersion = details.previousVersion;
const reason = details.reason;
switch (reason) {
case 'install':
onInstall();
break;
case 'update':
onUpdate(currentVersion, previousVersion);
break;
}
});
// This event is fired when the user accepts the input in the omnibox.
browser.omnibox.onInputEntered.addListener( handleSearch );