Linkify Pivotal Tracker links on Github

Converts pivotal tracker story links (#123456789) to actual links

  1. // ==UserScript==
  2. // @name Linkify Pivotal Tracker links on Github
  3. // @namespace http://paradox.io/linkify-pivotal-links
  4. // @homepage https://github.com/paradox460/userscripts/blob/master/pivotal-tracker-linkify.user.js
  5. // @version 0.2
  6. // @description Converts pivotal tracker story links (#123456789) to actual links
  7. // @author Jeff Sandberg
  8. // @match *://github.com/*
  9. // @grant none
  10. // @require https://cdn.jsdelivr.net/gh/padolsey/findAndReplaceDOMText@0.4.5/src/findAndReplaceDOMText.min.js
  11.  
  12. // ==/UserScript==
  13.  
  14. const forEach = (array, callback, scope) => {
  15. for (var i = 0; i < array.length; i++) {
  16. callback.call(scope, i, array[i]); // passes back stuff we need
  17. }
  18. };
  19.  
  20. const linkify = (elem) => {
  21. findAndReplaceDOMText(elem, {
  22. find: /#(\d{9,})/,
  23. replace: (m, [, id]) => {
  24. if (m.node.parentElement.matches('a')) { return m.text; }
  25.  
  26. var el = document.createElement('a');
  27. el.href = `https://www.pivotaltracker.com/story/show/${id}`;
  28. el.innerHTML = m.text;
  29. return el;
  30. },
  31. });
  32. };
  33.  
  34. let textNodes = document.querySelectorAll('.comment-body');
  35. forEach(textNodes, (index, elem) => {
  36. linkify(elem);
  37. });