-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
46 lines (32 loc) · 952 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
42
43
44
45
46
// https://anobjectisa.com/?p=410
chrome.runtime.onInstalled.addListener(({ reason, version }) => {
if (reason === chrome.runtime.OnInstalledReason.INSTALL) {
console.log("Install")
}
});
chrome.action.onClicked.addListener((tab) => {
console.log("click");
});
chrome.tabs.onUpdated.addListener(
function(tabId, changeInfo, tab) {
if (changeInfo.status === 'complete' && /^http/.test(tab.url)) {
info = get_url_info();
chrome.storage.local.set({
url: tab.url,
info: info,
}, function(){});
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ["./content-script.js"]
})
.then(() => {
console.log("INJECTED THE FOREGROUND SCRIPT.");
})
.catch(err => console.log(err));
}
}
);
function get_url_info(){
var info = {'id':0, 'name':'bob'};
return info
}