-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
57 lines (51 loc) · 1.42 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
48
49
50
51
52
53
54
55
56
57
chrome.runtime.onInstalled.addListener(() => {
// Use this event to set a state or for one-time initialization
// store default config
chrome.storage.sync.set({
bibleup_activated: false,
bibleup_init: {
popup: 'classic',
version: 'KJV',
darkTheme: false,
},
});
});
/* async function run() {
chrome.webNavigation.onCompleted.addListener(function() {
console.log('YESSS')
let [tab] = await chrome.tabs.query({active: true, currentWindow:true}) // Find current tab
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['lib/bibleup.min.js']
}, call);
})
} */
chrome.webNavigation.onCompleted.addListener(function (tab) {
if (tab.frameId == 0) {
// run in main frame only
chrome.storage.sync.get('bibleup_activated', function (data) {
if (data.bibleup_activated) {
injectBibleup();
}
});
}
});
let injectBibleup = () => {
console.log('YESSS');
chrome.tabs.query({ active: true, currentWindow: true }, function (tab) {
if (tab.length) {
chrome.scripting.executeScript({
target: { tabId: tab[0].id },
files: ['lib/bibleup.min.js'],
}, call.bind(this, tab[0].id));
}
});
};
let call = (tabId) => {
if (chrome.runtime.lastError) {
} // catch error log
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ['lib/init.js'],
});
};