GitHub Show Repo Issues

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

目前為 2015-12-26 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
// ==/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,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'12\' height=\'12\' viewBox=\'0 0 53.1 53.1\'><g transform=\'translate(0,-999)\'><path d=\'m39.2 999.3c2 0 3.7 1.5 3.7 3.4 0 1.9-1.7 3.4-3.7 3.4l-0.9-0.1-3.4 4c2.3 1.6 4.4 3.8 6 6.4-4 1.2-8.9 1.9-14.2 1.9-5.3 0-10.1-0.7-14.2-1.9 1.5-2.6 3.5-4.7 5.7-6.3l-3.5-4.1c-0.2 0-0.4 0.1-0.6 0.1-2 0-3.7-1.5-3.7-3.4 0-1.9 1.7-3.4 3.7-3.4 2 0 3.7 1.5 3.7 3.4 0 0.7-0.2 1.3-0.6 1.8l3.5 4.2c1.8-0.8 3.8-1.3 5.9-1.3 2 0 3.9 0.4 5.6 1.2l3.7-4.3c-0.3-0.5-0.4-1-0.4-1.6 0-1.9 1.6-3.4 3.7-3.4zm11.8 28.5c1.2 0 2.2 0.9 2.2 2 0 1.1-1 2-2.2 2l-6.7 0c-0.1 1.5-0.3 2.9-0.6 4.3l7.8 3.4c1.1 0.5 1.6 1.7 1.1 2.7-0.5 1-1.8 1.5-2.9 1l-7.2-3.1c-2.7 6.7-8 11.4-14.3 12.1l0-31.2c5.2-0.1 10-1 13.9-2.3l0.3 0.7 7.5-2.7c1.1-0.4 2.4 0.1 2.9 1.2 0.4 1.1-0.1 2.2-1.3 2.6l-7.9 2.8c0.3 1.4 0.6 2.9 0.7 4.5l6.7 0 0 0zm-48.7 0 6.7 0c0.1-1.5 0.3-3.1 0.7-4.5l-7.9-2.8c-1.1-0.4-1.7-1.6-1.3-2.6 0.4-1 1.7-1.6 2.9-1.2l7.5 2.7 0.3-0.7c3.9 1.3 8.7 2.1 13.9 2.3l0 31.2c-6.2-0.7-11.5-5.4-14.3-12.1l-7.2 3.1c-1.1 0.5-2.4 0-2.9-1-0.5-1 0-2.2 1.1-2.7l7.8-3.4c-0.3-1.4-0.5-2.8-0.6-4.3l-6.7 0c-1.2 0-2.2-0.9-2.2-2 0-1.1 1-2 2.2-2z\' fill=\'#888\'/></g></svg>',

				// 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 ) );