Skip to content

Instantly share code, notes, and snippets.

@jonathanMelly
Forked from knl/github-jira-love.js
Last active April 7, 2020 15:23
Show Gist options
  • Save jonathanMelly/0baed69ddc685ad8f3084d74181a5d9c to your computer and use it in GitHub Desktop.
Save jonathanMelly/0baed69ddc685ad8f3084d74181a5d9c to your computer and use it in GitHub Desktop.
Greasemonkey user script to link back to Azure devops from GitHub (forked from http://github.com/knl)
// ==UserScript==
// @name GitHub/Azure devops Links
// @namespace http://github.com/jonathanMelly
// @author jmy
// @version 1.0
// @description Link to azure devops work items from Github
// @match https://github.com/**
// @run-at document-end
// @noframes
// @grant none
// @match https://github.com/jonathanMelly/cosmos/*
// ==/UserScript==
const url = 'https://dev.azure.com/jonathanmelly/_workitems/edit';
const issueRegExp = '([aA][bB]#)([0-9]+)';
function doIt(node) {
// we actually iterate over the whole document now
document.querySelectorAll("p, pre, h1, a").forEach(function(elem) {
const regex = new RegExp(issueRegExp, 'g');
elem.innerHTML = elem.innerHTML.replace(regex, '<a href="' + url + '/$2" target=_blank>$1$2</a>');
});
}
/* Wait for selected elements to appear on the page and process them */
function waitForKeyElements (
selectorTxt, /* Required: The selector string that specifies the desired element(s). */
actionFunction, /* Required: The code to run when elements are found. Gets a node to the matched element. */
) {
document.querySelectorAll(selectorTxt).forEach(function(node) {
var alreadyFound = node.alreadyFound || false;
if (!alreadyFound) {
//--- Call the payload function.
actionFunction(node);
node.alreadyFound = true;
}
});
var timeControl = waitForKeyElements.timeControl;
//--- Set a timer, if needed.
if (!timeControl) {
timeControl = setInterval(function () {
waitForKeyElements(selectorTxt, actionFunction);
},
1000
);
waitForKeyElements.timeControl = timeControl;
}
}
waitForKeyElements ("p[class=commit-title], .comment-body", doIt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment