-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
37 lines (34 loc) · 939 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
let isEnabled = true;
chrome.commands.onCommand.addListener((command) => {
if (command === "toggle-extension") {
isEnabled = !isEnabled;
if (isEnabled) {
console.log("Extension enabled");
chrome.scripting.registerContentScripts([{
id: 'content_script',
matches: ['<all_urls>'],
js: ['content.js'],
runAt: 'document_idle'
}]);
} else {
console.log("Extension disabled");
chrome.scripting.unregisterContentScripts({ ids: ['content_script'] });
}
}
});
// Add a context menu item
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "goBack",
title: "Go Back",
contexts: ["all"]
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "goBack") {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: () => window.history.back()
});
}
});