|
1 | 1 | // ==UserScript== |
2 | 2 | // @name GitHub Custom Navigation |
3 | | -// @version 1.1.10 |
| 3 | +// @version 1.1.11 |
4 | 4 | // @description A userscript that allows you to customize GitHub's main navigation bar |
5 | 5 | // @license MIT |
6 | 6 | // @author Rob Garrison |
|
13 | 13 | // @grant GM_setValue |
14 | 14 | // @icon https://github.githubassets.com/pinned-octocat.svg |
15 | 15 | // @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 |
16 | 17 | // @updateURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-custom-navigation.user.js |
17 | 18 | // @downloadURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-custom-navigation.user.js |
18 | 19 | // @supportURL https://github.com/Mottie/GitHub-userscripts/issues |
19 | 20 | // ==/UserScript== |
20 | | -/* global dragula */ |
| 21 | +/* global dragula $ $$ addClass removeClass on */ |
21 | 22 | (() => { |
22 | 23 | "use strict"; |
23 | 24 |
|
|
545 | 546 | attr: { |
546 | 547 | "data-ghcn": name |
547 | 548 | }, |
548 | | - cl4ss: "Header-item", |
549 | | - html: html |
| 549 | + className: "Header-item", |
| 550 | + html |
550 | 551 | }); |
551 | 552 | } |
552 | 553 |
|
|
664 | 665 |
|
665 | 666 | function addBindings() { |
666 | 667 | // 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 | + }); |
676 | 676 |
|
677 | | - el = $$(` |
| 677 | + const els = $$(` |
678 | 678 | .Header .dropdown-item[href='/settings/profile'], |
679 | 679 | .Header .dropdown-item[data-ga-click*='go to profile'], |
| 680 | + .Header-item .dropdown-item[href='/settings/profile'], |
680 | 681 | .js-header-wrapper .dropdown-item[href='/settings/profile'], |
681 | 682 | .js-header-wrapper .dropdown-item[data-ga-click*='go to profile']` |
682 | 683 | ); |
683 | 684 | // get last found item - gists only have the "go to profile" item; GitHub |
684 | 685 | // 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); |
689 | 688 | on($("#ghcn-menu"), "click", openPanel); |
690 | 689 | } |
691 | 690 |
|
|
784 | 783 |
|
785 | 784 | // Main process - adds links to header navigation |
786 | 785 | function customize() { |
787 | | - let nav = $(".Header nav"); |
| 786 | + let nav = $("nav[aria-label='Global']"); |
788 | 787 | if (nav) { |
789 | 788 | nav.classList.add("ghcn-nav"); |
790 | 789 | let indx, els, |
|
813 | 812 | } |
814 | 813 | } |
815 | 814 |
|
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 | | - |
870 | 815 | let isValid = checkJSON(settings, "init"); |
871 | 816 | if (!isValid) { |
872 | 817 | resetLinks(); |
|
0 commit comments