-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,52 @@ | ||
// Update extension content for slack tabs | ||
chrome.tabs.query({}, async (tabs) => { | ||
for (const tabKey in tabs) { | ||
const tab = tabs[tabKey]; | ||
|
||
// Do not have permission | ||
if (tab.url === undefined) { | ||
continue; | ||
} | ||
const injectContentToTab = async (tab: chrome.tabs.Tab) => { | ||
// Do not have permission | ||
if (tab.url === undefined) { | ||
return; | ||
} | ||
|
||
// Skip execute on discarded tab | ||
if (tab.discarded) { | ||
continue; | ||
} | ||
// Skip execute on discarded tab | ||
if (tab.discarded) { | ||
return; | ||
} | ||
|
||
// Under some circumstances a Tab may not be assigned an ID | ||
if (tab.id === undefined) { | ||
continue; | ||
} | ||
// Under some circumstances a Tab may not be assigned an ID | ||
if (tab.id === undefined) { | ||
return; | ||
} | ||
|
||
const manifest = chrome.runtime.getManifest(); | ||
const cssFiles = manifest.content_scripts?.[0].css ?? []; | ||
const jsFiles = manifest.content_scripts?.[0].js ?? []; | ||
const manifest = chrome.runtime.getManifest(); | ||
const cssFiles = manifest.content_scripts?.[0].css ?? []; | ||
const jsFiles = manifest.content_scripts?.[0].js ?? []; | ||
|
||
if (cssFiles.length > 0) { | ||
await chrome.scripting.insertCSS({ | ||
target: { | ||
tabId: tab.id, | ||
allFrames: true, | ||
}, | ||
files: cssFiles, | ||
}); | ||
chrome.scripting.executeScript({ | ||
} | ||
if (jsFiles.length > 0) { | ||
await chrome.scripting.executeScript({ | ||
target: { | ||
tabId: tab.id, | ||
allFrames: true, | ||
}, | ||
files: jsFiles, | ||
}); | ||
} | ||
}; | ||
|
||
// Update extension content for tabs | ||
chrome.tabs.query({}, async (tabs) => { | ||
for (const tabKey in tabs) { | ||
const tab = tabs[tabKey]; | ||
|
||
try { | ||
injectContentToTab(tab); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
}); |