-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
executable file
·47 lines (42 loc) · 1.16 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
/*global browser, console*/
async function execute(tab, direction) {
const file = direction === 'lat_to_cyr' ? 'srbtranslit.js' : 'srbtranslitToCyr.js';
try {
await browser.scripting.executeScript({
target: {
tabId: tab.id,
allFrames: true,
},
files: [file],
});
} catch (err) {
console.error(`failed to execute script: ${err}`);
}
}
browser.contextMenus.create(
{
id: "transliterate-to-lat",
title: "Preslovi u latinicu",
contexts: ["page"],
},
() => void browser.runtime.lastError,
);
browser.contextMenus.create(
{
id: "transliterate-to-cyr",
title: "Преслови у ћирилицу (experimental)",
contexts: ["page"],
},
() => void browser.runtime.lastError,
);
browser.action.onClicked.addListener(async (tab) => execute(tab, 'lat_to_cyr'));
browser.contextMenus.onClicked.addListener((info, tab) => {
switch (info.menuItemId) {
case "transliterate-to-lat":
execute(tab, 'lat_to_cyr').then(r => void browser.runtime.lastError);
break;
case "transliterate-to-cyr":
execute(tab, 'cyr_to_lat').then(r => void browser.runtime.lastError);
break;
}
});