@@ -4,6 +4,8 @@ const API = 'https://api.github.com/repos/'
4
4
const LI_TAG_ID = 'github-repo-size'
5
5
const GITHUB_TOKEN_KEY = 'x-github-token'
6
6
7
+ const storage = chrome . storage . sync || chrome . storage . local
8
+
7
9
let githubToken
8
10
9
11
const isTree = ( uri ) => {
@@ -52,7 +54,7 @@ const getHumanReadableSizeObject = (bytes) => {
52
54
}
53
55
54
56
const K = 1024
55
- const MEASURE = [ 'Bytes ' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ]
57
+ const MEASURE = [ 'B ' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ]
56
58
const i = Math . floor ( Math . log ( bytes ) / Math . log ( K ) )
57
59
58
60
return {
@@ -73,15 +75,13 @@ const getSizeHTML = (size) => {
73
75
const humanReadableSize = getHumanReadableSizeObject ( size )
74
76
75
77
return '<li id="' + LI_TAG_ID + '">' +
76
- '<a>' +
77
78
'<svg class="octicon octicon-database" aria-hidden="true" height="16" version="1.1" viewBox="0 0 12 16" width="12">' +
78
79
'<path d="M6 15c-3.31 0-6-.9-6-2v-2c0-.17.09-.34.21-.5.67.86 3 1.5 5.79 1.5s5.12-.64 5.79-1.5c.13.16.21.33.21.5v2c0 1.1-2.69 2-6 2zm0-4c-3.31 0-6-.9-6-2V7c0-.11.04-.21.09-.31.03-.06.07-.13.12-.19C.88 7.36 3.21 8 6 8s5.12-.64 5.79-1.5c.05.06.09.13.12.19.05.1.09.21.09.31v2c0 1.1-2.69 2-6 2zm0-4c-3.31 0-6-.9-6-2V3c0-1.1 2.69-2 6-2s6 .9 6 2v2c0 1.1-2.69 2-6 2zm0-5c-2.21 0-4 .45-4 1s1.79 1 4 1 4-.45 4-1-1.79-1-4-1z"></path>' +
79
80
'</svg>' +
80
81
'<span class="num text-emphasized"> ' +
81
82
humanReadableSize . size +
82
83
'</span> ' +
83
84
humanReadableSize . measure +
84
- '</a>' +
85
85
'</li>'
86
86
}
87
87
@@ -126,8 +126,9 @@ const getAPIData = (uri, callback) => {
126
126
const getFileName = ( text ) => text . trim ( ) . split ( '/' ) [ 0 ]
127
127
128
128
const checkForRepoPage = ( ) => {
129
- const repoURI = window . location . pathname . substring ( 1 )
130
- const repoPath = repoURI . split ( '/' ) . splice ( 4 ) . join ( '/' ) . trim ( )
129
+ let repoURI = window . location . pathname . substring ( 1 )
130
+ repoURI = repoURI . endsWith ( '/' ) ? repoURI . slice ( 0 , - 1 ) : repoURI
131
+ let repoPath = repoURI . split ( '/' ) . splice ( 4 ) . join ( '/' ) . trim ( )
131
132
132
133
if ( isTree ( repoURI ) ) {
133
134
const ns = document . querySelector ( 'ul.numbers-summary' )
@@ -173,7 +174,7 @@ const checkForRepoPage = () => {
173
174
}
174
175
}
175
176
176
- chrome . storage . sync . get ( GITHUB_TOKEN_KEY , ( data ) => {
177
+ storage . get ( GITHUB_TOKEN_KEY , function ( data ) {
177
178
githubToken = data [ GITHUB_TOKEN_KEY ]
178
179
179
180
chrome . storage . onChanged . addListener ( ( changes , namespace ) => {
0 commit comments