// ==UserScript==
// @name TFS Helper
// @namespace http://jonas.ninja
// @version 1.5.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.12.0/jquery.min.js
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
/* jshint -W097 */
/* global $, GM_addStyle */
/* 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) {
copy(this, $(this).next('span.copy-message'))
if (e.ctrlKey) {
// if CTRL is held down, copy both the commit ID and a commit message (useful if you have a clipboard manager like Ditto)
var optMessage = 't' + (this.value) + ' ' + $(this).siblings('.info-text').text().replace(/^dev: /i, "")
var that = this
window.setTimeout(function() {
copy(that, $(that).next('span.copy-message'), optMessage)
}, 250)
}
})
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 column2 = $(linksPane).closest('table.content').parent('.column')
if (Math.max(window.innerWidth, document.documentElement.clientWidth) >= 1600) return;
column2.add(column2.prev()).css({width: '100%', display: 'block'})
window.dispatchEvent(new Event('resize'));
}
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 = $('