Skip to content

Instantly share code, notes, and snippets.

@alreva
Last active December 10, 2015 10:34
Show Gist options
  • Save alreva/0a02730dc1e175810073 to your computer and use it in GitHub Desktop.
Save alreva/0a02730dc1e175810073 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Copy TFS work item ID
// @namespace http://tfs.it.volvo.net:8080/
// @version 0.1
// @description nothing
// @author alreva
// @match http://tfs.it.volvo.net:8080/tfs/Global3/SEGOT-eCom-CORE/*
// @grant none
// ==/UserScript==
(function () {
var executeCopy = function (text, copyContainer) {
var input = document.createElement('textarea');
(copyContainer || document.body).appendChild(input);
input.value = text;
input.focus();
input.select();
document.execCommand('copy');
input.remove();
console.log("Copied:" + text);
};
var addCopyButtonToWorkItemList = function () {
if ($(".grid-header-column[title='ID']").length < 1) {
return;
}
var idIndex = $(".grid-header-column[title='ID']").index();
var idCells = $(".grid-row").find(".grid-cell:eq(" + idIndex + ")");
idCells.each(function () {
if ($(this).find(".copy-id-wi-list").length > 0) {
return;
}
$(this).prepend('<a class="copy-id-wi-list" title="Copy work item ID" style="margin-right:3px;"><i class="fa fa-clone"></i></a>');
});
}
var addCopyButtonToWorkItemPopup = function () {
if ($(".info-text-wrapper").length < 1 || $(".info-text-wrapper .copy-id-wi-popup").length > 0) {
return;
}
$("<a><i class='copy-id-wi-popup fa fa-clone fa-2' style='margin-right: 5px;' title='Copy work item ID'></i></a>")
.prependTo($(".info-text-wrapper"));
$(".info-text-wrapper").click(function (e) {
if (!$(e.target).hasClass("copy-id-wi-popup") && $(e.target).closest(".copy-id-wi-popup").length < 1) {
return;
}
var itemHref = $(".info-text-wrapper a.caption").attr("href");
var itemId = itemHref.substr(itemHref.lastIndexOf("/") + 1);
executeCopy(itemId, $(".info-text-wrapper")[0])
$(".info-text-wrapper a").fadeOut().fadeIn();
});
};
setInterval(addCopyButtonToWorkItemPopup, 1000);
setInterval(addCopyButtonToWorkItemList, 1000);
$(document).click(function (e) {
if (!$(e.target).hasClass("copy-id-wi-list") && $(e.target).closest(".copy-id-wi-list").length < 1) {
return;
}
var itemId = $(e.target).closest('.grid-cell').text().trim();
executeCopy(itemId);
$(e.target).closest('.grid-cell').fadeOut().fadeIn();
});
$("head").append('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">')
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment