GitHub Show Repo Issues

Show repo issues count on the repository tab & organization page (https://github.com/:user)

Verze ze dne 26. 12. 2015. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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.1
// @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
// ==/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;base64,PHN2ZyB4bWxucz0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wIDYuNyAwYzAuMS0xLjUgMC4zLTMuMSAwLjctNC41bC03LjktMi44Yy0xLjEtMC40LTEuNy0xLjYtMS4zLTIuNiAwLjQtMSAxLjctMS42IDIuOS0xLjJsNy41IDIuNyAwLjMtMC43YzMuOSAxLjMgOC43IDIuMSAxMy45IDIuM2wwIDMxLjJjLTYuMi0wLjctMTEuNS01LjQtMTQuMy0xMi4xbC03LjIgMy4xYy0xLjEgMC41LTIuNCAwLTIuOS0xLTAuNS0xIDAtMi4yIDEuMS0yLjdsNy44LTMuNGMtMC4zLTEuNC0wLjUtMi44LTAuNi00LjNsLTYuNyAwYy0xLjIgMC0yLjItMC45LTIuMi0yIDAtMS4xIDEtMiAyLjItMnoiIGZpbGw9IiM4ODgiLz48L2c+PC9zdmc+',

				// 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',

				// <a class="repo-list-stat-item tooltipped tooltipped-s" href="/:user/:repo/network" aria-label="Forks">
				//   <span class="octicon octicon-git-branch"></span> 1
				// </a>
				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(
											'<a class="repo-list-stat-item tooltipped tooltipped-s issues" href="' + repo +
											'issues"  aria-label="Issues"><span></span>' + data[ repoIndex ].open_issues_count + '</a>'
										);
									}
								}

							}
						}
					}
				});

			}
		}
	}

	$(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 ) );