-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
38 lines (36 loc) · 993 Bytes
/
Copy pathbackground.js
File metadata and controls
38 lines (36 loc) · 993 Bytes
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
if (!chrome.scripting) {
console.error(
'chrome.scripting is undefined at background script start. Check permissions in manifest.json and reload the extension.'
);
} else {
console.log('chrome.scripting is available at background script start.');
}
chrome.contextMenus.create(
{
id: 'typeSelection',
title: 'TypePractice Select',
contexts: ['selection'],
},
() => {
if (chrome.runtime.lastError) {
console.warn(
'Context menu creation error:',
chrome.runtime.lastError.message
);
} else {
console.log('Context menu created');
}
}
);
chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === 'typeSelection') {
chrome.scripting
.executeScript({
target: { tabId: tab.id },
func: () => {
document.dispatchEvent(new CustomEvent('enableTypingMode'));
},
})
.catch((err) => console.error('Failed to execute script:', err));
}
});