Skip to content

Commit 3eec6c7

Browse files
committed
Custom-navigation: Fix nav in projects & cleanup
1 parent b234a9c commit 3eec6c7

File tree

1 file changed

+18
-73
lines changed

1 file changed

+18
-73
lines changed

github-custom-navigation.user.js

Lines changed: 18 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name GitHub Custom Navigation
3-
// @version 1.1.10
3+
// @version 1.1.11
44
// @description A userscript that allows you to customize GitHub's main navigation bar
55
// @license MIT
66
// @author Rob Garrison
@@ -13,11 +13,12 @@
1313
// @grant GM_setValue
1414
// @icon https://github.githubassets.com/pinned-octocat.svg
1515
// @require https://cdnjs.cloudflare.com/ajax/libs/dragula/3.7.2/dragula.js
16+
// @require https://greasyfork.org/scripts/398877-utils-js/code/utilsjs.js?version=1079637
1617
// @updateURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-custom-navigation.user.js
1718
// @downloadURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-custom-navigation.user.js
1819
// @supportURL https://github.com/Mottie/GitHub-userscripts/issues
1920
// ==/UserScript==
20-
/* global dragula */
21+
/* global dragula $ $$ addClass removeClass on */
2122
(() => {
2223
"use strict";
2324

@@ -545,8 +546,8 @@
545546
attr: {
546547
"data-ghcn": name
547548
},
548-
cl4ss: "Header-item",
549-
html: html
549+
className: "Header-item",
550+
html
550551
});
551552
}
552553

@@ -664,28 +665,26 @@
664665

665666
function addBindings() {
666667
// Create a menu entry
667-
let el,
668-
menu = make({
669-
el: "a",
670-
cl4ss: "dropdown-item",
671-
html: "Custom Nav Settings",
672-
attr: {
673-
id: "ghcn-menu"
674-
}
675-
});
668+
const menu = make({
669+
el: "a",
670+
className: "dropdown-item",
671+
html: "Custom Nav Settings",
672+
attr: {
673+
id: "ghcn-menu"
674+
}
675+
});
676676

677-
el = $$(`
677+
const els = $$(`
678678
.Header .dropdown-item[href='/settings/profile'],
679679
.Header .dropdown-item[data-ga-click*='go to profile'],
680+
.Header-item .dropdown-item[href='/settings/profile'],
680681
.js-header-wrapper .dropdown-item[href='/settings/profile'],
681682
.js-header-wrapper .dropdown-item[data-ga-click*='go to profile']`
682683
);
683684
// get last found item - gists only have the "go to profile" item; GitHub
684685
// has both
685-
el = el[el.length - 1];
686-
if (el) {
687-
// insert after
688-
el.parentNode.insertBefore(menu, el.nextSibling);
686+
if (els.length) {
687+
els[els.length -1].after(menu);
689688
on($("#ghcn-menu"), "click", openPanel);
690689
}
691690

@@ -784,7 +783,7 @@
784783

785784
// Main process - adds links to header navigation
786785
function customize() {
787-
let nav = $(".Header nav");
786+
let nav = $("nav[aria-label='Global']");
788787
if (nav) {
789788
nav.classList.add("ghcn-nav");
790789
let indx, els,
@@ -813,60 +812,6 @@
813812
}
814813
}
815814

816-
function $(selector, el) {
817-
return (el || document).querySelector(selector);
818-
}
819-
820-
function $$(selector, el) {
821-
return [...(el || document).querySelectorAll(selector)];
822-
}
823-
824-
function addClass(els, name) {
825-
let indx = els.length;
826-
while (indx--) {
827-
els[indx].classList.add(name);
828-
}
829-
}
830-
831-
function removeClass(els, name) {
832-
let indx = els.length;
833-
while (indx--) {
834-
els[indx].classList.remove(name);
835-
}
836-
}
837-
838-
function on(els, name, callback) {
839-
els = Array.isArray(els) ? els : [els];
840-
let events = name.split(/\s+/);
841-
els.forEach(el => {
842-
events.forEach(ev => {
843-
el.addEventListener(ev, callback);
844-
});
845-
});
846-
}
847-
848-
function make(obj) {
849-
let key,
850-
el = document.createElement(obj.el);
851-
if (obj.cl4ss) {
852-
el.className = obj.cl4ss;
853-
}
854-
if (obj.html) {
855-
el.innerHTML = obj.html;
856-
}
857-
if (obj.attr) {
858-
for (key in obj.attr) {
859-
if (obj.attr?.[key]) {
860-
el.setAttribute(key, obj.attr[key]);
861-
}
862-
}
863-
}
864-
if (obj.appendTo) {
865-
$(obj.appendTo).appendChild(el);
866-
}
867-
return el;
868-
}
869-
870815
let isValid = checkJSON(settings, "init");
871816
if (!isValid) {
872817
resetLinks();

0 commit comments

Comments
 (0)