Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name Github milestone enhanced issue list
// @namespace https://github.com/bigwheel
// @version 1.0
// @description this is description
// @author bigwheel
// @match http://github.o-in.dwango.co.jp/*
// @grant GM_xmlhttpRequest
// @require http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js
// ==/UserScript==
function generateRGB(sourceString) {
return CryptoJS.MD5(sourceString).words[0].toString(16).slice(0, 6);
}
function getContrastRGB(rgbString) {
return (0xffffff - parseInt(rgbString, 16)).toString(16);
}
if(document.body && $('.issues-list')) {
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
$("li.issue-list-item").each(function() {
var issueId = $(this).attr("id").slice(6);
$(this).find("h4 span.type-icon").each(function() {
if (!($(this).next().hasClass('gs-append-milestone-label'))) {
var $milestoneLabel = $('<a class="gs-append-milestone-label"></a>');
$(this).after($milestoneLabel);
var userAndRepoPath = location.pathname.split('/').slice(1, 3).join('/'); // like bigwheel/repo1
GM_xmlhttpRequest({
method: "GET",
url: 'http://github.enterprise.url/api/v3/repos/' + userAndRepoPath + '/issues/' + issueId + '?access_token=2f4792a0551d5f7e168217cc242db30ab7519c8d',
onload: function(response) {
var milestone = $.parseJSON(response.responseText).milestone;
if (milestone) {
$milestoneLabel.append(milestone.title);
$milestoneLabel.attr('href', location.protocol + '//' + location.host + '/' + userAndRepoPath + '/issues?milestone=' + milestone.number + '&state=open');
var bgColor = generateRGB(milestone.title);
var fontColor = getContrastRGB(bgColor);
$milestoneLabel.css({
'color': '#' + fontColor,
'background-color': '#' + bgColor,
'border-style': 'solid',
'border-color': 'black'
});
}
}
});
}
});
});
});
observer.observe(document, {
subtree: true,
attributes: true
});
};
@bigwheel

This comment has been minimized.

Copy link
Owner Author

@bigwheel bigwheel commented May 25, 2015

github enterpriseのバージョン更新によりデフォルトで表示するようになったのでお役御免

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment