generated from tjx666/awesome-chrome-extension-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from GarinZ/v1.0.10
V1.0.10
- Loading branch information
Showing
32 changed files
with
492 additions
and
250 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 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,5 @@ | ||
import log from 'loglevel'; | ||
|
||
export const setLogLevel = () => { | ||
log.setLevel(__ENV__ === 'development' ? 'debug' : 'error'); | ||
}; |
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,46 @@ | ||
import { isEmpty } from 'lodash'; | ||
import { storage } from 'webextension-polyfill'; | ||
|
||
const EXT_PAGE_INFO = 'extPageInfo'; | ||
|
||
export interface Basic { | ||
windowId: number; | ||
tabId: number; | ||
ready: boolean; | ||
} | ||
|
||
export const getExtPageInfo = async (): Promise<Basic | null> => { | ||
const extPageInfo = await storage.local.get(EXT_PAGE_INFO); | ||
// 如果key不存在,返回的localStorage为空对象 | ||
return isEmpty(extPageInfo) ? null : JSON.parse(extPageInfo[EXT_PAGE_INFO]); | ||
}; | ||
|
||
export const setExtPageInfo = async (extPageInfo: Partial<Basic>): Promise<void> => { | ||
const oldData = (await getExtPageInfo()) ?? {}; | ||
return await storage.local.set({ | ||
[EXT_PAGE_INFO]: JSON.stringify({ | ||
...oldData, | ||
...extPageInfo, | ||
}), | ||
}); | ||
}; | ||
|
||
export const removeExtPageInfo = () => { | ||
return storage.local.remove(EXT_PAGE_INFO); | ||
}; | ||
|
||
const PREV_FOCUS_WINDOW_ID = 'prevFocusWindowId'; | ||
export const getPrevFocusWindowId = async (): Promise<number | null> => { | ||
const prevFocusWindowId = await storage.local.get(PREV_FOCUS_WINDOW_ID); | ||
return isEmpty(prevFocusWindowId) ? null : prevFocusWindowId[PREV_FOCUS_WINDOW_ID]; | ||
}; | ||
|
||
export const setPrevFocusWindowId = async (prevFocusWindowId: number): Promise<void> => { | ||
return await storage.local.set({ | ||
[PREV_FOCUS_WINDOW_ID]: prevFocusWindowId, | ||
}); | ||
}; | ||
|
||
export const removePrevFocusWindowId = () => { | ||
return storage.local.remove(PREV_FOCUS_WINDOW_ID); | ||
}; |
Oops, something went wrong.