Last active
August 29, 2015 14:21
-
-
Save bigwheel/f2d850b9edf4d10bfb22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==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 | |
| }); | |
| }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
github enterpriseのバージョン更新によりデフォルトで表示するようになったのでお役御免