Skip to content

Instantly share code, notes, and snippets.

@AllenJB
Last active August 1, 2020 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllenJB/5e6ced2ba0dec3d66f1c7e82ddf0901f to your computer and use it in GitHub Desktop.
Save AllenJB/5e6ced2ba0dec3d66f1c7e82ddf0901f to your computer and use it in GitHub Desktop.
June 2020 GitHub Redesign Modifications
.IssueLabel {
border-radius: 3px !important;
padding: 0 3px !important;
}
.UnderlineNav {
justify-content: center;
}
.UnderlineNav-item {
padding: 2px 12px !important;
}
.mb-3 {
margin-bottom: 2px !important;
}
// ==UserScript==
// @name GitHub menu additions
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author AllenJB
// @match https://github.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let url = window.location.href;
let re = new RegExp("github\.com/(?<owner>[^/]+)/(?<repo>[^/\?\#]+)/?(?<section>[^/\?\#]+)?");
let matches = url.match(re);
if (typeof matches.groups.owner === 'undefined') {
console.log("Menu additions: Failed to find repo owner");
return;
}
let repoOwner = matches.groups.owner;
let repoName = matches.groups.repo;
let siteSection = null;
if (typeof matches.groups.section !== 'undefined') {
siteSection = matches.groups.section;
}
let repoUrl = '/'+ repoOwner +'/'+ repoName +'/';
let refNode = document.querySelector("nav.js-repo-nav li");
let htmlReleases = '<li class="d-flex"><a class="js-selected-navigation-item UnderlineNav-item hx_underlinenav-item no-wrap js-responsive-underlinenav-item ajb-nav-releases" data-tab-item="releases-tab" href="'+ repoUrl +'releases"'
+' data-selected-links="repo_releases '+ repoUrl +'releases">'
+'<svg class="octicon octicon-issue-opened UnderlineNav-octicon d-none d-sm-inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.75 2.5a.25.25 0 00-.25.25v1.5c0 .138.112.25.25.25h12.5a.25.25 0 00.25-.25v-1.5a.25.25 0 00-.25-.25H1.75zM0 2.75C0 1.784.784 1 1.75 1h12.5c.966 0 1.75.784 1.75 1.75v1.5A1.75 1.75 0 0114.25 6H1.75A1.75 1.75 0 010 4.25v-1.5zM1.75 7a.75.75 0 01.75.75v5.5c0 .138.112.25.25.25h10.5a.25.25 0 00.25-.25v-5.5a.75.75 0 111.5 0v5.5A1.75 1.75 0 0113.25 15H2.75A1.75 1.75 0 011 13.25v-5.5A.75.75 0 011.75 7zm4.5 1a.75.75 0 000 1.5h3.5a.75.75 0 100-1.5h-3.5z"></path></svg>'
+'<span data-content="Releases">Releases</span>'
+'</a></li>';
let htmlBranches = '<li class="d-flex"><a class="js-selected-navigation-item UnderlineNav-item hx_underlinenav-item no-wrap js-responsive-underlinenav-item ajb-nav-branches" data-tab-item="branches-tab" href="'+ repoUrl +'branches">'
+'<svg class="octicon octicon-issue-opened UnderlineNav-octicon d-none d-sm-inline" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M11.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.25.75a2.25 2.25 0 113 2.122V6A2.5 2.5 0 0110 8.5H6a1 1 0 00-1 1v1.128a2.251 2.251 0 11-1.5 0V5.372a2.25 2.25 0 111.5 0v1.836A2.492 2.492 0 016 7h4a1 1 0 001-1v-.628A2.25 2.25 0 019.5 3.25zM4.25 12a.75.75 0 100 1.5.75.75 0 000-1.5zM3.5 3.25a.75.75 0 111.5 0 .75.75 0 01-1.5 0z"></path></svg>'
+'<span data-content="Branches">Branches</span>'
+'</a></li>';
refNode.insertAdjacentHTML('afterend', htmlBranches + htmlReleases);
let htmlHiddenMenu = '<li data-menu-item="releases-tab" hidden></li><li data-menu-item="branches-tab" hidden></li>';
let refNodeHiddenMenu = document.querySelector("li[data-menu-item='code-tab']");
refNodeHiddenMenu.insertAdjacentHTML('afterend', htmlHiddenMenu);
let oldSelectedItem = document.querySelector("*[aria-current='page']");
let selectedItem = document.querySelector('.ajb-nav-'+ siteSection);
if (selectedItem !== null) {
oldSelectedItem.removeAttribute("aria-current");
oldSelectedItem.classList.remove("selected");
selectedItem.setAttribute("aria-current", "page");
}
console.log("Menu additions: Active");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment