-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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