Skip to content

Instantly share code, notes, and snippets.

@Howard3
Last active May 10, 2023 12:26
Show Gist options
  • Save Howard3/fead4485a5a95d6886677f2fb65f4b13 to your computer and use it in GitHub Desktop.
Save Howard3/fead4485a5a95d6886677f2fb65f4b13 to your computer and use it in GitHub Desktop.
github_nav_packages_tab userscript
// ==UserScript==
// @name Github Packages Tab
// @description Adds a Packages tab to Github repository navigation bar.
// @version 1
// @grant none
// @match https://github.com/*
// @license MIT
// @author Howard D. Lince III
// @supportURL https://twitter.com/HowardL3
// @namespace https://github.com/howard3
// ==/UserScript==
(function() {
const repoUrlRegex = /\/([^\/]+)\/([^\/]+)\//;
const repoNav = document.querySelector('nav.js-repo-nav ul');
if (repoNav) {
const match = repoUrlRegex.exec(window.location.pathname);
if (match) {
const orgName = match[1];
const repoName = match[2];
const packagesUrl = `https://github.com/orgs/${orgName}/packages?repo_name=${repoName}`;
const packagesTab = document.createElement('li');
packagesTab.setAttribute('data-view-component', 'true');
packagesTab.classList.add('d-inline-flex');
packagesTab.innerHTML = `
<a href="${packagesUrl}" data-selected-links="repo_packages" data-tab-item="i8packages-tab" data-hotkey="g p" data-ga-click="Repository, Navigation click, Packages tab" data-view-component="true" class="js-selected-navigation-item UnderlineNav-item hx_underlinenav-item no-wrap js-responsive-underlinenav-item">
<svg height="16" class="octicon octicon-package UnderlineNav-octicon d-none d-sm-inline" viewBox="0 0 16 16" version="1.1" width="16" aria-hidden="true"><path fill-rule="evenodd" d="M14.5 1H1.5C.7 1 0 1.7 0 2.5v11c0 .8.7 1.5 1.5 1.5h13c.8 0 1.5-.7 1.5-1.5v-11c0-.8-.7-1.5-1.5-1.5zM1.5 2.02h13v2.17H1.5v-2.17zM1.5 13.98V8.9h13v5.08c0 .18-.14.32-.32.32h-12.36c-.18 0-.32-.14-.32-.32zM5.5 10c-.28 0-.5-.22-.5-.5v-2c0-.28.22-.5.5-.5s.5.22.5.5v2c0 .28-.22.5-.5.5zm3 0c-.28 0-.5-.22-.5-.5v-2c0-.28.22-.5.5-.5s.5.22.5.5v2c0 .28-.22.5-.5.5zm3 0c-.28 0-.5-.22-.5-.5v-2c0-.28.22-.5.5-.5s.5.22.5.5v2c0 .28-.22.5-.5.5z"></path></svg>
<span data-content="Packages">Packages</span>
</a>`;
repoNav.appendChild(packagesTab);
} else {
console.log("not found")
}
}
})();
@Howard3
Copy link
Author

Howard3 commented May 10, 2023

This Greasemonkey script adds a "Packages" tab to the repository navigation bar on Github. When viewing a repository, the script adds a new tab that links to the repository's packages page. The link to the packages page is constructed dynamically based on the organization and repository names extracted from the URL.

To use this script, you'll need to have a userscript manager installed in your browser, such as Greasemonkey or Tampermonkey. Once you have the userscript manager installed, you can simply copy and paste the script into a new userscript and save it. The next time you visit a Github repository page, the "Packages" tab should appear in the repository navigation bar.

@Howard3
Copy link
Author

Howard3 commented May 10, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment