// ==UserScript== // @name GitHub Show Repo Issues // @namespace github-show-repo-issues // @description Show repo issues count on the repository tab & organization page (https://github.com/:user) // @version 2.1.0 // @include https://github.com/* // @grant GM_addStyle // @grant GM_xmlhttpRequest // @run-at document-end // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js // @author Rob Garrison >> http://github.com/Mottie // @downloadURL none // ==/UserScript== /* global jQuery, GM_addStyle, GM_xmlhttpRequest */ ( function( unsafeWindow, $ ) { 'use strict'; function addIssues() { // look for repo tab if ( $( '.tabnav-tab.selected' ).length || $( '.repo-list' ).length ) { // Does not include forks & only includes the first 10 repos, or first 20 on the // organization page - these are the repos showing the participation graphs var max = $( '.tabnav-tab.selected' ).length ? 10 : 20, $items = $('.repo-list-item') .filter(':lt(' + max + ')') .filter('.public:not(.fork)') .find('a.repo-list-stat-item[aria-label="Forks"]'), len = $items.length, // bug icon img = 'data:image/svg+xml;charset=utf8,', // api v3: first 30 issues = https://api.github.com/repos/:user/:repo/issues?state=open // issue count = get all repos from user = https://api.github.com/users/:user/repos, // then look for "open_issues_count" in the named repo api = 'https://api.github.com/users', // // 1 // user = ( $items.eq( 0 ).attr( 'href' ) || '' ).match( /^\/[^/]+/ ); if ( user && user.length ) { // add bug image background GM_addStyle( '.repo-list-stats a.issues { padding-left: 18px; background: url("'+ img + '") no-repeat 0 2px !important; }' ); GM_xmlhttpRequest({ method : 'GET', url : api + user[ 0 ] + '/repos', onload : function( response ) { var itemIndex, repoIndex, repoLen, repo, data = $.parseJSON( response.responseText || 'null' ); if ( data ) { repoLen = data.length; for ( itemIndex = 0; itemIndex < len; itemIndex++ ) { repo = ( $items.eq( itemIndex ).attr( 'href' ) || '' ).replace( '/network', '' ).slice( 1 ); for ( repoIndex = 0; repoIndex < repoLen; repoIndex++ ) { if ( repo === data[ repoIndex ].full_name ) { $items.eq( itemIndex ).after( '' + data[ repoIndex ].open_issues_count + '' ); } } } } } }); } } } $(function(){ // easier to bind to these events than use mutation observer - or maybe I'm just lazy unsafeWindow.jQuery( '#js-repo-pjax-container, #js-pjax-container, .js-contribution-activity' ) .on('pjax:complete', function() { addIssues(); }); }); addIssues(); })( typeof unsafeWindow !== 'undefined' ? unsafeWindow : window, jQuery.noConflict( true ) );