Skip to content

Instantly share code, notes, and snippets.

@mrcaron
Created November 1, 2016 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrcaron/bff0b2cdf5e50e8990491fc68f68d12c to your computer and use it in GitHub Desktop.
Save mrcaron/bff0b2cdf5e50e8990491fc68f68d12c to your computer and use it in GitHub Desktop.
TFS 2015 Team Chat Notification Tampermonkey
// ==UserScript==
// @name TFS Team Room notifications in Chrome
// @namespace http://solidworks.com
// @version 0.51
// @description Getting tired of switching back and forth between a browser and Visual Studio...just to see if you have any chat notifications? Use this script, and get your notifications directly on your desktop!
// @match http://sw-dev-tfs:8080/tfs/_rooms*
// @copyright 2016+, Michael Caron
// ==/UserScript==
// uncomment to debug
// debugger;
// Bookmarklet to activate Chrome notifications on TFS Team Room Chat
$(function() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification");
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied' || Notification.permission === "default") {
Notification.requestPermission();
}
console.log("TFS Notifications - Setting up 5 second delay...");
// Activate the plugin after 5 seconds
window.setTimeout(function() {
$.connection.chatHub.on('messageReceived', function(roomId, message) {
var messageNotification = function(image, title, content) {
//var _notification = window.webkitNotifications.createNotification(_tfsIcon, title, content);
//_notification.show();
var options = {
body: content,
icon: image
};
new Notification(title, options);
// If you are mentioned in the chat, keep it displayed until you actively close it.
//if (message.Mentions.length == 0) {
// window.setTimeout(function() {
// _notification.cancel();
// }, 5000);
//}
};
if (message.postedByUserTfId != $.connection.chatHub.state.id) {
if (message.content.indexOf("{") === 0) {
var _tfsServerIcon = "/_static/tfs/20131021T164530/_content/tfs-large-icons.png";
var serverMessage = $.parseJSON(message.content);
messageNotification(_tfsServerIcon, serverMessage.type, serverMessage.title);
} else {
var iconpath = window.location.pathname.replace("_rooms","");
iconpath += window.location.search.substring(1).split('&')[0].split('=')[1];
iconpath += "/_api/_common/IdentityImage?id=" + message.postedByUserTfId;
if (Notification.permission === "granted") {
messageNotification(iconpath, message.postedByUserName, message.content);
}
}
}
});
console.log("TFS Notification code has loaded.");
}, 5000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment