3
3
const GITHUB_TOKEN_KEY = 'x-github-token'
4
4
const TOKEN_FEATURE_INFORMATION_KEY = 'user-knows-token-feature'
5
5
6
- const setGithubToken = ( key , cb ) => {
6
+ const storage = chrome . storage . sync || chrome . storage . local
7
+
8
+ function setGithubToken ( key , cb ) {
7
9
const obj = { }
8
10
9
11
obj [ GITHUB_TOKEN_KEY ] = key
10
12
11
- chrome . storage . sync . set ( obj , ( ) => {
13
+ storage . set ( obj , function ( ) {
12
14
alert ( 'Your Github token has been set successfully. Reload the Github page to see changes.' )
13
15
14
16
cb ( )
15
17
} )
16
18
}
17
19
18
- const handleOldGithubToken = ( cb ) => {
19
- chrome . storage . sync . get ( GITHUB_TOKEN_KEY , ( storedData ) => {
20
+ function handleOldGithubToken ( cb ) {
21
+ storage . get ( GITHUB_TOKEN_KEY , function ( storedData ) {
20
22
const oldGithubToken = storedData [ GITHUB_TOKEN_KEY ]
21
23
22
24
if ( oldGithubToken ) {
23
25
if ( confirm ( 'You have already set your Github token. Do you want to remove it?' ) ) {
24
- chrome . storage . sync . remove ( GITHUB_TOKEN_KEY , ( ) => {
26
+ storage . remove ( GITHUB_TOKEN_KEY , function ( ) {
25
27
alert ( 'You have successfully removed Github token. Click extension icon again to set a new token.' )
26
28
27
29
cb ( false )
@@ -39,11 +41,11 @@ const userNowKnowsAboutGithubTokenFeature = (cb) => {
39
41
const obj = { }
40
42
obj [ TOKEN_FEATURE_INFORMATION_KEY ] = true
41
43
42
- chrome . storage . sync . set ( obj , cb )
44
+ storage . set ( obj , cb )
43
45
}
44
46
45
- const informUserAboutGithubTokenFeature = ( ) => {
46
- chrome . storage . sync . get ( TOKEN_FEATURE_INFORMATION_KEY , ( storedData ) => {
47
+ function informUserAboutGithubTokenFeature ( ) {
48
+ storage . get ( TOKEN_FEATURE_INFORMATION_KEY , function ( storedData ) {
47
49
const userKnows = storedData [ TOKEN_FEATURE_INFORMATION_KEY ]
48
50
49
51
if ( ! userKnows ) {
0 commit comments