diff --git a/source/features/more-dropdown.tsx b/source/features/more-dropdown.tsx index f031e3a2d2bb..f029fa833f7d 100644 --- a/source/features/more-dropdown.tsx +++ b/source/features/more-dropdown.tsx @@ -31,10 +31,32 @@ async function init(): Promise { createDropdown(); } + let compareUrl = `/${repoUrl}/compare`; + let commitsUrl = `/${repoUrl}/commits`; + let tree = ''; + const urlParts = location.pathname.split('/'); + if (urlParts[3] === 'tree') { // On repo page + tree = urlParts[4]; + } else if (urlParts[3] === 'compare') { // On compare page + if (urlParts[4].includes('...')) { + tree = urlParts[4].split('...')[0]; + } else { + tree = urlParts[4]; + } + } else if (urlParts[3] === 'commits') { // On commits page + tree = urlParts[4]; + } else if (urlParts[3] === 'releases' && urlParts[4] === 'tag') { // On tag page + tree = urlParts[5]; + } + if (tree) { + compareUrl += `/${tree}`; + commitsUrl += `/${tree}`; + } + const menu = select('.reponav-dropdown .dropdown-menu')!; menu.append( - + {icons.darkCompare()} Compare , @@ -43,7 +65,7 @@ async function init(): Promise { {icons.dependency()} Dependencies , - + {icons.history()} Commits ,