-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use content script to stat browsing time for mv3 (#71)
- Loading branch information
1 parent
1366890
commit 2b9956c
Showing
39 changed files
with
262 additions
and
441 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
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 was deleted.
Oops, something went wrong.
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
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 @@ | ||
import { onInstalled } from "@api/chrome/runtime" | ||
import { createTab, listTabs } from "@api/chrome/tab" | ||
import metaService from "@service/meta-service" | ||
import { getGuidePageUrl } from "@util/constant/url" | ||
import { isBrowserUrl } from "@util/pattern" | ||
import UninstallListener from './uninstall-listener' | ||
|
||
async function onFirstInstall() { | ||
createTab(getGuidePageUrl(true)) | ||
metaService.updateInstallTime(new Date()) | ||
} | ||
|
||
function executeScript(tabId: number, files: string[]) { | ||
chrome.scripting.executeScript({ target: { tabId }, files }).catch(err => console.log(err)) | ||
} | ||
|
||
async function reloadContentScript() { | ||
const files = chrome.runtime.getManifest().content_scripts?.[0]?.js | ||
if (!files?.length) { | ||
return | ||
} | ||
const tabs = await listTabs() | ||
tabs.filter(({ url }) => url && !isBrowserUrl(url)) | ||
.forEach(tab => executeScript(tab.id, files)) | ||
} | ||
|
||
export default function handleInstall() { | ||
onInstalled(async reason => { | ||
reason === "install" && await onFirstInstall() | ||
// Questionnaire for uninstall | ||
new UninstallListener().listen() | ||
// Reload content-script | ||
await reloadContentScript() | ||
}) | ||
} |
File renamed without changes.
Oops, something went wrong.