-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
43 lines (38 loc) · 1.25 KB
/
background.js
File metadata and controls
43 lines (38 loc) · 1.25 KB
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
chrome.runtime.onInstalled.addListener(() => {
console.log("Extension installed");
});
// Function to inject the global variable
function injectGlobalVariable(tabId) {
chrome.scripting.executeScript({
target: {tabId: tabId},
func: () => {
window.humanextension = true;
document.documentElement.setAttribute('human-extension-installed', true);
var isInstalled = document.documentElement.getAttribute('human-extension-installed');
console.log("is installed::", isInstalled);
console.log("this is setting");
console.log('Human extension global variable has been set');
}
});
}
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
if (request) {
if (request.message) {
if (request.message == "version") {
sendResponse({version: 1.0});
}
}
}
return true;
});
// Execute when the extension icon is clicked
chrome.action.onClicked.addListener((tab) => {
injectGlobalVariable(tab.id);
});
// Optionally, inject into all tabs when they're updated
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url.startsWith('http')) {
injectGlobalVariable(tabId);
}
});