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