-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
41 lines (35 loc) · 877 Bytes
/
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
const id = "morsefire";
const defaultSettings = {
wpm: 20,
freq: 500,
eff: 15,
ews: 0.1,
playvolume: 0.1,
onHighlight: false,
};
function saveSettings(settings) {
browser.storage.local.set({ [id]: settings });
}
function getSettings() {
return browser.storage.local
.get(id)
.then((result) => result[id] ?? defaultSettings);
}
browser.contextMenus.create({
id,
title: "Play selection as Morse code",
contexts: ["selection"],
});
browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === id) {
browser.tabs.sendMessage(tab.id, { action: id, text: info.selectionText });
}
});
browser.runtime.onMessage.addListener((request) => {
switch (request.action) {
case "morsefire_settings_get":
return getSettings();
case "morsefire_settings_set":
return saveSettings(request.settings);
}
});