Skip to content

Commit 2c6540a

Browse files
committed
new
1 parent 8e7ddd5 commit 2c6540a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

hubtree/main.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const {render} = __webpack_require__(1);
9393
chrome.runtime.onMessage.addListener(({action}, sender, sendRes)=>{
9494
if(action ==='run_main'){
9595
modalShown()
96+
.then(addListeners)
9697
.then(getName)
9798
.then(getTree)
9899
.then(createTree)
@@ -105,7 +106,16 @@ chrome.runtime.onMessage.addListener(({action}, sender, sendRes)=>{
105106
return true
106107
})
107108
//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+
};
109119

110120
//Add modal to webpage
111121
const addModal = async () =>{
@@ -143,10 +153,16 @@ const getTree = async (name) =>{
143153
throw new Error('Problem with request')
144154
})
145155
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};
147157
throw new Error('No paths');
148158
}
149159

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+
150166
/***/ }),
151167
/* 1 */
152168
/***/ (function(module, exports, __webpack_require__) {

hubtree/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@
1818
font-size: 1.2rem;
1919
height: 100%;
2020
overflow-y: scroll;
21+
}
22+
23+
.link {
24+
color: white;
2125
}

0 commit comments

Comments
 (0)