9
9
getMuiDirExpandedIcon ,
10
10
getMUIDirIcon ,
11
11
getMuiFileIcon ,
12
+ getMUISubmoduleIcon ,
12
13
} from './libs/mui' ;
13
- import { detectBrowser } from './utils/detectBrowser' ;
14
+ import { getCurrentBrowser } from './utils/detectBrowser' ;
14
15
import { get , set } from './utils/storage' ;
15
16
// Content css
16
17
import '../styles/icons/icons.scss' ;
@@ -21,6 +22,8 @@ import './constants/colorThemesScss';
21
22
import { getResourceURL } from './utils/getResourceURL' ;
22
23
import { IconThemes } from './constants/iconThemes' ;
23
24
25
+ const currentBrowser = getCurrentBrowser ( ) ;
26
+
24
27
// ============ Icon theme ===================
25
28
26
29
const fonts = [
@@ -36,7 +39,6 @@ let octotree = false;
36
39
let github = false ;
37
40
let githubDiff = false ;
38
41
let iconTheme = IconThemes . MUI ;
39
- const browserName = detectBrowser ( ) ;
40
42
const githubMuiIconClass = 'github-mui-icon' ;
41
43
const muiIconOctotreeClass = 'mui-icon-octotree' ;
42
44
const muiDirClass = 'mui-icon-dir' ;
@@ -69,17 +71,20 @@ const replaceGithubIcon = ({
69
71
iconDom,
70
72
filenameDom,
71
73
isDir,
74
+ isSubmodule,
72
75
} : {
73
76
iconDom : HTMLElement | null ;
74
77
filenameDom : HTMLElement ;
75
78
isDir : boolean ;
79
+ isSubmodule : boolean ;
76
80
} ) => {
77
81
const fileName = isMobile
78
82
? getGitHubMobileFilename ( filenameDom )
79
83
: filenameDom . innerText . trim ( ) ;
80
84
if ( iconTheme === IconThemes . MUI ) {
81
85
let icon ;
82
- if ( ! isDir ) icon = getMuiFileIcon ( fileName ) ;
86
+ if ( ! isDir )
87
+ icon = isSubmodule ? getMUISubmoduleIcon ( ) : getMuiFileIcon ( fileName ) ;
83
88
else icon = getMUIDirIcon ( fileName ) ;
84
89
if ( iconDom ) {
85
90
const img = document . createElement ( 'img' ) ;
@@ -103,18 +108,17 @@ const replaceGithubDiffIcon = ({
103
108
iconDom,
104
109
filenameDom,
105
110
isDir,
111
+ isSubmodule,
106
112
} : {
107
113
iconDom : HTMLElement | null ;
108
114
filenameDom : HTMLElement ;
109
115
isDir : boolean ;
116
+ isSubmodule : boolean ;
110
117
} ) => {
111
118
const fileName = isMobile
112
119
? getGitHubMobileFilename ( filenameDom )
113
120
: filenameDom . innerText . trim ( ) ;
114
121
if ( iconTheme === IconThemes . MUI ) {
115
- let icon ;
116
- if ( ! isDir ) icon = getMuiFileIcon ( fileName ) ;
117
- else icon = getMUIDirIcon ( fileName ) ;
118
122
if ( iconDom ) {
119
123
if ( isDir ) {
120
124
const [ icon , expandedIcon ] = [
@@ -133,7 +137,9 @@ const replaceGithubDiffIcon = ({
133
137
iconDom . parentNode ?. replaceChild ( img , iconDom ) ;
134
138
img . parentNode ?. appendChild ( expandedImg ) ;
135
139
} else {
136
- const icon = getMuiFileIcon ( fileName ) ;
140
+ const icon = isSubmodule
141
+ ? getMUISubmoduleIcon ( )
142
+ : getMuiFileIcon ( fileName ) ;
137
143
if ( icon ) {
138
144
const img = document . createElement ( 'img' ) ;
139
145
img . classList . add ( muiIconDiffClass ) ;
@@ -146,7 +152,6 @@ const replaceGithubDiffIcon = ({
146
152
} else {
147
153
const className : string | null = fileIcons . getClassWithColor ( fileName ) ;
148
154
if ( className && ! isDir ) {
149
- console . log ( className ) ;
150
155
const icon = document . createElement ( 'span' ) ;
151
156
icon . className = `icon octicon-file ${ className } ` ;
152
157
if ( iconDom ) {
@@ -199,7 +204,12 @@ const replaceOctotreeIcon = ({
199
204
iconDom . parentNode ?. appendChild ( img ) ;
200
205
iconDom . parentNode ?. appendChild ( expandedImg ) ;
201
206
} else {
202
- const icon = getMuiFileIcon ( filename ) ;
207
+ const isSubmodule = ! Boolean (
208
+ iconDom . parentElement ?. getAttribute ( 'data-download-url' )
209
+ ) ;
210
+ const icon = isSubmodule
211
+ ? getMUISubmoduleIcon ( )
212
+ : getMuiFileIcon ( filename ) ;
203
213
if ( icon ) {
204
214
const img = document . createElement ( 'img' ) ;
205
215
img . classList . add ( muiIconOctotreeClass ) ;
@@ -242,11 +252,16 @@ const init = async () => {
242
252
'svg[aria-label=File]' ,
243
253
element
244
254
) as HTMLElement ;
255
+ const submoduleIconDom = select (
256
+ 'svg[aria-label=Submodule]' ,
257
+ element
258
+ ) as HTMLElement ;
245
259
246
260
replaceGithubIcon ( {
247
- iconDom : dirIconDom || fileIconDom ,
261
+ iconDom : dirIconDom || submoduleIconDom || fileIconDom ,
248
262
filenameDom,
249
263
isDir : Boolean ( dirIconDom ) ,
264
+ isSubmodule : Boolean ( submoduleIconDom ) ,
250
265
} ) ;
251
266
} ,
252
267
} ) ;
@@ -265,10 +280,16 @@ const init = async () => {
265
280
'svg[aria-label=File]' ,
266
281
element
267
282
) as HTMLElement ;
283
+ const submoduleIconDom = select (
284
+ 'svg[aria-label=Submodule]' ,
285
+ element
286
+ ) as HTMLElement ;
287
+
268
288
replaceGithubDiffIcon ( {
269
- iconDom : dirIconDom || fileIconDom ,
289
+ iconDom : dirIconDom || submoduleIconDom || fileIconDom ,
270
290
filenameDom,
271
291
isDir : Boolean ( dirIconDom ) ,
292
+ isSubmodule : Boolean ( submoduleIconDom ) ,
272
293
} ) ;
273
294
} ,
274
295
} ) ;
@@ -343,16 +364,14 @@ const applyColorTheme = async () => {
343
364
} ,
344
365
} ) ;
345
366
346
- ( browserName === 'chrome' ? chrome : browser ) . runtime . onMessage . addListener (
347
- ( request ) => {
348
- try {
349
- const message = JSON . parse ( request . message ) ;
350
- if ( message . type === 'OT_CODE_COLOR_THEME' ) {
351
- changeTheme ( message . codeColorTheme ) ;
352
- }
353
- } catch ( e ) { }
354
- }
355
- ) ;
367
+ currentBrowser . runtime . onMessage . addListener ( ( request ) => {
368
+ try {
369
+ const message = JSON . parse ( request . message ) ;
370
+ if ( message . type === 'OT_CODE_COLOR_THEME' ) {
371
+ changeTheme ( message . codeColorTheme ) ;
372
+ }
373
+ } catch ( e ) { }
374
+ } ) ;
356
375
} ;
357
376
358
377
get (
371
390
init ( ) ;
372
391
applyColorTheme ( ) ;
373
392
374
- chrome . runtime . onMessage . addListener ( function ( request ) {
393
+ currentBrowser . runtime . onMessage . addListener ( function ( request ) {
375
394
if ( request . message === Keys . OT_TAB_UPDATE ) {
376
395
applyColorTheme ( ) ;
377
396
}
0 commit comments