-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackground.js
More file actions
36 lines (33 loc) · 1.47 KB
/
Copy pathbackground.js
File metadata and controls
36 lines (33 loc) · 1.47 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
const useChrome = typeof (browser) === 'undefined';
const executionCommand = {
files: ['gpi.js'],
target: { allFrames: true, tabId: 0 },
world: 'MAIN'
};
const executionEnvironment = {
func: function (optionData) {
window.gpi = Object.assign({}, optionData);
},
args: [],
target: { allFrames: true, tabId: 0 },
world: 'MAIN',
injectImmediately: true
};
async function handleTabUpdate (tabId, changeInfo, tab) {
if (tab && tab.status === 'complete' && tab.url) {
const transformedOrigin = tab.url;
const hasHostPermission = useChrome ? await chrome.permissions.contains({ origins: [transformedOrigin] }) : await browser.permissions.contains({ origins: [transformedOrigin] });
console.debug('googlePanicImage - hasHostPermission: ', hasHostPermission);
if (hasHostPermission) {
const optionData = useChrome ? await chrome.storage.local.get() : await browser.storage.local.get();
if (optionData) {
executionEnvironment.target.tabId = tab.id;
executionEnvironment.args = [optionData];
useChrome ? await chrome.scripting.executeScript(executionEnvironment) : await browser.scripting.executeScript(executionEnvironment);
}
executionCommand.target.tabId = tab.id;
useChrome ? await chrome.scripting.executeScript(executionCommand) : await browser.scripting.executeScript(executionCommand);
}
}
}
useChrome ? chrome.tabs.onUpdated.addListener(handleTabUpdate) : browser.tabs.onUpdated.addListener(handleTabUpdate);