Fix bug: table update error while using file view
The extension tried to update file sizes even when a directory page was not being browsed, which led to error TypeError: tree.forEach is not a function on line 153 (line number before this pull request)
For example, visit page: https://github.com/harshjv/github-repo-size/blob/master/src/inject.js and check extension errors.
This is now fixed by detecting directory view with the presence of the 'Add file' button and updating table only if the button is present.
Also, removed redundant CSS 'cursor: pointer' for newLiElem.
@msvamp thank you for the update!
Can you please share steps to reproduce TypeError: tree.forEach is not a function error?
Sure. The steps are pretty simple.
Steps to reproduce
- Ensure the extension is enabled and Chrome Extensions Developer mode is enabled
- If the unpacked extension is being run, skip this step. But if one is running the extension from the webstore, Chrome will ignore all errors by default. So, visit
chrome://extensions/?id=apnjnioapinblneaedefcnopcjepgkciand enable the Collect Errors switch. - Now, visit the page corresponding to any file (not folder) in any GitHub repository. For example, the license file of this repository.
- Go to
chrome://extensions/?errors=apnjnioapinblneaedefcnopcjepgkciand the error should be there.
Steps to reproduce (alternate)
Alternately, the same error is also visible in the console section of the Developer Tools on visiting the same page.

What causes the error?
When a request is made to GitHub API for a directory in a repo or the root of the repo, the response contains the corresponding details of all files in the folder in the the form of an array of JSON objects.
Example request: https://api.github.com/repos/harshjv/github-repo-size/contents/?ref=f82f23b9a2c18afdd824cc0b89b1d909b9a090f9

But when a request is made for a file in a repo, the response contains a single JSON object with the details of the single file, and hence the forEach operation fails.
Example request: https://api.github.com/repos/harshjv/github-repo-size/contents/LICENSE.md?ref=f82f23b9a2c18afdd824cc0b89b1d909b9a090f9
