Last active
March 26, 2021 12:52
-
-
Save paradox460/fa76ecacdbb47d8fa9100fbf9305a97e to your computer and use it in GitHub Desktop.
Linkify PivotalTracker links on github
This file contains 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 Linkify Pivotal Tracker links on Github | |
// @namespace http://paradox.io/linkify-pivotal-links | |
// @version 0.1 | |
// @description Converts pivotal tracker story links (#123456789) to actual links | |
// @author Jeff Sandberg | |
// @match *://github.com/* | |
// @grant none | |
// @downloadURL https://gist.githubusercontent.com/paradox460/fa76ecacdbb47d8fa9100fbf9305a97e/raw | |
// @require https://cdn.jsdelivr.net/gh/padolsey/findAndReplaceDOMText@0.4.5/src/findAndReplaceDOMText.min.js | |
// ==/UserScript== | |
const forEach = (array, callback, scope) => { | |
for (var i = 0; i < array.length; i++) { | |
callback.call(scope, i, array[i]); // passes back stuff we need | |
} | |
}; | |
const linkify = (elem) => { | |
findAndReplaceDOMText(elem, { | |
find: /#(\d{9,})/, | |
replace: (m, [,id]) => { | |
if (m.node.parentElement.matches('a')) { return m.text }; | |
var el = document.createElement('a'); | |
el.href = `https://www.pivotaltracker.com/story/show/${id}`; | |
el.innerHTML = m.text; | |
return el | |
}, | |
}) | |
}; | |
let textNodes = document.querySelectorAll('.comment-body') | |
forEach(textNodes, (index, elem) => { | |
linkify(elem); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment