diff --git a/src/inject.js b/src/inject.js index 6b140de..3e16266 100755 --- a/src/inject.js +++ b/src/inject.js @@ -67,11 +67,11 @@ const getSizeHTML = (size) => { return `
  • - - ${humanReadableSize.size} ${humanReadableSize.measure} + ${humanReadableSize.size} ${humanReadableSize.measure}
  • ` @@ -132,20 +132,24 @@ const checkForRepoPage = async () => { const ns = document.querySelector('ul.UnderlineNav-body') const navElem = document.getElementById(NAV_ELEM_ID) const tdElems = document.querySelector('span.github-repo-size-div') + + // whether the files list box has any rows + const viewingDir = document.querySelector('div.Box-row') && true if (ns && !navElem) { getAPIData(repoObj.repo).then(summary => { if (summary && summary.size) { ns.insertAdjacentHTML('beforeend', getSizeHTML(summary.size * 1024)) const newLiElem = document.getElementById(NAV_ELEM_ID) - newLiElem.title = 'Click to load directory sizes' - newLiElem.style.cssText = 'cursor: pointer' - newLiElem.onclick = loadDirSizes + if(viewingDir) { + newLiElem.title = 'Click to load directory sizes' + newLiElem.onclick = loadDirSizes + } } }) } - if (tdElems) return + if (!viewingDir || tdElems) return const tree = await getAPIData(`${repoObj.repo}/contents/${repoObj.currentPath}?ref=${repoObj.ref}`) const sizeObj = { '..': '..' }