Skip to content

Instantly share code, notes, and snippets.

@DanielArndt
Last active November 9, 2017 18:08
Show Gist options
  • Save DanielArndt/b653f41ba1f8987c1df6 to your computer and use it in GitHub Desktop.
Save DanielArndt/b653f41ba1f8987c1df6 to your computer and use it in GitHub Desktop.
Tampermonkey script to override the build message function in slack to replace JIRA issue IDs with links.
// ==UserScript==
// @name Slack to Jira links
// @namespace ca.arndt.dan.slack.jiralinks
// @version 1
// @description JIRA links in Slack
// @include https://*.slack.com/*
// @run-at document-end
// @grant unsafeWindow
// ==/UserScript==
var jiraBaseUrl = "https://analyzere.atlassian.net/";
var jiraProjects = ["ARE", "PS", "TP", "CSD"];
var jiraIssuePath = "browse/";
jiraLink = function(str) {
const regex = /<span class="message_body">(.*)<\/span>/g;
var msg = str;
// console.log(str.replace(regex, function(a,b){
// return jiraLink(b);
//}));
var regEx;
var dealWithMatch = function(match, p1, p2) {
console.log("Matched: " + match);
if (match.slice(0, 3) === "%2F") {
return match;
}
if (match.slice(2, 3) === "/") {
return match;
}
return p1 + "<a href='" + jiraBaseUrl + jiraIssuePath + p2 + "'>"+ p2+"</a>";
};
jiraProjects.forEach(function (project) {
regEx = new RegExp("(...)("+project+"-[0-9]+)","gim");
msg = msg.replace(regEx, dealWithMatch);
});
return msg;
};
var oldBuildMsgHTML = TS.templates.builders.msgs.buildHTML;
TS.templates.builders.msgs.buildHTML = function(obj) {
var returnValue = oldBuildMsgHTML(obj);
return jiraLink(returnValue);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment