@@ -93,6 +93,7 @@ const {render} = __webpack_require__(1);
93
93
chrome . runtime . onMessage . addListener ( ( { action} , sender , sendRes ) => {
94
94
if ( action === 'run_main' ) {
95
95
modalShown ( )
96
+ . then ( addListeners )
96
97
. then ( getName )
97
98
. then ( getTree )
98
99
. then ( createTree )
@@ -105,7 +106,16 @@ chrome.runtime.onMessage.addListener(({action}, sender, sendRes)=>{
105
106
return true
106
107
} )
107
108
//Make a directory tree and inject it into HTML
108
- const createTree = async ( paths ) => document . querySelector ( '#hubtree-modal-inner' ) . innerHTML = render ( paths , '' , ( parent , file , explicit ) => `${ file } <br>` ) ;
109
+ const createTree = async ( { paths, name, tree} ) => {
110
+ document . querySelector ( '#hubtree-modal-inner' ) . innerHTML = render ( paths , '' , ( parent , file , explicit ) => {
111
+ const type = ( tree . find ( item => {
112
+ //Account for extra slash the package adds to file name
113
+ if ( file [ file . length - 1 ] === '/' ) return item . path === ( parent + file . slice ( 0 , file . length - 1 ) )
114
+ return item . path === ( parent + file )
115
+ } ) ) . type
116
+ return `<a target="_blank" class="link" href=" https://github.com/${ name } /${ type } /master/${ parent } ${ file } " > ${ file } </a> <br>`
117
+ } )
118
+ } ;
109
119
110
120
//Add modal to webpage
111
121
const addModal = async ( ) => {
@@ -143,10 +153,16 @@ const getTree = async (name) =>{
143
153
throw new Error ( 'Problem with request' )
144
154
} )
145
155
const paths = treeData . tree . map ( item => item . path ) ;
146
- if ( paths . length > 0 ) return paths ;
156
+ if ( paths . length > 0 ) return { paths, name , tree : treeData . tree } ;
147
157
throw new Error ( 'No paths' ) ;
148
158
}
149
159
160
+ const addListeners = async ( ) => {
161
+ document . querySelector ( '#hubtree-modal' ) . addEventListener ( 'click' , ( e ) => {
162
+ if ( e . target === e . currentTarget ) modalShown ( ) . catch ( err => console . log ( err ) ) ;
163
+ } )
164
+ }
165
+
150
166
/***/ } ) ,
151
167
/* 1 */
152
168
/***/ ( function ( module , exports , __webpack_require__ ) {
0 commit comments