-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Reload tab when configs are changed in popup
- Loading branch information
Showing
4 changed files
with
39 additions
and
1 deletion.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export const sendMsgToAllTab = <T>(msg: T) => { | ||
const urls = getUrlsFromManifest(); | ||
chrome.tabs.query( | ||
{ | ||
url: urls, | ||
}, | ||
(tabs) => { | ||
tabs.forEach((tab) => { | ||
try { | ||
chrome.tabs.sendMessage(tab.id!, msg); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
}, | ||
); | ||
}; | ||
|
||
export const getUrlsFromManifest = () => { | ||
const manifest = chrome.runtime.getManifest(); | ||
const content_scripts = manifest.content_scripts; | ||
if (!content_scripts) return []; | ||
|
||
// (string | undefined)[] => string[] | ||
// なんで動くのか素でわからん | ||
// asとの違いとか、そもそもなんでこれがないとダメなのか。普通に推論して欲しい。 | ||
// //https://qiita.com/suin/items/cda9af4f4f1c53c05c6f | ||
return content_scripts | ||
.map((c) => { | ||
return c.matches; | ||
}) | ||
|
||
.flat() | ||
.filter((c): c is string => typeof c === "string"); | ||
}; |