// ==UserScript== // @name TFS Helper // @namespace http://jonas.ninja // @version 1.3.1 // @description Adds styles and moves things around so that oft-used functions are easier // @author @_jnblog // @match http://*/tfs/DefaultCollection/*/_backlogs/* // @match http://*/tfs/DefaultCollection/*/_versionControl/* // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js // @grant GM_addStyle // @downloadURL none // ==/UserScript== /* jshint -W097 */ /* global $ */ /* jshint asi: true, multistr: true */ 'use strict' var topClass = "makeTfsNotAwful" $('body').addClass(topClass) function doEverything (linksPane) { if ($(linksPane).data('moved')) { return } showLinksPane(linksPane) stackAllTabs(linksPane) window.setTimeout(function() { addTaskIdCopyUtilities(linksPane) changeDialogBorderColor(linksPane) }, 250) } $(document).on('click', 'input.task-identifier', function clickToCopy(e) { // if shift is held down, copy a commit message var optMessage = undefined if (e.ctrlKey) { optMessage = 't' + (this.value) + ' ' + $(this).siblings('.info-text').text().replace(/^dev: /i, "") } copy(this, $(this).next('span.copy-message'), optMessage) }) function showLinksPane (linksPane) { $(linksPane).data('moved', true) .addClass('linksPanel') .prepend($("

").addClass('linksPanelHeader') .text($(linksPane).attr('rawtitle'))) var link = $('a[rawtitle=Links]') link.closest('td').parent().closest('td').prev().css('width', '30%') link.closest('td').prepend(linksPane) link.parent().remove() } function changeDialogBorderColor(linksPane) { // depending on the type of this work item, color the border differently var dialog = $(linksPane).closest('.workitem-dialog') var caption = dialog.find('a.caption').text() if (caption.indexOf('Product Backlog Item ') !== -1) { dialog.css('border-color', '#009CCC') // blue } else if (caption.indexOf('Bug ') !== -1) { dialog.css('border-color', '#CC293D') // red } else { // Task dialog.css('border-color', '#E0C252') // yellow } } function stackAllTabs (linksPane) { var column2table = $(linksPane).closest('table.content') if (column2table.width() < 882) { // put att tabPanels in a single column column2table.parent().siblings().append(column2table).css('width', '100%').children().css('overflow', 'hidden') } } function addTaskIdCopyUtilities (linksPane) { $('.workitem-info-bar').find('.info-text-wrapper').each(function() { var $header = $(this) if ($header.hasClass('added')) { return } $header.addClass('added') var id = $header.find('a.caption').text().match(/\d+/)[0] var $input = $('').addClass('task-identifier') $header.find('span.info-text').after($('').addClass('copy-message')).after($input) }); } function copy(elToCopy, $messageContainer, optionalMessage) { var $fakeElem = $('